Skip to content

Commit

Permalink
Introduce reprex.current_venue option
Browse files Browse the repository at this point in the history
cc @kevinushey

Relates to #313
  • Loading branch information
jennybc committed Jan 16, 2021
1 parent dbdf408 commit a4e3efe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

* Experimental venue "rtf" now works on Windows, to approximately the same extent as it works on macOS. In both cases, it still requires a working installation of the highlight command line tool (#331).

* `reprex.current_venue` is a new read-only option that is set during `reprex_render()`. Other packages can use it to generate `reprex()`-compatible, `venue`-specific output.

## Dependency changes

R 3.1 and R 3.2 are no longer explicitly supported or tested. Our general practice is to support the current release (4.0, at time of writing), devel, and the 4 previous versions of R (3.6, 3.5, 3.4, 3.3).
Expand Down
12 changes: 7 additions & 5 deletions R/reprex-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#' * `reprex.tidyverse_quiet`
#' * `reprex.std_out_err`
#'
#' A few more options exist, but are only consulted in specific situations:
#' * `reprex.venue`: Only consulted by [reprex_selection()]. [reprex()]
#' itself reveals the possible values for `venue` in the "Usage" section
#' of its help file and defaults to the first value, in the usual
#' [match.arg()] way.
#' A few more options exist, but are only relevant to specific situations:
#' * `reprex.venue`: Can be used to control the `venue` used by the
#' [reprex_selection()] addin.
#' * `reprex.current_venue`: Read-only option that is set during
#' [reprex_render()]. Other packages that want to generate reprex-compatible
#' output can consult it via `getOption("reprex.current_venue")`, if they want
#' to tailor their output to the `venue`.
#' * `reprex.highlight.hl_style`: Only relevant to `venue = "rtf`. Details are
#' in the article
#' [reprex venue RTF](https://reprex.tidyverse.org/articles/articles/rtf.html).
Expand Down
3 changes: 2 additions & 1 deletion R/reprex_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ reprex_render_impl <- function(input,
rlang_trace_top_env = globalenv(),
`rlang:::force_unhandled_error` = TRUE,
rlang_backtrace_on_error = "full",
crayon.enabled = FALSE
crayon.enabled = FALSE,
reprex.current_venue = venue
)
if (new_session) {
out <- tryCatch(
Expand Down
12 changes: 7 additions & 5 deletions man/reprex_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-reprex-options.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("reprex.current_venue is set", {
skip_on_cran()
input <- "getOption('reprex.current_venue')"
ret <- reprex(input = paste0(input, "\n"))
expect_match(ret, "gh", all = FALSE)
ret <- reprex(input = paste0(input, "\n"), venue = "html")
expect_match(ret, "html", all = FALSE)
})

0 comments on commit a4e3efe

Please sign in to comment.