save R object to a central location

save_object(
  object_list,
  save_date = jamba::getDate(),
  objects_path = jamsession_paths()$objects,
  object_notes_list = "",
  do_file_info = FALSE,
  object_suffix = ".RData",
  envir = globalenv(),
  verbose = TRUE,
  ...
)

Arguments

object_list

character vector of object names to save, typically only one value.

save_date

character date string to use when naming the file, typically the current date is used.

objects_path

character vector of one or more file paths to search for saved R objects. When objects_path=NULL, it uses the output from jamsession_paths()$objects.

object_notes_list

character vector of optional notes associated with the R object. Intended as a crude way to allow describing an object.

do_file_info

logical whether to print information about the saved .RData file, for example including the size.

envir

the environment from which to obtain the R object.

Value

invisible file path loaded

Details

This function saves a single R object to an .RData file, versioned by date using jamba::getDate(), so it can be discovered and re-used by other R sessions.

When multiple objects should be saved together, the recommended method:

  • create a list object that includes these objects

  • save this list object using save_object()

However, when multiple objects are supplied in object_list, the object names are concatenated with "-" and this string is used to define the saved R object file. For example save_object(c("df1", "df2")) will save an R object file using the string "df1-df2". When this file is loaded, two R objects are loaded into the environment: "df1" and "df2". While not always ideal, this mechanism may be more convenient, and it is left for the user to decide which is best.

Note that objects_path may contain multiple directories, and when this occurs, the directories are attempted in order. The R object is saved to the first directory that allows the file to be saved successfully.

See also

Other jamsession objects: grep_objects(), list_objects(), load_object()