MakeObj: Automatically make & save or load an R object

Description Usage Arguments Details Note See Also Examples

View source: R/MakeObj.R

Description

MakeObj automatically generates an R object using the provided expression and saves the associated RDS file, or skips these two operations and loads the previously saved RDS file when it is available, or even avoids to do anything when the object is already defined in its parent environment.

The automation performed by MakeObj can be controlled by optional arguments and their corresponding global options which are accessible via the LittleThumb function (see the details section).

Usage

1

Arguments

...

at least an R symbol and an expression defining the corresponding R object. The symbol must be provided in first position and the expression in last position, both as unnamed arguments.

Details

The MakeObj function requires at least two arguments: an R symbol in the first position and an R expression in the last position, both being provided as unnamed arguments.

When evaluated, the provided expression must define the value of the R object to be automatically saved or loaded. For instance, the following line would automatically make/save/load an integer vector named x and containing values from 1 to 10:

MakeObj(x, { x <- 1:10 })

In addition, the following named arguments can be used in between the symbol and expression arguments (see LittleThumb):

path, relative, embedded, parent, makedir, reload, rebuild, cleanup, and messages

Note

MkObj can be used as a short alias of function MakeObj.

See Also

LittleThumb, DeleteObj

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 1. Configure global options --------------------------------------------------

# Here we choose the default location for automatically saved RDS files
LittleThumb(rootpath = "AutoSaved")

# 2. Define persistent R objects -----------------------------------------------

MakeObj(xyz, {

  # Here we compute the value of the object
  xyz <- 0

})

# 3. Do anything with defined R objects ----------------------------------------

print(xyz)

# Cleanup ======================================================================
DeleteObj(xyz)
unlink("AutoSaved", recursive = TRUE)

benja0x40/LittleThumb documentation built on Jan. 22, 2021, 2:36 p.m.