| shell_script | R Documentation |
Create a shell script for a data analysis workflow consisting of commands extracted from existing R files.
shell_script(
path_files,
dir_shell = NULL,
name_shell = "workflow.sh",
overwrite = FALSE,
quiet = FALSE
)
path_files |
A path from |
dir_shell |
The directory where
|
name_shell |
The name of the shell script.
The default is |
overwrite |
Whether to overwrite
an existing shell script. Default is |
quiet |
Whether to suppress
progress messages. Default is |
To create a shell script in the files
directory, set files to ".".
To obtain the contents of the shell script
without creating a file on disk,
creating the file on disk, set
name_shell to NULL.
Supplying a value for files is
compulsory for shell_script(),
but optional for makefile().
The output from shell_script()
is generated entirely from files
while the output from makefile()
also includes some general-purpose Makefile
commands.
shell_script() is called for its
side effect, which is to create a
file. However, shell_script() also
returns a string with the contents of the
shell script.
Episodes 1–3 of The Unix Shell Introduction to the command line
Command-Line Programs Introduction to Rscript
Creating a Shell Script More on shell_script()
extract_shell() Turn a cmd_assign() call into a shell command
makefile() Makefile equivalent of shell_script()
cmd_assign() Process command line arguments
Modular Workflows for Data Analysis Safe, flexible data analysis workflows
littler Alternative to Rscript
library(fs)
library(withr)
with_tempdir({
## create 'src' directory
dir_create("src")
## put R scripts containing calls to
## 'cmd_assign' in the 'src' directory
writeLines(c("cmd_assign(x = 1, .out = 'out/results.rds')",
"results <- x + 1",
"saveRDS(results, file = .out)"),
con = "src/results.R")
writeLines(c("cmd_assign(x = 1, .out = 'out/more_results.rds')",
"more_results <- x + 2",
"saveRDS(more_results, file = .out)"),
con = "src/more_results.R")
## call 'shell_script()'
shell_script(path_files = "src",
dir_shell = ".")
## shell script has been created
dir_tree()
## print contents of shell script
cat(readLines("workflow.sh"), sep = "\n")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.