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

print and glimpse don't work on a tbl_df that contains data.frame column #775

Closed
jennybc opened this issue Nov 14, 2014 · 2 comments
Closed

print and glimpse don't work on a tbl_df that contains data.frame column #775

jennybc opened this issue Nov 14, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@jennybc
Copy link
Member

@jennybc jennybc commented Nov 14, 2014

Since the new data_frame() performs no coercion of its arguments, there will likely be more data.frames (and tbl_dfs) running around with data.frame columns.

Here's a simple one and I've noticed that simple printing and glimpse()ing don't work.

suppressPackageStartupMessages(library(dplyr))

my_vec <- LETTERS[1:3]
my_df <- data.frame(month = month.abb[1:3],
                                        month_name = month.name[1:3])

dplyr_result <- data_frame(my_vec, my_df)
dplyr_result %>% str
dplyr_result
dplyr_result %>% print
dplyr_result %>% glimpse

devtools::session_info() %>%
    capture.output %>%
    grep("dplyr", ., value = TRUE)

And here's what it looks like in my Console:

> suppressPackageStartupMessages(library(dplyr))
> my_vec <- LETTERS[1:3]
> my_df <- data.frame(month = month.abb[1:3],
+ month_name = month.name[1:3])
> dplyr_result <- data_frame(my_vec, my_df)
> dplyr_result %>% str
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   3 obs. of  2 variables:
 $ my_vec: chr  "A" "B" "C"
 $ my_df :'data.frame': 3 obs. of  2 variables:
  ..$ month     : Factor w/ 3 levels "Feb","Jan","Mar": 2 1 3
  ..$ month_name: Factor w/ 3 levels "February","January",..: 2 1 3
> dplyr_result
Source: local data frame [3 x 2]

Error in `[.data.frame`(X[[2L]], ...) : undefined columns selected
> dplyr_result %>% print
Source: local data frame [3 x 2]

Error in `[.data.frame`(X[[2L]], ...) : undefined columns selected
> dplyr_result %>% glimpse
Variables:
Error in `[.data.frame`(X[[2L]], ...) : undefined columns selected
> devtools::session_info() %>%
+ capture.output %>%
+ grep("dplyr", ., value = TRUE)
Session info---------------------------------------------------------------------------
Packages-------------------------------------------------------------------------------
[1] " dplyr      * 0.3.0.9000 2014-11-06 Github (hadley/dplyr@8b0191a)   "
@hadley hadley added the bug label Nov 20, 2014
@hadley hadley added this to the 0.3.1 milestone Nov 20, 2014
@hadley hadley self-assigned this Nov 20, 2014
@hadley
Copy link
Member

@hadley hadley commented Nov 20, 2014

Here's an example of all the complex col types we need to support:

cdf <- data_frame(
  a = 1:3, 
  b = list(1, 3, 4), 
  c = data_frame(x = 1:3, y = 1:3), 
  d = matrix(1:6, ncol = 2)
)

Loading

@hadley
Copy link
Member

@hadley hadley commented Nov 21, 2014

Hmmmm, I'm now having second thoughts about supporting matrix and data frame columns, because it's not clear when they will be useful. I think I was getting confused with lists of data frames, which I can clearly see being used an as interim hierarchical form between normalised and unnormalised data. But data frame and matrix columns, just extend the columns in weird ways, and need a lot of special handling.

Data frames in particularly are problematic because the length of a data frame is the number of columns, where the length of a list-column is the number of rows.

cc @romainfrancois - I think this means we don't need special handling, and can happily throw an error if we see a data frame or matrix column. data_frame() will need a minor adjustment to use length() instead of NROW(). I'm not sure if we single them out for special handling errors as well.

Loading

@hadley hadley closed this in c07f1b6 Nov 24, 2014
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants