# NOT RUN {
## a rendered reprex can be inverted, at least approximately
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)
writeLines(x)
reprex_invert(x)
## a displayed reprex can be cleaned of commented output
x <- c(
"## a regular comment, which is retained",
"(x <- 1:4)",
"#> [1] 1 2 3 4",
"median(x)",
"#> [1] 2.5"
)
reprex_clean(x)
# }
# NOT RUN {
## round trip with reprex(..., venue = "R")
code_in <- c("x <- rnorm(2)", "min(x)")
res <- reprex(input = code_in, venue = "R")
res
(code_out <- reprex_clean(res))
identical(code_in, code_out)
# }
# NOT RUN {
## rescue a reprex that was copied from a live R session
x <- c(
"> ## a regular comment, which is retained",
"> (x <- 1:4)",
"[1] 1 2 3 4",
"> median(x)",
"[1] 2.5"
)
reprex_rescue(x)
# }
Run the code above in your browser using DataLab