different results for standard form and functional form of data.table assigne-by-reference `:=`

百般思念 提交于 2019-12-04 04:37:53

This is very good question that touches design decision about := operator.

For simple calls using := as an operator, like col := val, we decided to wrap val into a list automatically. This decision was made to make it more convenient for users to assign single column.

When you are using function call form, ":="(col = val) we are not wrapping val into list anymore. It is extended form already. := behaves as an alias to list but updating in-place. You can always check what will be the updated column by changing := into list (or .) like .(col = val).

Not that even when using := as an operator, you still have to provide RHS as list of you are creating 2+ columns, c("col1","col2") := list(val1, val2).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!