library('datasets')
export(list(mtcars1 = mtcars[1:10,],
mtcars2 = mtcars[11:20,],
mtcars3 = mtcars[21:32,]),
xlsx_file <- tempfile(fileext = ".xlsx")
)
# import a single file from multi-object workbook
str(import(xlsx_file, which = "mtcars1"))
# import all worksheets
str(import_list(xlsx_file), 1)
# import and rbind all worksheets
mtcars2 <- import_list(xlsx_file, rbind = TRUE)
all.equal(mtcars2[,-12], mtcars, check.attributes = FALSE)
# import multiple files
wd <- getwd()
setwd(tempdir())
export(mtcars, "mtcars1.csv")
export(mtcars, "mtcars2.csv")
str(import_list(dir(pattern = "csv$")), 1)
unlink(c("mtcars1.csv", "mtcars2.csv"))
setwd(wd)
# cleanup
unlink(xlsx_file)
Run the code above in your browser using DataLab