Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Export elements of a list to separate excel files in R

I’ve got a list of 24 dataframes and I’m wondering if there’s an easy way to export each element to it’s own excel file from R, preferably using the name of the list element in the excel file’s title?

I know I can do write.xlsx(listofdfs, "newexcelfilename.xlsx") and it will put each element into it’s own worksheet within the file, but in my case I’ll eventually need to email these files separately so it’s best if I can get them into their own individual excel files. Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may use any of the apply function in base R. For example, using Map

Map(openxlsx::write.xlsx, listofdfs, paste0(names(listofdfs), '.xlsx'))

Also with purrr::imap

purrr::imap(listofdfs, ~openxlsx::write.xlsx(.x, paste0(.y, '.xlsx')))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading