loadArgs: Load Function Arguments and Results From Files

Description Usage Arguments Value See Also Examples

Description

Read the function arguments and function results that were stored in RData files (in objects args and result, respectively) by a previous call of saveArgs.

Usage

1
loadArgs(functionName = NULL, data.dir = file.path(tempdir(), "test"))

Arguments

functionName

Name of the function to load arguments and results for. The name is used to create a search pattern for RData files in data.dir.

data.dir

Directory in which to look for RData files matching args_<functionName>_<hhmmss>_<no>.RData. The default is the subfolder test in tempdir().

Value

list with as many items as there were files args_<functionName>_* in the directory given in data.dir. Each list element has two components: args containing the arguments that were given to the function and result containing what the function returned.

See Also

saveArgs

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
25
26
# Define a function that stores its arguments and result with saveArgs
double <- function(x) {
  result <- 2 * x
  saveArgs("double", args = list(x = x), result = result)
  result
}

# Set global variable TESTMODE to "activate" saveArgs() in double()
TESTMODE <- TRUE

# Call the function a couple of times
double(4)
double(-99)
double(1:10)

# Load what was stored behind the scenes
testdata <- loadArgs("double")

# "Deactivate" saveArgs() in double()
TESTMODE <- FALSE

# Rerun the function with the stored arguments
results <- lapply(testdata, function(x) do.call("double", x$args))

# Compare the new with the old results
identical(results, lapply(testdata, "[[", "result"))

KWB-R/kwb.test documentation built on Sept. 12, 2019, 3:41 a.m.