Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
as_tibble(matrix w/ attributes) copies too many attributes from matrix to its columns #184
The as_tibble method for matrices copies all the attributes of the input matrix to
With TIBCO's TERR there are further problems with the same code because its SET_ATTRIB checks that the dim attribute is compatible with the object's length and R's SET_ATTRIB does not.
Calling out to the R-level "[" to extract the columns would solve the problem.
Note that I am not trying insert a matrix column into a tibble,
I would expect each column to be a time-series vector or perhaps
On Thu, Nov 17, 2016 at 7:07 AM, Kirill Müller email@example.com
added a commit
Jan 9, 2017
One might be able to fix it by doing the subscripting in C++ if the object has dims but no class (or exactly the class "matrix") and calling out to the interpreter to evaluate 'mat[,column]' or 'mat[,column,drop=TRUE]' for those objects with dims but unrecognized class. We can expect that their [ methods should return a column with appropriate attributes.…
On Tue, Jan 10, 2017 at 11:55 AM, Chris Hammill ***@***.***> wrote: @krlmlr <https://github.com/krlmlr> This problem is more general, any time a matrix is given an extra class it breaks matrixToDataFrame. e.g. mat <- matrix(1:100, nrow = 10) attr(mat, "special") <- "a little extra" class(mat) <- c("special_matrix", "matrix") as_tibble(mat) %>% mutate(colnum = 1:10) ## error — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#184 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALHWBQTHdBTOmwuWTOwkfWuXKpoMnYR1ks5rQ-JDgaJpZM4KdlI8> .
I find it surprising that you want your function to act differently than '[' when splitting a matrix into its columns.…
On Tue, Jan 10, 2017 at 12:21 PM, Kirill Müller ***@***.***> wrote: @BillDunlap <https://github.com/BillDunlap>: Your strategy fails for an existing test <https://github.com/tidyverse/tibble/blob/3d6f8b417f5ed994c59b60528075a6825013c5da/tests/testthat/test-matrix.R#L25-L35> for a matrix-like object of class Date, this is supposed to be converted to a tibble with date columns. @hadley <https://github.com/hadley>: Do you remember the rationale behind this behavior? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#184 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALHWBRiYG0JccL0piCPSvK0q94wHX5uOks5rQ-hTgaJpZM4KdlI8> .
I think that all of the as.data.frame methods should worry about their argument being a matrix, since dates, factors, etc. can have a dims attribute. But, if some class's [ method chooses to drop or change attributes when extracting a column, the matrix->list-of-columns code should respect that choice.…
On Tue, Jan 10, 2017 at 12:35 PM, Hadley Wickham ***@***.***> wrote: The original motivation is probably that as.data.frame(date) doesn't do the right thing. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#184 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALHWBTt5IwfklGn6IUeqR00La4hKaipgks5rQ-uegaJpZM4KdlI8> .