R/read_rda.R

Defines functions read_rda

Documented in read_rda

#' @name read_rda
#'
#' @title Read an .rda file and return its contents
#'
#' @description Reads the contents of an .RData file into a separate environment
#' (to avoid overwriting existing variables) and returns the contents for assignment
#' to your own variable names.
#'
#' @param file a string with the file name and path.
#'
#' @return An object or list of objects stored in \code{file}.
#' @export


read_rda <- function(file){

    env <- new.env()
    new_objnms <- load(file, env)

    # If file had multiple objects, build a list to return
    out <-
        if(length(new_objnms) == 1) get(new_objnms, envir = env)
    else mget(new_objnm, envir = env)

    return(out)
}
coletl/coler documentation built on May 12, 2021, 9:44 p.m.