convert_to_script {sdtmval} | R Documentation |
Convert SDTM QC code from a .Rmd file to .R script
Description
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.
Usage
convert_to_script(filename, dir = NULL, archive = FALSE)
Arguments
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
|
Details
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
Value
nothing
See Also
Examples
# 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)