SaveObj: Save the RDS file associated to an R object

Description Usage Arguments Details See Also Examples

View source: R/SaveObj.R

Description

Save the RDS file associated to an R object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SaveObj(
  obj,
  path = NULL,
  name = NULL,
  parent = NULL,
  parent.name = NULL,
  relative = NULL,
  embedded = NULL,
  messages = NULL,
  makedir = NULL,
  origin = parent.frame()
)

Arguments

obj

an R object.

path

folder location for RDS files. LittleThumb interprets this path either as a sub-directory of the rootpath location, or as an independent location (see relative). By default path is ignored (path = NA).

name

RESERVED FOR INTERNAL USE: optional name of the R object. When omitted this name is automatically provided by the symbol being passed as first argument using substitute and deparse.

parent

environment where the R object should be located. By default parent is the parent.frame of the function being called.

parent.name

optional name of the parent environment.

relative

logical value controlling if the path option is interpreted as a relative location, meaning as a sub-directory of the rootpath location (default = TRUE, yes), or as an independent one.

embedded

logical value controlling whether child objects should have their associated RDS files organized into sub-directories corresponding to parent objects (default = TRUE, yes).

messages

logical value enabling or disabling status messages from LittleThumb functions (default = TRUE, enabled).

makedir

logical value controlling if non-existing folders should be created automatically when necessary (default = TRUE, yes).

origin

RESERVED FOR INTERNAL USE: parent.frame of the initial function call.

Details

When unspecified, the value of the following argument(s) are determined by the corresponding automation option(s) (see LittleThumb):

parent, relative, embedded, makedir and messages

See Also

MakeObj, LittleThumb

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Create a simple R object named 'a'
a <- 1:10

# Save object a in the current working directory
SaveObj(a)

# Simulate restarting the R environment
rm(a)

# Check if object a is available in the R environment (FALSE)
exists("a")

# Check if an RDS file is available for object a (TRUE)
AvailableObj(a)

# Load object a from the current working directory
LoadObj(a)

print(a)

# Delete the RDS file associated to object a and remove the object itself
DeleteObj(a)

# Now both lines below should return FALSE
AvailableObj(a)
exists("a")

# A verbose way to automatically make/save/load the object 'a' (don't use this)
if(AvailableObj(a)) {
  LoadObj(a)
} else {
  a <- 1:10
  SaveObj(a)
}

# Automatically make/save/load the object 'a'
MakeObj(a, { a <- 1:10 })

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

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