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
Milestone

Comments

@osofr
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Member

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

yihui/knitr#1457

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

Successfully merging a pull request may close this issue.

4 participants