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

groupingsets() adding an extra column with named vectors? #5206

Closed
sindribaldur opened this issue Oct 11, 2021 · 5 comments · Fixed by #5227
Closed

groupingsets() adding an extra column with named vectors? #5206

sindribaldur opened this issue Oct 11, 2021 · 5 comments · Fixed by #5227

Comments

@sindribaldur
Copy link

sindribaldur commented Oct 11, 2021

groupingsets(
  data.table(iris),
  j = mean(Sepal.Length),
  by = c('Sp' = 'Species'),
  sets = list('Species')
)
     Sp    V1    Species
1: <NA> 5.006     setosa
2: <NA> 5.936 versicolor
3: <NA> 6.588  virginica

I'm using latest development version of data.table and R 4.1.0. This seems not to have been the behaviour about three months ago when I last ran the code that now broke.

@jangorecki
Copy link
Member

Could you check verbose=T (if there is)? I think it may not be related to groupingsets, it calls ordinary dt code under the hood.

@sindribaldur
Copy link
Author

Setting options(datatable.verbose = TRUE) I get:

Argument 'by' after substitute: by
i clause present and columns used in by detected, only these subset: [Species]
Detected that j uses these columns: [Sepal.Length]
lapply optimization is on, j unchanged as 'mean(Sepal.Length)'
Old mean optimization changed j from 'mean(Sepal.Length)' to '.External(Cfastmean, Sepal.Length, FALSE)'
Making each group and running j (GForce FALSE) ... 
  memcpy contiguous groups took 0.000s for 1 groups
  eval(j) took 0.000s for 1 calls
0.010s elapsed (0.020s cpu) 
Argument 'by' after substitute: by.set
Detected that j uses these columns: [Sepal.Length]
Finding groups using forderv ... forder.c received 150 rows and 1 columns
0.000s elapsed (0.000s cpu) 
Finding group sizes from the positions (can be avoided to save RAM) ... 0.000s elapsed (0.000s cpu) 
lapply optimization is on, j unchanged as 'mean(Sepal.Length)'
GForce optimized j to 'gmean(Sepal.Length)'
Making each group and running j (GForce TRUE) ... gforce initial population of grp took 0.002
gforce assign high and low took 0.000
This gmean took (narm=FALSE) ... gather took ... 0.000s
0.000s
gforce eval took 0.001
0.020s elapsed (0.000s cpu) 

@jangorecki
Copy link
Member

Hm, it was split function that had verbose arg. Grouping sets doesn't provide this level of debug.

@sindribaldur
Copy link
Author

I removed development version and installed again from CRAN and the issue is gone.

@ben-schwen
Copy link
Member

ben-schwen commented Oct 18, 2021

For reproduceability and can confirm that there is an issue/changing behavior

# 1.14.2
groupingsets(
  data.table(iris),
  j = mean(Sepal.Length),
  by = c('Sp' = 'Species'),
  sets = list('Species')
)
#       Species    V1
#        <fctr> <num>
# 1:     setosa 5.006
# 2: versicolor 5.936
# 3:  virginica 6.588

# current dev 1.14.3
groupingsets(
  data.table(iris),
  j = mean(Sepal.Length),
  by = c('Sp' = 'Species'),
  sets = list('Species')
)
#        Sp    V1    Species
#    <fctr> <num>     <fctr>
# 1:   <NA> 5.006     setosa
# 2:   <NA> 5.936 versicolor
# 3:   <NA> 6.588  virginica

Doing some digging current behavior was introduced by #4713

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

Successfully merging a pull request may close this issue.

4 participants