R/make_copy.R

Defines functions make_copy

Documented in make_copy

#' Duplicate an object in the global environment
#'
#' Duplicate an oject in the global environment, so that one version can be modified without losing the previous version. Useful for testing modifications to objects generated by time-consuming code.
#' @param var_name character string, the name of the object to be copied.
#' @param append character string, the text to be appended to the object's name when making the copy. Defaults to ".old".
#' @param envir the name of the environment in which to make the changes. Defaults to the global environment, \code{.GlobalEnv}.
#' @export
#' @usage make_copy(var_name, append=".old", envir=.GlobalEnv)
make_copy <- function(var_name, append=".old", envir=.GlobalEnv) {
  assign(paste0(var_name, append), get(var_name, envir=envir), envir = envir)
}
mjdufort/miscHelpers documentation built on Feb. 4, 2024, 7:44 p.m.