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.

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

Examples


# 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)
#> [Set global variable TESTMODE to FALSE to prevent this message]
#> Save args to 'double' (y, n)? 
#> [1] 8
double(-99)
#> [Set global variable TESTMODE to FALSE to prevent this message]
#> Save args to 'double' (y, n)? 
#> [1] -198
double(1:10)
#> [Set global variable TESTMODE to FALSE to prevent this message]
#> Save args to 'double' (y, n)? 
#>  [1]  2  4  6  8 10 12 14 16 18 20

# Load what was stored behind the scenes
testdata <- loadArgs("double")
#> Error: No such file: 'test' in
#>   '/var/folders/c9/jqpw9nhs7jj7vm5185nyw05h0000gn/T//RtmprftjbG'.
#> Available files:
#>   'downlit'
#>   'file13435c749744'
#>   'file134361d2d374'
#>   'file134376e6f487'

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

# Rerun the function with the stored arguments
results <- lapply(testdata, function(x) do.call("double", x$args))
#> Error in eval(expr, envir, enclos): object 'testdata' not found

# Compare the new with the old results
identical(results, lapply(testdata, "[[", "result"))
#> Error in eval(expr, envir, enclos): object 'results' not found