FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`setNames` causes error when used with groupby (the `by` parameter) · Issue #4963 · Rdatatable/data.table · GitHub

setNames causes error when used with groupby (the by parameter) #4963

Description

Hi data.table team, this is the first time I'm reporting an issue to this repo. I have tried to search in release docs, other issues, stackoverflow, and have not found anything similar reported yet. If that's not true then I apologise for the trouble. I did not try this on latest dev version.

# [Minimal reproducible example]
In V1.14.0, the following gives an error. However, the exact same code in V1.12.8 works fine with valid output.

> library(data.table)
> dt = data.table(id=c(1:3), grp=c('a', 'a', 'b'), value=c(4:6))
> dt
   id grp value
1:  1   a     4
2:  2   a     5
3:  3   b     6

> dt[, by = grp, .(agg = list(setNames(as.list(value), id)))]
Error in lapply(x, runlock, current_depth = current_depth + 1L) : 
  'names' attribute [2] must be the same length as the vector [1]

Also, not sure if this is relevant but dplyr gives the same output in both versions of data.table, although with slightly different formatting, which I assume is merely a change of how data.table print out the list type in those two versions.

> dt %>% group_by(grp) %>% summarise(agg = list(setNames(as.list(value), id))) %>% data.table
`summarise()` ungrouping output (override with `.groups` argument)
   grp       agg
1:   a <list[2]>
2:   b <list[1]>

# Output of sessionInfo()

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.14.0

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL