R/restore.R

Defines functions restore

Documented in restore

#' Restores a backed up object
#'
#' Function takes the name of the object and checks if there is a backup of it;
#' if there is, restores it.
#'
#' @param object the object to restore (use the original name, not the one with
#'   "_bak").
#' @keywords backup, restore
#' @export
#' @examples
#' (test <- 1:10)
#' backup(test)
#' (test <- 11:20)
#' (restore(test))

restore <-
  function(object) {

    bak_name <-
      paste0(deparse(substitute(object)),
             "_bak")

    if(exists(bak_name)) {
      assign(deparse(substitute(object)),
             get(bak_name),
             pos = parent.frame())
    } else {
      warning(paste0("No backup found for '",
                     deparse(substitute(object)),
                     "'"))
    }
  }
mtcruz/mtcruzr documentation built on Dec. 26, 2019, 11:04 p.m.