data.table not updating by reference anymore

后端 未结 1 1651
走了就别回头了
走了就别回头了 2021-01-20 04:46

Here is a function

f <- function(orderData){
        colNames <- paste0(\"lim_\",sort(unique(orderData[,XLM])))
        orderData[, (colNames):={lim_=f         


        
1条回答
  •  北海茫月
    2021-01-20 05:23

    In both cases the length of the data table is 2 and the truelength is 100:

    > length(dt); truelength(dt)
    [1] 2
    [1] 100
    > length(dt1); truelength(dt1)
    [1] 2
    [1] 100
    

    however, in the case of dt colNames is 300 so 2+300 exceeds the truelength but in the case of dt1 colNames is 81 so 2+81 does not.

    You can either allocate a larger truelength in advance, e.g.

    alloc.col(dt, 1000)
    

    or you can set the default so that all data tables have a larger default:

    options(datatable.alloccol = 1000)
    

    See ?alloc.col ,

    0 讨论(0)
提交回复
热议问题