Skip to content

Commit

Permalink
export readRDS_or_return_alt_data() (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman authored Apr 27, 2024
1 parent f00b1a4 commit 0d0029d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(empty_portfolio_results)
export(get_build_version_msg)
export(log_user_errors)
export(quit_if_no_pacta_relevant_data)
export(readRDS_or_return_alt_data)
export(remove_if_exists)
export(save_if_exists)
export(set_analysis_inputs_path)
Expand Down
12 changes: 12 additions & 0 deletions R/readRDS_or_return_alt_data.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#' Return the object stored in a RDS at a specified file path, or an alternate
#' value/object if the file doesn't exist.
#'
#' @param filepath a single string containing a file path to a RDS file
#' @param alt_return an R object/value to be returned if the file at `filepath`
#' does not exist
#'
#' @return an object, either the object stored in the RDS at the `filepath` or
#' the value of `alt_return`
#'
#' @export

readRDS_or_return_alt_data <- function(filepath, alt_return = NULL) {
if (file.exists(filepath)) {
return(readRDS(filepath))
Expand Down
23 changes: 23 additions & 0 deletions man/readRDS_or_return_alt_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d0029d

Please sign in to comment.