Created
June 22, 2014 14:20
-
-
Save dpastoor/29b76bdde130a8a5b8ba to your computer and use it in GitHub Desktop.
save multiple to xlsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
save.xlsx <- function (file, ...) | |
{ | |
require(xlsx, quietly = TRUE) | |
objects <- list(...) | |
fargs <- as.list(match.call(expand.dots = TRUE)) | |
objnames <- as.character(fargs)[-c(1, 2)] | |
nobjects <- length(objects) | |
for (i in 1:nobjects) { | |
if (i == 1) | |
write.xlsx(objects[[i]], file, sheetName = objnames[i]) | |
else write.xlsx(objects[[i]], file, sheetName = objnames[i], | |
append = TRUE) | |
} | |
print(paste("Workbook", file, "has", nobjects, "worksheets.")) | |
} | |
Then | |
save.xlsx("myworkbook.xlsx", mtcars, Titanic, AirPassengers, state.x77) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment