Description Usage Arguments Details Value Examples
Saves objects specified using dots and/or a list. Ensures that all names are unique (appending with "-uni_<ind>" for duplicated names). Ensures that all objects have names (appending with "-obj_<ind>") for objects without names.
1 2 3 4 5 6 7 8 9 10 11 |
... |
Objects to be saved. Preferrably specify name-value pairings, otherwise default values will be given. Objects are saved with the name appended by ".rds". |
obj_list |
list. List where the names (if supplied) are the
names to save the corresponding values in the list as. If names
are not supplied, then they will be created. Note that if you want to save ggplot2 plots as "PNG" or "PDF" images with
custom names, then you need to pass them to the function as a named list to the |
dir_proj |
character. |
dir_sub |
character vector or character list. Each element appends a new directory
to dir_proj, in the order they're given. If not provided, then |
empty |
logical. If |
silent |
logical. If |
gg_device |
'rds', 'png' or 'pdf. Specifies device to
save objects of class |
width, height |
numeric. Height and width to pass to |
Files that already exist before they are saved are deleted. This is to ensure that on Windows the "Date Modified" column in Windows Explorer updates.
invisible{TRUE}
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # standard use
dir_proj <- tempdir()
.save_objects(x = x, y = y, dir_proj = dir_proj, dir_sub = "test")
for(obj in c('x', 'y')) print(file.exists(file.path(dir_proj, "test",
paste0(obj, ".rds"))))
readRDS(file.path(dir_proj, "test", "x.rds"))
readRDS(file.path(dir_proj, "test", "y.rds"))
# ensure all objects have names
.save_objects('a', obj_list = list('c', 100, z = 4), dir_proj = dir_proj, dir_sub = "test") # warning printed
readRDS(file.path(dir_proj, "test", "obj_1.rds"))
readRDS(file.path(dir_proj, "test", "obj_2.rds"))
readRDS(file.path(dir_proj, "test", "obj_3.rds"))
readRDS(file.path(dir_proj, "test", "z.rds")) # objects with names given do not have names overwritten
# ensure that objects have unique names
.save_objects(x = 'a', x = 'b', dir_proj = dir_proj, dir_sub = "test") # warning printed
readRDS(file.path(dir_proj, "test", "x-uni_1.rds"))
readRDS(file.path(dir_proj, "test", "x-uni_2.rds"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.