excel - Passing List of Character Arguments to a Function -
the following function creates single excel file multiple sheets, each sheet containing contents of r object. works fine when list objects 1 one:
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) (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) } }
however, need work multiple datasets, each 1 containing 50 or more files, , it's tedious write them out 1 one every time.
so, tried following. first, created list of of sas files want add excel spreadsheet:
filenames <- list.files(pattern = "*.sas7bdat") mylist <- as.vector(unlist(strsplit(filenames,",")), mode="list")
then try use do.call execute function:
do.call(save.xlsx, c('myworkbook.xlsx', mylist))
i spreadsheet multiple tabs, contents of each tab name of sas file, not data itself.
can help, please?
Comments
Post a Comment