R/loadRawData.R

Defines functions loadRawData

Documented in loadRawData

#' Load Data Sets into a List
#'
#' @param dataNames_char Names of data sets to load
#'
#' @return Loads data sets specified into the current function environment for
#'    further evaluation (unused) and then returns these data sets as a named
#'    list
#'
#' @details We may want to perform SQL-like operations on a set of tables
#'    without loading each table into R's Global Environment separately. This
#'    function loads these data sets into a self-destructing environment and
#'    then returns a named list of these data sets.
#'
#' @import public.ctn0094data
#' @importFrom magrittr `%>%`
#' @importFrom purrr map
#' @importFrom utils data
#' @export
#'
#' @examples
#'    loadRawData(c("tlfb", "all_drugs"))
loadRawData <- function(dataNames_char){
  # browser()

  dataNames_symb <-
    dataNames_char %>%
    map(as.name)

  here_env <- environment()
  dataHere <- function(...){
    data(..., envir = here_env)
  }

  do.call("dataHere", dataNames_symb)
  mget(dataNames_char)

}

Try the public.ctn0094extra package in your browser

Any scripts or data that you put into this service are public.

public.ctn0094extra documentation built on Nov. 22, 2023, 5:07 p.m.