grep_objects: search for saved R objects

grep_objectsR Documentation

search for saved R objects

Description

search for saved R objects

Usage

grep_objects(
  grep_string = ".",
  save_date = ".",
  objects_path = jamsession_paths()$objects,
  ignore.case = TRUE,
  return_df = TRUE,
  most_recent = TRUE,
  add_stats = FALSE,
  verbose = FALSE,
  ...
)

Arguments

grep_string

character string with regular expression pattern, although usually any text substring will work. When grep_string contains multiple values, they are used in order to find matching object names, using jamba::provigrep(). The order typically has no effect, but can be used to retain the order of objects returned even when the objects have the same save_date.

save_date

character string or vector, used as a regular expression search for matching values in the save_date column output from list_objects(). It can be used to search for objects with a specific save_date. Remember to use most_recent=FALSE when searching for past versions of stored R objects.

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.

ignore.case

logical passed to grep() indicating whether to ignore upper and lower case, by default ignore.case=TRUE.

return_df

logical indicating whether to return a data.frame.

most_recent

logical whether to return only the most recent saved version of each matching object, by default most_recent=TRUE. Note that it returns the most recent of each matching object.

add_stats

logical indicating whether to include summary stats for each object: number_saved is the number of past versions of the object; total_size is the total file size for all saved versions.

verbose

logical whether to print verbose output

...

additional arguments are passed to grepl().

Details

This function searches for saved R objects using one or more text or regular expression patterns.

It is possible to supply multiple file paths using the argument objects_path, in which case all objects are returned for all directories, then they are sorted by save_date. The input objects_path is stored as an ordered factor, such that two files with the same save_date will still be ordered consistent with the input directories in objects_path. In this case, when most_recent=TRUE there will be one entry returned per object name, and the first entry will be the most recent entry ordered by objects_path. In practice, it is recommended to use one objects_path location, but this option exists.

For example, load_object(grep_objects("my_favorite_object")) will load the most recent object by save_date where any ties prefer the order in objects_path. Similarly, load_object("my_favorite_object") does the same thing, without the grep_patten search step.

See save_object() for examples.

Value

data.frame when return_df=TRUE; character vector when return_df=FALSE. The returned data will contain object names that match the grep_string input.

See Also

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


jmw86069/jamsession documentation built on June 8, 2022, 8:47 p.m.