tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.

Home Page:https://reprex.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prevent prex from changing certain session options

jennybc opened this issue · comments

Now, first, remember that prex() is unexported precisely because it creates leakage between your current R session and your (re)prex. So in general, prex() users have to take the bad with the good.

But we could try harder to leave certain things the way we found them.

Consider these options, which we inject into to-be-(re)prexed code:

reprex/R/reprex_document.R

Lines 131 to 141 in 318363c

reprex_opts <- function(venue = "gh") {
string <- glue('
```{{r reprex-options, include = FALSE}}
options(
keep.source = TRUE,
rlang_backtrace_on_error_report = "full",
crayon.enabled = FALSE,
reprex.current_venue = "{venue}"
)
```')
}

prex() could note the original values of keep.source, rlang_backtrace_on_error_report, and crayon.enabled and make a point of scheduling their restoration.

Before the fix

Screen Shot 2022-09-15 at 4 03 37 PM

After the fix

Screen Shot 2022-09-15 at 4 02 50 PM