We’ve made reprex more pleasant to use in settings where we cannot access the user’s clipboard from R. Specifically, this applies to use on RStudio Server and RStudio Cloud.
reprex()is called without
input, in a context where the user’s clipboard can’t be reached from R, the default is now to consult the current selection for reprex source. Previously this was only available via the
reprex_selection()addin. Note that this “current selection” default behaviour propagates to convenience wrappers around
reprex(), such as
reprex_locale()and venue-specific functions like
reprex_r(), and to the un-
reprex()functions, such as
wd is a new argument to set the reprex working directory. As a result, the
outfile argument is deprecated and the
input argument has new significance. Here’s how to use
wd to control reprex filepaths:
reprex(outfile = NA)
reprex(wd = ".")
reprex(wd = "path/to/desired/wd").
reprex(input = "path/to/stuff.R"). When
inputis a filepath, that filepath determines the working directory and how reprex files are named and
wdis never even consulted.
Various changes mean that more users will see reprex filepaths. Therefore, we’ve revised them to be more self-explanatory and human-friendly. When reprex needs to invent a file name, it is now based on a random “adjective-animal” slug. Bring on the
reprex() renders the reprex in a separate, fresh R session using
callr::r(). As of callr 3.4.0 (released 2019-12-09), the default became
callr::r(..., user_profile = "project"), which means that callr executes a
.Rprofile found in current working directory. Most reprexes happen in a temp directory and there will be no such
.Rprofile. But if the user intentionally reprexes in an existing project with a
callr::r() and therefore
reprex() honor it. In this version of reprex:
callr::r()call is the same as the effective working directory of the reprex.
.Rprofilehas been found.
.Rprofilein the rendered reprex.
These changes are of special interest to users of the renv package, which uses
.Rprofile to implement a project-specific R package library. Combined with the filepath changes (described above), this means an renv user can call
reprex(wd = "."), to render a reprex with respect to a project-specific library.
rstudioapi moves from Suggests to Imports. Related to improving the experience when reprex cannot access the user’s clipboard.
mockr is new in Suggests; it’s used in the tests.
We bumped the documented minimum version of Pandoc, because we use the
gfm markdown variant to get GitHub-Flavored Markdown. The
gfm variant was introduced in Pandoc 2.0 (released 2017-10-29).
reprex_VENUE(...) is a new way to call
reprex(..., venue = "VENUE"). For example,
reprex_r() is equivalent to
reprex(venue = "r"). This makes non-default venues easier to access via auto-completion (#256).
"slack" is a new venue that tweaks the default Markdown output for pasting into Slack messages. It removes the
r language identifier from the opening code fence, simplifies image links and, by default, suppresses the ad. Note that
venue = "slack" or
reprex_slack() work best for people who opt-out of the WYSIWYG message editor: in Preferences > Advanced, select “Format messages with markup”.
venue = "so" (SO = Stack Overflow) has converged with default
venue = "gh" (GitHub). As of January 2019, SO supports CommonMark fenced code blocks. The only remaining difference is that Stack Overflow does not support the collapsible details tag that we use on GitHub to reduce the clutter from, e.g., session info (#231).
"rtf" (Rich Text Format) is a new experimental
venue for pasting into applications like PowerPoint and Keynote. It is experimental because it requires a working installation of the highlight command line tool, which is left as a somewhat fiddly exercise for the user (#331).
venue = "rtf" is documented in its own article.
reprex() has been internally refactored to make better use of the official machinery for extending rmarkdown:
reprex_document()is a new R Markdown output format.
reprex_render()is a newly exported function.
reprex_document()is designed to be rendered with
reprex_render()is designed to act on a
reprex_document(). This is (still) the heart of what the
reprex()function does, in addition to various interface and workflow niceties.
knit: reprex::reprex_renderin the YAML, which causes the RStudio “Knit” button to use
prex_render() are new unexported functions that, like
reprex(), render a small bit of code, but with much less reproducibility! The code is evaluated in the global workspace of the current process, with the current working directory. This pragmatic hack is useful when preparing a series of related snippets, e.g., for a Keynote or PowerPoint presentation, and there’s not enough space to make each one self-contained.
si argument of
reprex() is now
session_info. Being explicit seems more important than saving characters, given auto-completion.
show argument of
reprex() is now
html_preview, for the sake of consistency with other R Markdown output formats.
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).
sessioninfo is new in Suggests, replacing devtools.
glue is new in Imports, replacing whisker.
knitr moves from Suggests to Imports (although it was already a hard dependency via rmarkdown), so we can require v1.23 or higher, which represents a major switch to UTF-8.
cli is new in Imports.
reprex now relies on testthat >= 3.0.0 and, specifically, uses third edition features.
The YAML of reprex’s template has been updated in light of the stricter YAML parser used in Pandoc >= 2.2.2.
rlang::set_attrs() has been soft-deprecated and is no longer used internally.
The reprex ad is formatted as superscript for
venue = "gh" and
venue = "so", i.e. it is more subtle (#201).
opts_knit have been removed from
reprex(). The same effect has always been achievable via roxygen comments in the reprex code and the examples have always demonstrated this. Overriding knitr options doesn’t seem to come up often enough in real-world
reprex() usage to justify these arguments.
Internal file system operations use the fs package. This should not make any user-facing changes in reprex and we definitely want to know if it does.
reprex() gains several arguments and many arguments can now be controlled via an option, in case a user wants their own defaults.
If reprex can’t write to the user’s clipboard (e.g. on RStudio server or Unix-like systems lacking xclip or xsel), it offers to open the output file for manual copy.
These look like
reprex(..., arg = opt(DEFAULT), ...) in the help file. This is shorthand for
arg = getOption("reprex.arg", DEFAULT), i.e. the option
reprex.arg is consulted and, if unset, the documented default is used. Allows user to define their own default behaviour (#116).
advertise: toggles inclusion of a footer that describes when and how the reprex was created, e.g., “Created on 2017-11-16 by the reprex package (v0.1.1.9000)”. Defaults to
style: requests code restyling via the newly-Suggested styler package. styler can cope with tidyeval syntactical sugar, e.g.
df %>% group_by(!! group_var). Defaults to
tidyverse_quiet: affords control of the startup message of the tidyverse meta-package. Defaults to
TRUE, i.e. suppresses the message (important special case of #70, #100).
std_out_err: appends output sent to stdout and stderr by the reprex rendering process. This can be necessary to reveal output if the reprex spawns child processes or has
system()calls. Defaults to
render: determines if the reprex is actually rendered or just returns after producing the templated
.Rfile. For internal testing.
venue = "gh" now targets CommonMark as the standard for GitHub Flavored Markdown (#77).
venue = "so" has appropriate whitespace at the start.
venue = "ds" is a new value, corresponding to https://www.discourse.org, which is the platform behind community.rstudio.com. This is currently just an alias for the default
"gh" GitHub venue, because the formatting appears to be compatible. Adding the
"ds" value so Discourse can be documented and to guard against the possibility that some formatting is actually unique.
keep.source option is set to
TRUE when rendering the reprex, so reprexes involving srcrefs should work (#152).
Expression input handling has been refactored. As a result, formatR is no longer Suggested. Trailing comments – inline and on their own line – are also now retained (#89, #91, #114, @jennybc and @jimhester).
This was a non-functioning release created by CRAN maintainers by commenting out lines of code relating to the clipboard.
outfile = NA causes outfiles to be left in working directory. Filenames will be based on the
input file, if there was one.
reprex() strips any leading prompts from input code.
venue = "R" (or
"r") can be used to get an R script back, augmented with commented output.
comment argument added to specify prefix for commented output.
Added an RStudio addin, accessed via “Render reprex”.
input argument to
reprex() and friends handles code as string, character vector, or file path.
The reprex is rendered via
callr::r_safe() and is thus run in a clean, separate R process, eliminating any leakage of objects or loaded packages to/from the calling session.
upload.funargument unnecessary, so it’s gone. The
upload.funoption defaults to
knitr::imgur_upload, which means figures produced by the reprex will be uploaded to imgur.com and the associated image syntax will be put into the Markdown, e.g.
!(https://i.imgur.com/QPU5Cg9.png). (#15 @paternogbc)
reprex() arguments has changed.
reprex() gains the
si argument to request that
sessionInfo() be appended to reprex code (#6 @dgrtwo). When
si = TRUE and
venue = "gh" (the default), session info is wrapped in a collapsible details tag. See an example (#55).