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

optimized by group gvar() returns error: "negative length vectors are not allowed" when within-group variance is 0 #2111

Closed
osofr opened this issue Apr 12, 2017 · 3 comments · Fixed by #2480
Assignees
Labels
bug
Milestone

Comments

@osofr
Copy link

@osofr osofr commented Apr 12, 2017

Using latest development version of data.table (1.10.5):

This returns an error:

library(data.table)
testDT <- data.table(col1 = c(1,1,1, 2,2,2), col2 = c(2,2,2,1,1,1), ID = c(rep(1,3), rep(2,3)))
setkeyv(testDT, "ID")
testDT[, lapply(.SD, var), by = ID]

Error in gvar(col1) : negative length vectors are not allowed

This however works fine:

testDT[, lapply(.SD, stats::var), by = ID]
   ID col1 col2
1:  1    0    0
2:  2    0    0
@franknarf1

This comment has been minimized.

Copy link
Contributor

@franknarf1 franknarf1 commented Apr 12, 2017

Fwiw , no repro with

data.table 1.10.5 IN DEVELOPMENT built 2017-04-04 00:37:37 UTC; travis
 
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

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

loaded via a namespace (and not attached):
[1] tools_3.3.3
@osofr

This comment has been minimized.

Copy link
Author

@osofr osofr commented Apr 12, 2017

Apologies, adding session details, Mac OS X, R 3.3.1.

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(data.table)
data.table 1.10.5 IN DEVELOPMENT built 2017-04-04 00:37:37 UTC; travis
  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
> testDT <- data.table(col1 = c(1,1,1, 2,2,2), col2 = c(2,2,2,1,1,1), ID = c(rep(1,3), rep(2,3)))
> setkeyv(testDT, "ID")
> testDT[, lapply(.SD, var), by = ID]
Error in gvar(col1) : negative length vectors are not allowed
> testDT[, lapply(.SD, stats::var), by = ID]
   ID col1 col2
1:  1    0    0
2:  2    0    0
> 
@MichaelChirico

This comment has been minimized.

Copy link
Member

@MichaelChirico MichaelChirico commented Nov 13, 2017

Linking this knitr issue I created which may be related (though it seems to be a knitr issue in my case):

yihui/knitr#1457

@arunsrinivasan arunsrinivasan self-assigned this Nov 13, 2017
@arunsrinivasan arunsrinivasan added the bug label Nov 13, 2017
@arunsrinivasan arunsrinivasan added this to the v1.10.6 milestone Nov 13, 2017
arunsrinivasan added a commit that referenced this issue Nov 13, 2017
mattdowle added a commit that referenced this issue Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.