Import list of data frames
Use import
to import a list of data frames from a vector of file names or from a multi-object file (Excel workbook, .Rdata file, zip directory, or HTML file)
import_list( file, setclass, which, rbind = FALSE, rbind_label = "_file", rbind_fill = TRUE, ... )
file |
A character string containing a single file name for a multi-object file (e.g., Excel workbook, zip directory, or HTML file), or a vector of file paths for multiple files to be imported. |
setclass |
An optional character vector specifying one or more classes to set on the import. By default, the return object is always a “data.frame”. Allowed values include “tbl_df”, “tbl”, or “tibble” (if using dplyr) or “data.table” (if using data.table). Other values are ignored, such that a data.frame is returned. |
which |
If |
rbind |
A logical indicating whether to pass the import list of data frames through |
rbind_label |
If |
rbind_fill |
If |
... |
Additional arguments passed to |
If rbind=FALSE
(the default), a list of a data frames. Otherwise, that list is passed to rbindlist
with fill = TRUE
and returns a data frame object of class set by the setclass
argument; if this operation fails, the list is returned.
library('datasets') export(list(mtcars1 = mtcars[1:10,], mtcars2 = mtcars[11:20,], mtcars2 = mtcars[21:32,]), "mtcars.xlsx") # import a single file from multi-object workbook str(import("mtcars.xlsx", which = "mtcars1")) # import all worksheets str(import_list("mtcars.xlsx"), 1) # import and rbind all worksheets mtcars2 <- import_list("mtcars.xlsx", rbind = TRUE) all.equal(mtcars2, mtcars, check.attributes = FALSE) # import multiple files export(mtcars, "mtcars.csv") export(mtcars, "iris.csv") str(import_list(dir(pattern = "csv$")), 1) # cleanup unlink("mtcars.xlsx") unlink("mtcars.csv") unlink("iris.csv")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.