Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing (and adding) a column by reference on null data.table need not error #2335

Closed
arunsrinivasan opened this issue Sep 7, 2017 · 0 comments
Labels
Milestone

Comments

@arunsrinivasan
Copy link
Member

@arunsrinivasan arunsrinivasan commented Sep 7, 2017

require(data.table) # CRAN stable at the moment, will update after testing from home on devel.
dt <- data.table()
dt[, col := NULL]
# Error in `[.data.table`(dt, , `:=`(col, NULL)) : 
#   Cannot use := to add columns to a null data.table (no columns), currently. You can use := 
#        to add (empty) columns to a 0-row data.table (1 or more empty columns), though.

I see this error mentioned in NEWS in 1.8.10! Didn't expect it to be that long ago. There's no issue number mentioned there.

Firstly I feel perhaps a warning would be sufficient instead of an error message?

And more importantly, removing a column on a null data.table could simply return the empty table without any error/warning, or for consistency, with a warning (assuming change to 'warning' goes through). Also the error/warning message should mention about 'removing' cols as well (minor).

The inconvenience with the way it is currently is that, when tables (/files) are being read off disk, and some tables don't exist, a null data.table is returned, and this error results in having an if() check everywhere before adding/removing cols by reference during downstream manipulations, which I find is unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant