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

Created NULL column somehow? #3089

Closed
MichaelChirico opened this issue Oct 2, 2018 · 2 comments
Closed

Created NULL column somehow? #3089

MichaelChirico opened this issue Oct 2, 2018 · 2 comments
Labels
Milestone

Comments

@MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented Oct 2, 2018

Was trying to swap values from a column into another column and erase the original values; I made a mistake in doing so:

set.seed(20349)
DT = data.table(
  a = rnorm(10)
)
DT[a < 0, c('a', 'b') := .(NULL, a)]

Which correctly errors:

Error in [.data.table(DT, a < 0, :=(c("a", "b"), .(NULL, a))) : When deleting columns, i should not be provided

However, now DT is corrupted:

DT
#              a    b
#  1:  0.6667242 NULL
#  2: -1.8261938 NULL
#  3:  0.2047286 NULL
#  4: -0.4425548 NULL
#  5: -0.6238520 NULL
#  6: -1.9680856 NULL
#  7:  0.2002663 NULL
#  8: -0.1607745 NULL
#  9:  0.0206196 NULL
# 10:  0.3074775 NULL

DT$b
# NULL

DT[is.na(b)]

Error in [.data.table(DT, is.na(b)) : SETLENGTH() can only be applied to a standard vector, not a 'NULL'

DT[ , b := NULL]

Error in ans[[target]] : subscript out of bounds

Seems the only way to clean the table is with a copy:

DT = DT[ , !'b']

Obviously what I tried is wrong (I meant to have .(NA, a) on the RHS), but it seems this mistake has cascaded...

@DavidArenburg
Copy link
Member

@DavidArenburg DavidArenburg commented Oct 2, 2018

You can also remove it using DT[["b"]] <- NULL (which also makes a copy). Also DT[1] crashes my R session. Interesting edge case

@mrdwab
Copy link

@mrdwab mrdwab commented Oct 2, 2018

In case it helps, set seems to work:

packageVersion("data.table")
# [1] ‘1.11.8’
set(DT, j = "b", value = NULL)
str(DT)
# Classes ‘data.table’ and 'data.frame':	10 obs. of  1 variable:
#  $ a: num  0.667 -1.826 0.205 -0.443 -0.624 ...
#  - attr(*, ".internal.selfref")=<externalptr> 

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

5 participants