-
Notifications
You must be signed in to change notification settings - Fork 33
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
Issue with aggregate command (from stats) in notebooks only #116
Comments
That’s a super weird structure. > str(aggregate(. ~ Species, iris, range))
'data.frame': 3 obs. of 5 variables:
$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 2 3
$ Sepal.Length: num [1:3, 1:2] 4.3 4.9 4.9 5.8 7 7.9
$ Sepal.Width : num [1:3, 1:2] 2.3 2 2.2 4.4 3.4 3.8
$ Petal.Length: num [1:3, 1:2] 1 3 4.5 1.9 5.1 6.9
$ Petal.Width : num [1:3, 1:2] 0.1 1 1.4 0.6 1.8 2.5 A data frame with matrices as columns? Hmm, no idea how to do that best. |
Thanks a lot for taking a look (and for moving it in the proper component repo)! Base R coerces the matrix columns to separate data.frame columns, appending a column-in-matrix index to the column main name (i.e. you get Sepal.Length.1 & Sepal.Length.2 and so on)... This happens with any kind of multivalued function passed through aggregate, for what is worth: |
Yes, for printing. Doesn’t seem like a good idea: People will think I’m thinking that we could handle it by collapsing the rows of the nested matrices with commas:
|
That would be like forcing |
Thanks a lot! |
Jupyter notebooks with R kernel seem to have issues in some cases when aggregate (from stats package in base R) returns multiple values (e.g. a vector).
This can be reproduced by running the following command
aggregate(. ~ Species, iris, range)
which results in an error:
ERROR while rich displaying an object: Error in vapply(part, format, character(nrow(part))): values must be length 3, but FUN(X[[2]]) result is length 6
The issue is mitigated by the fact that if I run
aggregate(. ~ Species, iris, range, simplify=F)
the code works, but this way I get a data.frame with list columns and not the same object that I can obtain from R console with
simplify=T
(default value).The issue seems strictly related either to the way IRkernel tries to display the data.frame, since the command
print(aggregate(. ~ Species, iris, range))
produce the correct output. But it surprised me that the code works flawlessly in R and Rmarkdown and it fails on IRkernel notebooks
I was unable to find a similar issue on the github tracker (searching for
vapply
andaggregate
orprint
), so I hope this is not a duplicated report.My system has:
but the issue is reproducible also on my colleague laptop.
The text was updated successfully, but these errors were encountered: