{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/1689","repository_url":"https://api.github.com/repos/hadley/dplyr","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/1689/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/1689/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/1689/events","html_url":"https://github.com/hadley/dplyr/issues/1689","id":138934318,"number":1689,"title":"length of the names vector is longer than the length of the m_odds column","user":{"login":"JanSchulz","id":890156,"avatar_url":"https://avatars.githubusercontent.com/u/890156?v=3","gravatar_id":"","url":"https://api.github.com/users/JanSchulz","html_url":"https://github.com/JanSchulz","followers_url":"https://api.github.com/users/JanSchulz/followers","following_url":"https://api.github.com/users/JanSchulz/following{/other_user}","gists_url":"https://api.github.com/users/JanSchulz/gists{/gist_id}","starred_url":"https://api.github.com/users/JanSchulz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanSchulz/subscriptions","organizations_url":"https://api.github.com/users/JanSchulz/orgs","repos_url":"https://api.github.com/users/JanSchulz/repos","events_url":"https://api.github.com/users/JanSchulz/events{/privacy}","received_events_url":"https://api.github.com/users/JanSchulz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-07T09:45:49Z","updated_at":"2016-03-09T17:37:05Z","closed_at":null,"body":"[This is a forward from https://github.com/IRkernel/repr/issues/30, where this issue is now worked around; @karldw is the one who debugged this and has a better understanding what's going on here.]\r\n\r\nQuoting @karldw from that issue:\r\n\r\n---\r\n@JanSchulz, it seems like this is a deeper problem with the `interesting` tbl_df.  For instance, I get your same error when I try `print(as.data.frame(interesting))`.  It seems that the `m_odds` column has an attribute called `names` that is longer than the number of rows.  Maybe ask the `dplyr` people?\r\n\r\nOddly, `print(data.table::as.data.table(interesting))` works fine.\r\n\r\n\r\n```R\r\n> attributes(interesting)\r\n$class\r\n[1] \"tbl_df\"     \"tbl\"        \"data.frame\"\r\n\r\n$row.names\r\n [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\r\n[26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\r\n[51] 51 52 53 54 55 56 57 58 59 60 61 62 63\r\n\r\n$names\r\n[1] \"candidate\" \"m_odds\"   \r\n\r\n> attributes(interesting$candidate)\r\nNULL\r\n> attributes(interesting$m_odds)\r\n$names\r\n  [1] \"1/2\"   \"9/4\"   \"16\"    \"28\"    \"50\"    \"50\"    \"80\"    \"125\"   \"150\"  \r\n [10] \"300\"   \"1/2\"   \"9/4\"   \"14\"    \"25\"    \"50\"    \"50\"    \"80\"    \"150\"  \r\n [19] \"300\"   \"300\"   \"300\"   \"8/15\"  \"7/4\"   \"18\"    \"28\"    \"50\"    \"50\"   \r\n [28] \"80\"    \"100\"   \"100\"   \"150\"   \"500\"   \"8/15\"  \"7/4\"   \"18\"    \"28\"   \r\n [37] \"50\"    \"50\"    \"80\"    \"100\"   \"100\"   \"150\"   \"500\"   \"8/15\"  \"19/10\"\r\n [46] \"16\"    \"25\"    \"40\"    \"80\"    \"100\"   \"200\"   \"300\"   \"1/2\"   \"2\"    \r\n [55] \"14\"    \"20\"    \"50\"    \"50\"    \"80\"    \"150\"   \"1/2\"   \"9/4\"   \"18\"   \r\n [64] \"25\"    \"22\"    \"40\"    \"80\"    \"80\"    \"200\"   \"200\"   \"325\"   \"1/2\"  \r\n [73] \"2\"     \"12\"    \"20\"    \"40\"    \"50\"    \"80\"    \"100\"   \"300\"   \"1/2\"  \r\n [82] \"2\"     \"17\"    \"22\"    \"40\"    \"50\"    \"100\"   \"750\"   \"8/15\"  \"9/4\"  \r\n [91] \"16\"    \"25\"    \"50\"    \"50\"    \"66\"    \"100\"   \"100\"   \"100\"   \"1/2\"  \r\n[100] \"2\"     \"18\"    \"25\"    \"50\"    \"16\"    \"80\"    \"100\"   \"200\"   \"8/15\" \r\n[109] \"2\"     \"14\"    \"18\"    \"50\"    \"50\"    \"80\"    \"80\"    \"400\"   \"1/2\"  \r\n[118] \"9/4\"   \"16\"    \"20\"    \"33\"    \"50\"    \"100\"   \"100\"   \"200\"   \"500\"  \r\n[127] \"500\"   \"500\"   \"500\"   \"500\"   \"500\"   \"500\"   \"500\"   \"500\"   \"999\"  \r\n[136] \"999\"   \"999\"   \"999\"   \"999\"   \"999\"   \"999\"   \"999\"   \"999\"   \"999\"  \r\n[145] \"999\"   \"999\"   \"999\"   \"999\"   \"1000\"  \"1000\"  \"9999\"  \"9999\"  \"9999\" \r\n[154] \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\" \r\n[163] \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"9999\"  \"1/2\"   \"2\"    \r\n[172] \"17\"    \"22\"    \"40\"    \"50\"    \"100\"   \"750\"   \"8/15\"  \"2\"     \"16\"   \r\n[181] \"25\"    \"40\"    \"40\"    \"80\"    \"100\"   \"300\"   \"300\"   \"1/2\"   \"2\"    \r\n[190] \"17\"    \"22\"    \"40\"    \"50\"    \"100\"   \"750\"   \"1/2\"   \"2\"     \"18\"   \r\n[199] \"25\"    \"50\"    \"50\"    \"80\"    \"150\"   \"250\"   \"750\"   \"8/15\"  \"3\"    \r\n[208] \"18\"    \"33\"    \"56\"    \"80\"    \"89\"    \"151\"   \"256\"   \"503\"   \"949\"  \r\n[217] \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"398\"   \"541\"   \"949\"   \"949\"  \r\n[226] \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"379\"   \"949\"   \"949\"   \"949\"  \r\n[235] \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"949\"   \"8/15\" \r\n[244] \"3\"     \"89/5\"  \"33\"    \"53\"    \"81\"    \"90\"    \"154\"   \"523\"   \"969\"  \r\n[253] \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"969\"  \r\n[262] \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"736\"   \"969\"   \"969\"   \"969\"  \r\n[271] \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"969\"   \"8/15\"  \"5/2\"   \"91/5\" \r\n[280] \"21\"    \"54\"    \"79\"    \"89\"    \"50\"    \"545\"   \"545\"   \"545\"   \"545\"  \r\n[289] \"545\"   \"545\"   \"545\"   \"545\"   \"297\"   \"990\"   \"545\"   \"545\"   \"545\"  \r\n[298] \"495\"   \"990\"   \"545\"   \"495\"   \"198\"   \"545\"   \"495\"   \"495\"   \"545\"\r\n\r\n> length(attributes(interesting$m_odds)$names)\r\n[1] 306\r\n\r\n```\r\n---\r\n\r\nand \r\n\r\n---\r\n@JanSchulz, I don't have a 100% clear understanding here, but it looks like dplyr is assigning names to the `m_odds` variable, and the length of the vector of `names` vector is longer than the length of the `m_odds` column.  Note that it's not a problem with the row names of the `interesting` table; instead, the `summarise` command has actually gone and assigned names in the values in the `m_odds` column.  (I've never seen that before, but I'm sure Hadley had a good reason.)  \r\n\r\nTo look at this more, I ran your code in a normal R session (avoiding Jupyter to aid debugging).  After running your notebook's cells 1 through 11, I get similar errors when I try to convert to a matrix or data.frame.\r\n\r\n```R\r\n> as.matrix(interesting)\r\nError in as.matrix.data.frame(interesting) : \r\n  'names' attribute [232] must be the same length as the vector [61]\r\n> as.data.frame(interesting)\r\nError in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  : \r\n  'names' attribute [232] must be the same length as the vector [61]\r\n```\r\n---\r\n\r\nThe code to produce `interesting` can be found in:\r\n\r\nhttp://nbviewer.jupyter.org/gist/JanSchulz/2fc1a468a65f5fd47d51 \r\nhttps://gist.github.com/JanSchulz/2fc1a468a65f5fd47d51\r\n\r\n[Note: there is an error in the notebook: the problematic cell 11 has a `%>%` too much at the end of the first line, this was introduced **after** the cell was run but before I created the gist :-/]"},"comment":{"url":"https://api.github.com/repos/hadley/dplyr/issues/comments/194416694","html_url":"https://github.com/hadley/dplyr/issues/1689#issuecomment-194416694","issue_url":"https://api.github.com/repos/hadley/dplyr/issues/1689","id":194416694,"user":{"login":"JanSchulz","id":890156,"avatar_url":"https://avatars.githubusercontent.com/u/890156?v=3","gravatar_id":"","url":"https://api.github.com/users/JanSchulz","html_url":"https://github.com/JanSchulz","followers_url":"https://api.github.com/users/JanSchulz/followers","following_url":"https://api.github.com/users/JanSchulz/following{/other_user}","gists_url":"https://api.github.com/users/JanSchulz/gists{/gist_id}","starred_url":"https://api.github.com/users/JanSchulz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanSchulz/subscriptions","organizations_url":"https://api.github.com/users/JanSchulz/orgs","repos_url":"https://api.github.com/users/JanSchulz/repos","events_url":"https://api.github.com/users/JanSchulz/events{/privacy}","received_events_url":"https://api.github.com/users/JanSchulz/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T17:37:05Z","updated_at":"2016-03-09T17:37:05Z","body":"I installed the current dplyr from github (execute the sniped in the readme) and could still reproduce this. This is the script I use:\r\n\r\n```R\r\noptions(repos = c(CRAN = \"http://cran.rstudio.com\"))\r\np <- function(...) cat(sprintf(...), \"\\n\", sep='', file=stdout())\r\nensure.package <- function(...) {\r\n  if (!suppressPackageStartupMessages({require(...)})) {\r\n    install.packages(...)\r\n    library(...)\r\n  }\r\n}\r\nensure.package(\"rvest\") \r\nensure.package(\"assertr\")\r\nensure.package(\"dplyr\") \r\nensure.package(\"tidyr\") \r\nensure.package(\"readr\")\r\nensure.package(\"lubridate\")\r\nensure.package(\"ggplot2\")\r\nrow_is <- function(row_n, value){\r\n  if (!is.numeric(row_n)) \r\n    stop(\"row_n must be numeric\")\r\n  fun <- function(a_vector){\r\n    res = rep(TRUE, length(a_vector))\r\n    if (is.na(value)){\r\n      res[row_n] <- is.na(a_vector[row_n])\r\n    } else {\r\n      res[row_n] <- a_vector[row_n] == value\r\n    }\r\n    return(res)\r\n  }\r\n  comment(fun) <- \"assertr/vectorized\"    \r\n  return(fun)\r\n}\r\nrow_is_not <- function(row_n, value){\r\n  if (!is.numeric(row_n)) \r\n    stop(\"row_n must be numeric\")\r\n  fun <- function(a_vector){\r\n    res = rep(TRUE, length(a_vector))\r\n    if (is.na(value)){\r\n      res[row_n] <- !is.na(a_vector[row_n])\r\n    } else {\r\n      res[row_n] <- a_vector[row_n] != value\r\n    }\r\n    return(res)\r\n  }\r\n  comment(fun) <- \"assertr/vectorized\"    \r\n  return(fun)\r\n}\r\nmath_eval <- function(exp){\r\n  eval(parse(text=exp))\r\n}\r\n\r\nprocess_data_table <- . %>% html_node(css=\".eventTable\") %>% \r\n  html_table() %>% \r\n  slice(5:n()) %>% \r\n  assert(row_is(1, \"\"), X1) %>% \r\n  assert(row_is_not(2, \"\"), X1) %>%\r\n  slice(2:n()) %>%\r\n  gather(\"bookie\", \"odds\", -X1) %>%\r\n  rename(candidate=X1) %>%\r\n  filter(odds!=\"\") %>%\r\n  mutate(odds=sapply(odds, math_eval))\r\n\r\nhtml_president <- read_html(\"http://www.oddschecker.com/politics/us-politics/us-presidential-election-2016/winner\")\r\ndf_president <- html_president %>% process_data_table\r\ndf_president %>% head(2)\r\n\r\ninteresting <- df_president %>% group_by(candidate) %>% summarise(m_odds=mean(odds)) \r\nas.matrix(interesting)\r\n```\r\n\r\n```R\r\n> as.matrix(interesting)\r\nError in as.matrix.data.frame(interesting) : \r\n  'names' attribute [188] must be the same length as the vector [11]\r\n```\r\n\r\n[R3.2, win7 64bit]"}}