-
Notifications
You must be signed in to change notification settings - Fork 991
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
Aggregation fails for list columns with closures that don't have class "function" #4814
Comments
> traceback()
10: as.list.default(X)
9: as.list(X)
8: lapply(x, runlock, current_depth = current_depth + 1L)
7: FUN(X[[i]], ...)
6: lapply(x, runlock, current_depth = current_depth + 1L)
5: FUN(X[[i]], ...)
4: lapply(x, runlock, current_depth = current_depth + 1L)
3: runlock(ans)
2: `[.data.table`(dt, , .(f2), by = id)
1: dt[, .(f2), by = id] The MAX_DEPTH = 5L
runlock = function(x, current_depth = 1L) {
if (is.recursive(x) && current_depth <= MAX_DEPTH) {
if (inherits(x, 'data.table')) .Call(C_unlock, x)
else return(lapply(x, runlock, current_depth = current_depth + 1L))
}
return(invisible())
}
runlock(ans) Now this illustrates the root cause: lapply(f, print)
#x
#$x
#
#
#[[2]]
#x
lapply(f2, print)
#Error in as.vector(x, "list") :
# cannot coerce type 'closure' to vector of type 'list' Closures are recursive. I think you need a |
Or |
MRE:
This issue is that you've erased
Still I think it is low overhead for us to add |
throws a similar error:
|
I think these issues can all be avoided by using a for loop instead of lapply. |
@Coorsaa could you please check if related PR fixed your use case? |
hi @jangorecki , |
Yes agree a loop instead of lapply would be better, especially at C level. For another day. |
I would expect the result of
.(f2)
aggregation to be similar to the.(f)
aggregation.(Maybe this is related to the fact that
as.list(f)
gives a result andas.list(f2)
fails? But I don't think it should fail since the content of thef
column is not the result ofas.list(f)
.)The text was updated successfully, but these errors were encountered: