ifnofile: Run if file does (not) exist, else load file

Description Usage Arguments Author(s) Examples

View source: R/RFunctions.R

Description

Check if a file exists, and if it doesn't, run an expression, and save the resulting objects to the specified filename. Useful when writing Rmarkdown reports with time-intensive analyses; these can be run once and then saved.

Usage

1
ifnofile(filename, expr)

Arguments

filename

Check whether this file exists or not. If it does exist, load the contents of that file into the global environment.

expr

An expression to be evaluated if the filename does not exist. Multiple expressions should be enclosed in curly braces. Objects created by this expression are stored in a file called filename.

Author(s)

Caspar J. van Lissa

Examples

1
2
3
4
5
6
7
8
ifnofile("example.RData", {
  a <- 1
  b <- 2
})
ifnofile("example.RData", {
  a <- 1
  b <- 2
})

cjvanlissa/motley documentation built on Sept. 23, 2019, 7:39 p.m.