convert_to_script | R Documentation |
Wraps knitr::purl()
to create an .R script from a .Rmd file. It can also
auto-archive the .Rmd file to a [dir]/archive
sub-directory. This is useful
for turning first-attempt exploratory data analysis into production scripts
once the validation code is complete.
convert_to_script(filename, dir = NULL, archive = FALSE)
filename |
string, the file name of both the .Rmd file that will be read and the file name of the .R file to be written (do not include .Rmd or .R extension) |
dir |
string, the directory where the .Rmd file is and the .R file will
be written, default is |
archive |
logical, whether to auto-archive the .Rmd file; default is
|
The resulting script will take the same name as the .Rmd file but with a different extension (.R)
If [dir]/archive
does not already exist, it will be created
nothing
write_sessionInfo()
# get test notebook from the sdtmval/inst/extdata dir and copy it to temp dir
test_file_dir <- system.file("extdata", package = "sdtmval")
filename <- "test_notebook"
temp_path <- tempdir()
file.copy(from = file.path(test_file_dir, paste0(filename, ".Rmd")),
to = file.path(temp_path, paste0(filename, ".Rmd")))
# create the script and archive the .Rmd file
convert_to_script(dir = temp_path, filename = filename, archive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.