[R] write.xls

Marc Schwartz marc_schwartz at me.com
Sun May 20 15:56:29 CEST 2012


On May 20, 2012, at 7:30 AM, Gabor Grothendieck wrote:

> On Sat, May 19, 2012 at 9:32 PM, Spencer Graves
> <spencer.graves at structuremonitoring.com> wrote:
>> Hello, All:
>> 
>> 
>>      The "writeFindFn2xls" function in the "sos" package tries to write an
>> Excel file with 3 sheets ('PackageSum2', 'findFn', 'call'). Unfortunately,
>> it is often unable to do this because of configuration problems that are not
>> easy to fix.  I've found 3 contributed packages that provide facilities to
>> write Excel files with multiple sheets. Unfortunately, I can't get any of
>> them to work consistently for me. Below please find test cases that
>> illustrate the problems.  Any suggestions for how to solve this problem will
>> be appreciated.
>> 
>> 
>>      Thanks,
>>      Spencer
>> 
>> 
>> library(dataframes2xls)
>> 
>> df1 <- data.frame(c1=1:2, c2=3:4, c3=5:6)
>> df2 <- data.frame(c21=c(10.10101010101,20, 3), c22=c(50E50,60, 3) )
>> outFile <- 'df12.xls'
>> 
>> write.xls(c(df1,df2), outFile)
>> # works
>> 
>> do.call(write.xls, list(c(df1, df2), outFile))
>> # Error in get(s[i]) : object 'structure(list(c1=1:2' not found
>> 
> 
> Try this:
> 
> dd <- list(df1 = df1, df2 = df2)
> do.call("WriteXLS", list("dd", outFile))
> 
> or this:
> 
> do.call("WriteXLS", list(c("df1", "df2"), outFile)



Thanks Gabor. Note that since WriteXLS version 2.0 (2010), WriteXLS can accept a named list and write out each list element data frame to an XLS file. An example is given in ?WriteXLS:

  iris.split <- split(iris, iris$Species)
  WriteXLS("iris.split", "irissplit.xls")

You end up with a worksheet in the XLS file for each factor level in iris$Species.

Regards,

Marc Schwartz



More information about the R-help mailing list