You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
character column of x no longer available as ii in x[ y[ii] ] #3669
# example
library(data.table)
# data.table 1.12.3 IN DEVELOPMENT built 2019-06-19 19:02:40 UTC; travis using 4 threads (see ?getDTthreads). Latest news: r-datatable.com
iDT = data.table(key = "i_id",
i_id = c("A", "B", "C", "D"),
g = state.name[c(1,1,2, 3)],
e_date = as.IDate(c("2019-01-20", "2019-01-20", "2019-01-01", "2019-01-01")),
e_time = as.ITime(c("14:00", "20:00", "20:00", "20:00"))
)
set.seed(1)
vDT = data.table(i_id = unique(iDT$i_id))[, .(v = runif(5,0,10), p = sample(c(5,5,10,10,10))), by=i_id]
# old code that now errors due to bare i_id in the i= clause
vDT[c("B", "C", "A"), on=.(i_id), .N, by=.EACHI][iDT[i_id, order(e_date, e_time)]]
# longer/clearer version of the same
tmp = vDT[c("B", "C", "A"), on=.(i_id), .N, by=.EACHI]
tmp[iDT[i_id, order(e_date, e_time)]]
but the last line now yields
Error in [.data.table(iDT, i_id, forder(x, e_date, e_time)) :
i_id is not found in calling scope but it is a column of type character. If you wish to select rows where that column contains TRUE, or perhaps that column contains row numbers of itself to select, try DT[(col)], DT[DT$col], or DT[col==TRUE] is particularly clear and is optimized. When the first argument inside DT[...] is a single symbol (e.g. DT[var]), data.table looks for var in calling scope.
Contrary to the error message, i_id is in calling scope from tmp, right? Here's working code illustrating expected behavior:
tmp[iDT[tmp$i_id, order(e_date, e_time)]]
# i_id N
# 1: C 5
# 2: A 5
# 3: B 5
My code was confusing (took me a minute to figure out what I was trying to do before I could start debugging) so I don't mind if the idiom I used no longer works. I'm just bringing it up in case the scoping is intended to work there.
Reacted by Michael Chirico, MarkusBonsch and Matt Dowle
@MichaelChirico Thanks, yes, that works. I was just reporting since it used to work without needing to be wrapped in parentheses. If no one else minds the change in behavior and no rev deps are impacted either, maybe the issue could be closed.
Side note: I ran into a seg fault when messing around with the example, below. Please let me know if I should open a new issue.
@MichaelChirico on #3669 (comment), wrapping with paren like that returns a result by using the character column to join to itself (rather than the variable in calling scope which should work). But then the result is different (the NA is not desired). I'm assuming what @franknarf1 meant by 'it works' was really 'it doesn't error but it means something else and doesn't return what I need'.
Anyway, looks to be fixed now in dev. Just confirming what fixed it and adding tests...
Activity
MichaelChirico commentedon Sep 2, 2019
The advice of the error message works though right?
franknarf1 commentedon Sep 2, 2019
@MichaelChirico Thanks, yes, that works. I was just reporting since it used to work without needing to be wrapped in parentheses. If no one else minds the change in behavior and no rev deps are impacted either, maybe the issue could be closed.
Side note: I ran into a seg fault when messing around with the example, below. Please let me know if I should open a new issue.
MichaelChirico commentedon Sep 3, 2019
I wouldn't close as it is a regression. If we're going to break something we need to report it.
That code didn't segfault for me, please report in a new issue if it's still failing from dev master
mattdowle commentedon Oct 1, 2019
@MichaelChirico on #3669 (comment), wrapping with paren like that returns a result by using the character column to join to itself (rather than the variable in calling scope which should work). But then the result is different (the NA is not desired). I'm assuming what @franknarf1 meant by 'it works' was really 'it doesn't error but it means something else and doesn't return what I need'.
Anyway, looks to be fixed now in dev. Just confirming what fixed it and adding tests...