Description Usage Arguments Examples
This helper function will load all .R
scripts within a specified factory
and folder. All scripts are loaded within the calling environment and in
alphanumeric order.
1 | load_scripts(factory = ".", folder = "scripts", quiet = FALSE)
|
factory |
The path to the report factory or a folder within the desired factory. Defaults to the current directory. |
folder |
The folder (relative to the factory) from which to source |
quiet |
A logical indicating whether messages should be displayed to the
console ( |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | if (require(reportfactory)) {
# create factory
f <- new_factory(path = tempdir(), move_in = FALSE)
# create .R files in scripts/
## scripts are loaded in alphanumeric order, so "b.R" is loaded after "a.R" and
## can use its content
cat("addone <- function(x) x + 1", file = file.path(f, "scripts", "addone.R"))
cat("a <- 2L", file = file.path(f, "scripts", "a.R"))
cat("b <- 2L + a", file = file.path(f, "scripts", "b.R"))
## load scripts, check that 'a', 'b', and 'addone' exist
load_scripts(f)
a
b
addone(10)
addone(c(a, b))
# cleanup
unlink(f, recursive = TRUE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.