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

DT[j ,c("COL1", "NEW_COL"):=list(COL2, newValue)] returns error if j does not match #2829

Closed
cguill95 opened this issue May 3, 2018 · 5 comments
Assignees
Milestone

Comments

@cguill95
Copy link

@cguill95 cguill95 commented May 3, 2018

The below script illustrates the issue

DT <- data.table(
COL_INT = 1L,
COL_INT_2 = 5L,
)

# Works
DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(9L, "Test")]

# Does not work
DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(COL_INT_2, "Test")]
@mattdowle
Copy link
Member

@mattdowle mattdowle commented May 3, 2018

Works for me. Please follow the Support Guide (e.g. point 3) and the issue template. "Does not work" is a well known unhelpful statement, referred to in the links in those guides.

@mattdowle mattdowle closed this May 3, 2018
@st-pasha
Copy link
Contributor

@st-pasha st-pasha commented May 3, 2018

I can reproduce the error with latest data.table just pulled from master:

R version 3.4.2 (2017-09-28) -- "Short Summer"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
> require(data.table)
Loading required package: data.table
data.table 1.11.1 IN DEVELOPMENT built 2018-05-03 18:45:22 UTC; pasha
  The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
  Documentation: ?data.table, example(data.table) and browseVignettes("data.table")
  Release notes, videos and slides: http://r-datatable.com
> DT <- data.table(COL_INT=1L, COL_INT_2=5L)
> DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(COL_INT_2, "Test")]
Error in `[.data.table`(DT, COL_INT == 0L, `:=`(c("COL_INT", "NEW_COL"),  : 
  RHS of assignment to existing column 'COL_INT' is zero length but not NULL. If you intend to delete the column use NULL. Otherwise, the RHS must have length > 0; e.g., NA_integer_. If you are trying to change the column type to be an empty list column then, as with all column type changes, provide a full length RHS vector such as vector('list',nrow(DT)); i.e., 'plonk' in the new column.

I presume the operation should have been a noop, given that i matched no rows (and if i did match some rows, j would have been a valid update statement too).

@st-pasha st-pasha reopened this May 3, 2018
@mattdowle
Copy link
Member

@mattdowle mattdowle commented May 3, 2018

Still works for me. What's the difference?

R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
> require(data.table)
Loading required package: data.table
data.table 1.11.1 IN DEVELOPMENT built 2018-05-03 21:05:11.755 UTC; mdowle
  The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
  Documentation: ?data.table, example(data.table) and browseVignettes("data.table")
  Release notes, videos and slides: http://r-datatable.com
> DT <- data.table(COL_INT=1L, COL_INT_2=5L)
> DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(9L, "Test")]
> DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(COL_INT_2, "Test")]
>

@st-pasha
Copy link
Contributor

@st-pasha st-pasha commented May 4, 2018

The difference is that you did DT[COL_INT == 0L, c("COL_INT", "NEW_COL"):=list(9L, "Test")] step first. Not sure why (maybe because it creates a key on COL_INT?), but it makes the following step work.

@MarkusBonsch MarkusBonsch self-assigned this May 9, 2018
@MarkusBonsch
Copy link
Contributor

@MarkusBonsch MarkusBonsch commented May 10, 2018

Seems very much related to
#759
#2690

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

Successfully merging a pull request may close this issue.

None yet
4 participants