Skip to content
Prev 295119 / 398506 Next

write.xls

On Sun, May 20, 2012 at 7:15 PM, Spencer Graves
<spencer.graves at structuremonitoring.com> wrote:
Unfortunately this is getting increasingly complex due to the
non-standard evaluation done by dataframes2xls but if you want to do
it then this will do it.  We copy dataframes2xls to the current
environment and reset write.xls's environment so that it finds the
arguments.


run <- function(x1, x2, file){

   df.names <- paste0(deparse(substitute(x1)), ":::", deparse(substitute(x2)))

   # copy dataframe2xls namespace contents here & reset environment of write.xls
   here <- environment()
   ns <- asNamespace("dataframes2xls")
   for(nm in ls(ns)) here[[nm]] <- ns[[nm]]
   environment(write.xls) <- here

   x23 <- quote(c(x1, x2))
   do.call("write.xls", list(x23, file, sh.names = df.names))
}

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'

run(df1, df2, outFile)