Is there a work around for slow performance of do.call(cbind.xts,…) in R 2.15.2?

前端 未结 1 939
心在旅途
心在旅途 2021-01-05 04:42

I would expect cbind.xts and do.call(cbind.xts) to perform with similar elapsed time. That was true for R2.11, R2.14.

For R2.15.2 and

相关标签:
1条回答
  • 2021-01-05 05:30

    One work-around is to set quote=TRUE in do.call.

    R> system.time(cb <- cbind.xts(d1,d2))
       user  system elapsed 
      0.004   0.000   0.004 
    R> system.time(dc <- do.call(cbind.xts, list(d1,d2), quote=TRUE))
       user  system elapsed 
      0.000   0.004   0.004 
    R> identical(cb,dc)
    [1] TRUE
    

    The slowness is caused by do.call evaluating the arguments before evaluating the function call by default, which causes the call to be much larger. For example, compare these two calls:

    call("cbind", d1, d2)                # huge
    call("cbind", quote(d1), quote(d2))  # dainty
    
    0 讨论(0)
提交回复
热议问题