load R object by name
load_object( object, save_date = NULL, objects_path = jamsession_paths()$objects, envir = globalenv(), verbose = TRUE, ... )
object |
|
---|---|
save_date | optional character string with a specific date to
use when loading an object. This string is matched with
the |
objects_path | character vector of one or more file paths to
search for saved R objects. When |
envir | optional R environment inside which to load the R object.
Note that if an R object already exists in this environment,
it will overwritten without warning. This behavior is intended
by |
verbose | logical whether to print verbose output |
... | additional arguments are ignored. |
invisible name of the R object loaded. It also loads the R object into the environment specified, by default the active global environment .GlobalEnv.
This function loads the most recently saved R object by name, from a given file path. This mechanism is intended to help share useful R objects across R sessions, especially where it may be helpful to discover R objects by name, and where R objects may continue to be useful over time.
Typically this function is called with the name of one or more saved
objects, and loads the most recent version of each. However, the argument
save_date
can be supplied as a vector, which is recycled for each
saved object, as a method to load a specific version of an object.
This behavior is not intended for routine use, but is available
in rare cases that you may want to inspect previous versions of
an object.
Note that envir
can be used to load the object into a separate
environment, if needed.
Other jamsession objects:
grep_objects()
,
list_objects()
,
save_object()
#> A a #> 1 A a #> 2 B b #> 3 C c #> 4 D d #> 5 E e#> Error in save_object("my_df"): Object could not be saved.#> object save_date days_old file_size #> my_df_12jun2020 my_df 12jun2020 259 160 bytes #> my_df-my_df2_12jun2020 my_df-my_df2 12jun2020 259 212 bytes #> object_path #> my_df_12jun2020 /Users/wardjm/Projects/R-objects #> my_df-my_df2_12jun2020 /Users/wardjm/Projects/R-objects #> object_file #> my_df_12jun2020 my_df_12jun2020.RData #> my_df-my_df2_12jun2020 my_df-my_df2_12jun2020.RData#> Warning: no non-missing arguments to min; returning Inf#> Warning: no non-missing arguments to max; returning -Inf#> Warning: no non-missing arguments to min; returning Inf#> Warning: no non-missing arguments to max; returning -Inf#> ## (11:51:44) 26Feb2021: load_object(): Loaded object: 'my_df'#> A a #> 1 A a #> 2 B b #> 3 C c #> 4 D d #> 5 E e#> ## (11:51:44) 26Feb2021: load_object(): Loaded object: 'my_df' #> ## (11:51:44) 26Feb2021: load_object(): Loaded objects: my_df,my_df2#> A a #> 1 A a #> 2 B b #> 3 C c #> 4 D d #> 5 E e#> Warning: object 'my_df' not found#> ## (11:51:44) 26Feb2021: load_object(): Loaded object: 'my_df'#> [1] ".GlobalEnv"#> A a #> 1 A a #> 2 B b #> 3 C c #> 4 D d #> 5 E e#> [1] ".GlobalEnv"#>#> #>#> [1] ".GlobalEnv" "sep_env"#> [1] ".GlobalEnv"###################################### # example showing two objects stored together my_df2 <- data.frame(B=LETTERS[11:15], b=letters[11:15]); load_object("my_df");#> ## (11:51:44) 26Feb2021: load_object(): Loaded object: 'my_df'#> ## (11:51:44) 26Feb2021: save_objects(): Objects saved:~/Projects/R-objects/my_df-my_df2_26feb2021.RData#> object save_date days_old file_size #> my_df-my_df2_26feb2021 my_df-my_df2 26feb2021 0 212 bytes #> object_path #> my_df-my_df2_26feb2021 /Users/wardjm/Projects/R-objects #> object_file #> my_df-my_df2_26feb2021 my_df-my_df2_26feb2021.RData#> ## (11:51:44) 26Feb2021: load_object(): Loaded objects: my_df,my_df2#> [1] "my_df" "my_df2"