EVOLUTION-MANAGER
Edit File: un-reprex.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Un-render a reprex</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for un-reprex {reprex}"><tr><td>un-reprex {reprex}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Un-render a reprex</h2> <h3>Description</h3> <p>Recover clean, runnable code from a reprex captured in the wild and write it to user's clipboard. The code is also returned invisibly and optionally written to file. Three different functions address various forms of wild-caught reprex. </p> <h3>Usage</h3> <pre> reprex_invert(input = NULL, outfile = NULL, venue = c("gh", "so", "ds", "r"), comment = opt("#>")) reprex_clean(input = NULL, outfile = NULL, comment = opt("#>")) reprex_rescue(input = NULL, outfile = NULL, prompt = getOption("prompt"), continue = getOption("continue")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>input</code></td> <td> <p>Character. If has length one and lacks a terminating newline, interpreted as the path to a file containing reprex code. Otherwise, assumed to hold reprex code as character vector. If not provided, the clipboard is consulted for input.</p> </td></tr> <tr valign="top"><td><code>outfile</code></td> <td> <p>Optional basename for output file. When <code>NULL</code>, no file is left behind. If <code>outfile = "foo"</code>, expect an output file in current working directory named <code>foo_clean.R</code>. If <code>outfile = NA</code>, expect on output file in a location and with basename derived from <code>input</code>, if a path, or in current working directory with basename derived from <code><a href="../../base/html/tempfile.html">tempfile()</a></code> otherwise.</p> </td></tr> <tr valign="top"><td><code>venue</code></td> <td> <p>Character. Must be one of the following (case insensitive): </p> <ul> <li><p> "gh" for <a href="https://github.github.com/gfm/">GitHub-Flavored Markdown</a>, the default </p> </li> <li><p> "so" for <a href="https://stackoverflow.com/editing-help">Stack Overflow Markdown</a> </p> </li> <li><p> "ds" for Discourse, e.g., <a href="https://community.rstudio.com">community.rstudio.com</a>. Note: this is currently just an alias for "gh"! </p> </li> <li><p> "r" for a runnable R script, with commented output interleaved </p> </li> <li><p> "rtf" for <a href="https://en.wikipedia.org/wiki/Rich_Text_Format">Rich Text Format</a> (not supported for un-reprexing) </p> </li> <li><p> "html" for an HTML fragment suitable for inclusion in a larger HTML document (not supported for un-reprexing) </p> </li></ul> </td></tr> <tr valign="top"><td><code>comment</code></td> <td> <p>regular expression that matches commented output lines</p> </td></tr> <tr valign="top"><td><code>prompt</code></td> <td> <p>character, the prompt at the start of R commands</p> </td></tr> <tr valign="top"><td><code>continue</code></td> <td> <p>character, the prompt for continuation lines</p> </td></tr> </table> <h3>Value</h3> <p>Character vector holding just the clean R code, invisibly </p> <h3>Functions</h3> <ul> <li> <p><code>reprex_invert</code>: Attempts to reverse the effect of <code><a href="reprex.html">reprex()</a></code>. When <code>venue = "r"</code>, this just becomes a wrapper around <code>reprex_clean()</code>. </p> </li> <li> <p><code>reprex_clean</code>: Assumes R code is top-level, possibly interleaved with commented output, e.g., a displayed reprex copied from GitHub or the direct output of <code>reprex(..., venue = "R")</code>. This function removes commented output. </p> </li> <li> <p><code>reprex_rescue</code>: Assumes R code lines start with a prompt and that printed output is top-level, e.g., what you'd get from copy/paste from the R Console. Removes lines of output and strips prompts from lines holding R commands. </p> </li></ul> <h3>Examples</h3> <pre> ## Not run: ## a rendered reprex can be inverted, at least approximately tmp_in <- file.path(tempdir(), "roundtrip-input") x <- reprex({ #' Some text #+ chunk-label-and-options-cannot-be-recovered, message = TRUE (x <- 1:4) #' More text y <- 2:5 x + y }, show = FALSE, advertise = FALSE, outfile = tmp_in) tmp_out <- file.path(tempdir(), "roundtrip-output") x <- reprex_invert(x, outfile = tmp_out) x # clean up file.remove( list.files(dirname(tmp_in), pattern = "roundtrip", full.names = TRUE) ) ## End(Not run) ## Not run: ## a displayed reprex can be cleaned of commented output tmp <- file.path(tempdir(), "commented-code") x <- c( "## a regular comment, which is retained", "(x <- 1:4)", "#> [1] 1 2 3 4", "median(x)", "#> [1] 2.5" ) out <- reprex_clean(x, outfile = tmp) out # clean up file.remove( list.files(dirname(tmp), pattern = "commented-code", full.names = TRUE) ) ## round trip with reprex(..., venue = "R") code_in <- c("x <- rnorm(2)", "min(x)") res <- reprex(input = code_in, venue = "R", advertise = FALSE) res (code_out <- reprex_clean(res)) identical(code_in, code_out) ## End(Not run) ## Not run: ## rescue a reprex that was copied from a live R session tmp <- file.path(tempdir(), "live-transcript") x <- c( "> ## a regular comment, which is retained", "> (x <- 1:4)", "[1] 1 2 3 4", "> median(x)", "[1] 2.5" ) out <- reprex_rescue(x, outfile = tmp) out # clean up file.remove( list.files(dirname(tmp),pattern = "live-transcript", full.names = TRUE) ) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>reprex</em> version 0.3.0 <a href="00Index.html">Index</a>]</div> </body></html>