{"action":"opened","issue":{"url":"https://api.github.com/repos/Rapporter/pander/issues/205","labels_url":"https://api.github.com/repos/Rapporter/pander/issues/205/labels{/name}","comments_url":"https://api.github.com/repos/Rapporter/pander/issues/205/comments","events_url":"https://api.github.com/repos/Rapporter/pander/issues/205/events","html_url":"https://github.com/Rapporter/pander/issues/205","id":96098432,"number":205,"title":"0 row data.frame/matrix displayed as if they had a single NA row","user":{"login":"BrianDiggs","id":463252,"avatar_url":"https://avatars.githubusercontent.com/u/463252?v=3","gravatar_id":"","url":"https://api.github.com/users/BrianDiggs","html_url":"https://github.com/BrianDiggs","followers_url":"https://api.github.com/users/BrianDiggs/followers","following_url":"https://api.github.com/users/BrianDiggs/following{/other_user}","gists_url":"https://api.github.com/users/BrianDiggs/gists{/gist_id}","starred_url":"https://api.github.com/users/BrianDiggs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrianDiggs/subscriptions","organizations_url":"https://api.github.com/users/BrianDiggs/orgs","repos_url":"https://api.github.com/users/BrianDiggs/repos","events_url":"https://api.github.com/users/BrianDiggs/events{/privacy}","received_events_url":"https://api.github.com/users/BrianDiggs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-20T16:11:00Z","updated_at":"2015-07-20T16:11:00Z","closed_at":null,"body":"# Summary\r\n\r\nA `data.frame` or `matrix` with no rows is displayed the same way as one with a single row filled with `NA`s. As theses are different things, they should be displayed differently.\r\n\r\n# Discussion\r\n\r\nIn R, a zero row `data.frame` and `matrix` are well defined, and sometimes useful, constructs. Separately, a row in a `data.frame` or `matrix` can contain all `NA`s. This happens most frequently when selecting rows with a logical vector and on element is `NA`. Pander, however, displays these the same way. I believe pander's display is correct for a single `NA` row, but not correct for a zero-row version.\r\n\r\nThis came up in the discussion of #204.\r\n\r\n# Example code\r\n```r\r\nlibrary(\"pander\")\r\n\r\nexplore <- function(x) {\r\n  cat(\"print:\\n\")\r\n  print(x)\r\n  cat(\"\\ndim:\\n\")\r\n  print(dim(x))\r\n  cat(\"\\nstr:\\n\")\r\n  str(x)\r\n  cat(\"\\npander:\\n\")\r\n  pander(x)\r\n  invisible(x)\r\n}\r\n\r\nexplore(mtcars[1,][NA,])\r\nexplore(mtcars[FALSE,])\r\nmtcars.mx <- as.matrix(mtcars)\r\nexplore(mtcars.mx[1,,drop=FALSE][NA,])\r\nexplore(mtcars.mx[FALSE,])\r\n```\r\n\r\n# Output\r\n```r\r\n> explore <- function(x) {\r\n+   cat(\"print:\\n\")\r\n+   print(x)\r\n+   cat(\"\\ndim:\\n\")\r\n+   print(dim(x))\r\n+   cat(\"\\nstr:\\n\")\r\n+   str(x)\r\n+   cat(\"\\npander:\\n\")\r\n+   pander(x)\r\n+   invisible(x)\r\n+ }\r\n> \r\n> explore(mtcars[1,][NA,])\r\nprint:\r\n   mpg cyl disp hp drat wt qsec vs am gear carb\r\nNA  NA  NA   NA NA   NA NA   NA NA NA   NA   NA\r\n\r\ndim:\r\n[1]  1 11\r\n\r\nstr:\r\n'data.frame':   1 obs. of  11 variables:\r\n $ mpg : num NA\r\n $ cyl : num NA\r\n $ disp: num NA\r\n $ hp  : num NA\r\n $ drat: num NA\r\n $ wt  : num NA\r\n $ qsec: num NA\r\n $ vs  : num NA\r\n $ am  : num NA\r\n $ gear: num NA\r\n $ carb: num NA\r\n\r\npander:\r\n\r\n---------------------------------------------------\r\n &nbsp;   mpg   cyl   disp   hp   drat   wt   qsec \r\n-------- ----- ----- ------ ---- ------ ---- ------\r\n **NA**   NA    NA     NA    NA    NA    NA    NA  \r\n---------------------------------------------------\r\n\r\nTable: Table continues below\r\n\r\n \r\n--------------------------------\r\n &nbsp;   vs   am   gear   carb \r\n-------- ---- ---- ------ ------\r\n **NA**   NA   NA    NA     NA  \r\n--------------------------------\r\n\r\n> explore(mtcars[FALSE,])\r\nprint:\r\n [1] mpg  cyl  disp hp   drat wt   qsec vs   am   gear carb\r\n<0 rows> (or 0-length row.names)\r\n\r\ndim:\r\n[1]  0 11\r\n\r\nstr:\r\n'data.frame':   0 obs. of  11 variables:\r\n $ mpg : num \r\n $ cyl : num \r\n $ disp: num \r\n $ hp  : num \r\n $ drat: num \r\n $ wt  : num \r\n $ qsec: num \r\n $ vs  : num \r\n $ am  : num \r\n $ gear: num \r\n $ carb: num \r\n\r\npander:\r\n------------------------------------------------------------------\r\n mpg   cyl   disp   hp   drat   wt   qsec   vs   am   gear   carb \r\n----- ----- ------ ---- ------ ---- ------ ---- ---- ------ ------\r\n NA    NA     NA    NA    NA    NA    NA    NA   NA    NA     NA  \r\n------------------------------------------------------------------\r\n\r\n> mtcars.mx <- as.matrix(mtcars)\r\n> explore(mtcars.mx[1,,drop=FALSE][NA,])\r\nprint:\r\n mpg  cyl disp   hp drat   wt qsec   vs   am gear carb \r\n  NA   NA   NA   NA   NA   NA   NA   NA   NA   NA   NA \r\n\r\ndim:\r\nNULL\r\n\r\nstr:\r\n Named num [1:11] NA NA NA NA NA NA NA NA NA NA ...\r\n - attr(*, \"names\")= chr [1:11] \"mpg\" \"cyl\" \"disp\" \"hp\" ...\r\n\r\npander:\r\n\r\n----------------------------------------------------\r\n mpg   cyl   disp   hp   drat   wt   qsec   vs   am \r\n----- ----- ------ ---- ------ ---- ------ ---- ----\r\n NA    NA     NA    NA    NA    NA    NA    NA   NA \r\n----------------------------------------------------\r\n\r\nTable: Table continues below\r\n\r\n \r\n-------------\r\n gear   carb \r\n------ ------\r\n  NA     NA  \r\n-------------\r\n\r\n> explore(mtcars.mx[FALSE,])\r\nprint:\r\n     mpg cyl disp hp drat wt qsec vs am gear carb\r\n\r\ndim:\r\n[1]  0 11\r\n\r\nstr:\r\n num[0 , 1:11] \r\n - attr(*, \"dimnames\")=List of 2\r\n  ..$ : NULL\r\n  ..$ : chr [1:11] \"mpg\" \"cyl\" \"disp\" \"hp\" ...\r\n\r\npander:\r\n------------------------------------------------------------------\r\n mpg   cyl   disp   hp   drat   wt   qsec   vs   am   gear   carb \r\n----- ----- ------ ---- ------ ---- ------ ---- ---- ------ ------\r\n NA    NA     NA    NA    NA    NA    NA    NA   NA    NA     NA  \r\n------------------------------------------------------------------\r\n``` \r\nResults generated by pander 0.5.2 except for the results of the pander call for zero row `data.frame` and `matrix` which are extrapolated from the stated behavior in #204. \r\n\r\nThe expected result for a zero row `data.frame` or `matrix` might be\r\n\r\n```r\r\n------------------------------------------------------------------\r\n mpg   cyl   disp   hp   drat   wt   qsec   vs   am   gear   carb \r\n----- ----- ------ ---- ------ ---- ------ ---- ---- ------ ------\r\n------------------------------------------------------------------\r\n```\r\nmaybe with a notation that it is zero row, much like `print` gives (\"`<0 rows> (or 0-length row.names)`\"). I am not sure the exact format that it should have, but I do not think it should be indistinguishable from a single `NA` row version.\r\n"}}