Skip to content

Instantly share code, notes, and snippets.

@dpastoor
Created June 22, 2014 14:20
Show Gist options
  • Save dpastoor/29b76bdde130a8a5b8ba to your computer and use it in GitHub Desktop.
Save dpastoor/29b76bdde130a8a5b8ba to your computer and use it in GitHub Desktop.
save multiple to xlsx
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