Skip to contents

search for saved R functions

Usage

grep_functions(
  grep_string = ".",
  save_date = ".",
  functions_path = jamsession_paths()$functions,
  ignore.case = TRUE,
  return_df = TRUE,
  most_recent = TRUE,
  verbose = FALSE,
  ...
)

Arguments

grep_string

character string with regular expression pattern, although usually any text substring will work.

  • Note that input may contain the date as seen in rownames() of list_functions() output. 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.

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.

verbose

logical whether to print verbose output

...

additional arguments are passed to grepl().

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.

Value

one of:

  • When return_df=TRUE it returns data.frame

  • Otherwise character vector.

Details

This function searches for saved R functions in the appropriate file paths as defined in jamsession_paths(), using jamsession_paths()$functions, or customized with argument functions_path.

It is possible to supply multiple file paths using the argument functions_path. All functions are returned, sorted by save_date, then by the order of functions_path. So a file saved on the same date will be returned by first entry in functions_path.

When using most_recent=TRUE, only the first entry is returned, using the most recent entry ordered by functions_path.

For example, refresh_functions(grep_functions("myfunctions")) will load the most recent function by save_date where any ties prefer the order in functions_path. Similarly, refresh_functions("my_favorite_function") does the same thing, without the grep_patten search step.

See also

Other jamsession functions: list_functions_exports(), refresh_functions()