Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

export_list

Export list of data frames to files


Description

Use export to export a list of data frames to a vector of file names or a filename pattern.

Usage

export_list(x, file, ...)

Arguments

x

A list of data frames to be written to files.

file

A character vector string containing a single file name with a %s wildcard placeholder, or a vector of file paths for multiple files to be imported. If x elements are named, these will be used in place of %s, otherwise numbers will be used; all elements must be named for names to be used.

...

Additional arguments passed to export.

Details

export can export a list of data frames to a single multi-dataset file (e.g., an Rdata or Excel .xlsx file). Use export_list to export such a list to multiple files.

Value

The name(s) of the output file(s) as a character vector (invisibly).

See Also

Examples

library('datasets')
export(list(mtcars1 = mtcars[1:10,], 
            mtcars2 = mtcars[11:20,],
            mtcars3 = mtcars[21:32,]), "mtcars.xlsx")

# import all worksheets
mylist <- import_list("mtcars.xlsx")

# re-export as separate named files
export_list(mylist, file = paste0("mtcars", 1:3, ".csv"))

# re-export as separate files using a name pattern
export_list(mylist, file = "%s.csv")

# cleanup
unlink("mtcars.xlsx")
unlink("mtcars1.csv")
unlink("mtcars2.csv")
unlink("mtcars3.csv")

rio

A Swiss-Army Knife for Data I/O

v0.5.26
GPL-2
Authors
Jason Becker [ctb], Chung-hong Chan [aut], Geoffrey CH Chan [ctb], Thomas J. Leeper [aut, cre] (<https://orcid.org/0000-0003-4097-6326>), Christopher Gandrud [ctb], Andrew MacDonald [ctb], Ista Zahn [ctb], Stanislaus Stadlmann [ctb], Ruaridh Williamson [ctb], Patrick Kennedy [ctb], Ryan Price [ctb], Trevor L Davis [ctb], Nathan Day [ctb], Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>), Alex Bokov [ctb] (<https://orcid.org/0000-0002-0511-9815>)
Initial release
2021-02-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.