R/xlsx.reader.R

Defines functions xlsx.reader

Documented in xlsx.reader

#' @describeIn preinstalled.readers Read an Excel 2007 file with a \code{.xlsx} file extension.
#'
#' This function will load the specified Excel file into memory using the
#' \code{readxl} package.
xlsx.reader <- function(data.file, filename, workbook.name)
{
  .require.package('readxl')

  sheets <- readxl::excel_sheets(filename)

  for (sheet.name in sheets)
  {
    variable.name <- paste(workbook.name, clean.variable.name(sheet.name), sep = ".")
    tryCatch(assign(variable.name,
                    data.frame(readxl::read_excel(filename,
                                       sheet = sheet.name)),
                    envir = .TargetEnv),
             error = function(e)
             {
               warning(paste("The worksheet", sheet.name, "didn't load correctly."))
             })
  }
}

Try the ProjectTemplate package in your browser

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

ProjectTemplate documentation built on July 31, 2021, 5:07 p.m.