load_scripts: Load R scripts within factory folder

Description Usage Arguments Examples

View source: R/load_scripts.R

Description

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.

Usage

1
load_scripts(factory = ".", folder = "scripts", quiet = FALSE)

Arguments

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 .R files; defaults to scripts/.

quiet

A logical indicating whether messages should be displayed to the console (TRUE, default), or not.

Examples

 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)
}

reconhub/rfextras documentation built on Aug. 16, 2021, 5:25 a.m.