pander icon indicating copy to clipboard operation
pander copied to clipboard

Seemingly a bug in justify= and rownames=1:nrow()

Open cpsyctc2 opened this issue 6 years ago • 2 comments

I use pander a lot for tables in Rmarkdown generated from Rstudio so many thanks for the package.

Here's a reproducible example I think. It may be a bit of an edge case as I do want row names when they are 1:nrow(tmpDF)

dput(tmpDF)
structure(list(companyid = c("5be03792e60b662819bb2068", "5be071e44f07bccdf1601d0e", 
"5be069ddc5ad8b5d83c1a453", "5c5d5d3f65c8f7daf974b770", "5c7e670b08263a276d43198d", 
"5c8f873bb34f572ae12bd0b3", "5c8fccf2bf6843025d207058", "5ca1b137e4e8ee864f9c8152", 
"5ca1fd523115bd8cf834fe7d", "5cab31b0bacb74464a4cba4e"), nRowsDat = c(7429L, 
7742L, 2829L, 448L, 302L, 1994L, 827L, 1634L, 441L, 18L), nUsers = c(57L, 
70L, 15L, 4L, 2L, 23L, 12L, 14L, 4L, 1L), firstDate = structure(c(17780, 
17780, 17843, 17952, 17960, 17973, 17981, 17987, 17987, 17994
), class = "Date"), lastDate = structure(c(18000, 17994, 17933, 
17961, 17988, 18000, 17999, 18000, 17999, 17994), class = "Date"), 
    daysInData = c(220, 214, 90, 9, 28, 27, 18, 13, 12, 0)), row.names = c(NA, 
-10L), class = "data.frame")
> tmpDF
                  companyid nRowsDat nUsers  firstDate   lastDate daysInData
1  5be03792e60b662819bb2068     7429     57 2018-09-06 2019-04-14        220
2  5be071e44f07bccdf1601d0e     7742     70 2018-09-06 2019-04-08        214
3  5be069ddc5ad8b5d83c1a453     2829     15 2018-11-08 2019-02-06         90
4  5c5d5d3f65c8f7daf974b770      448      4 2019-02-25 2019-03-06          9
5  5c7e670b08263a276d43198d      302      2 2019-03-05 2019-04-02         28
6  5c8f873bb34f572ae12bd0b3     1994     23 2019-03-18 2019-04-14         27
7  5c8fccf2bf6843025d207058      827     12 2019-03-26 2019-04-13         18
8  5ca1b137e4e8ee864f9c8152     1634     14 2019-04-01 2019-04-14         13
9  5ca1fd523115bd8cf834fe7d      441      4 2019-04-01 2019-04-13         12
10 5cab31b0bacb74464a4cba4e       18      1 2019-04-08 2019-04-08          0

> dim(tmpDF)
[1] 10  6

but

> pander(tmpDF, justify = "rlrrllr",row.names = 1:nrow(tmpDF)) # left over from bug reporting
Error in pandoc.table.return(res[[1]], caption = caption, digits = digits,  : 
  Wrong number of parameters (5 instead of *4*) passed: justify

> pander(tmpDF, justify = "rlrrllr")
Error in pandoc.table.return(...) : 
  Wrong number of parameters (7 instead of *6*) passed: justify

Which is correct, as it is that pander(tmpDF, justify = "lrrllr") works correctly.

I hope I'm not missing something. TIA, Chris

cpsyctc2 avatar Apr 15 '19 18:04 cpsyctc2

Thanks for the report -- this seems to be more of an issue with splitting tables, as the below works:

> pander(tmpDF[, 1:3], justify = rep('right', 4), row.names = 1:nrow(tmpDF)) 

-------------------------------------------------------
                     companyid   nRowsDat   nUsers
-------- -------------------------- ---------- --------
   **1**   5be03792e60b662819bb2068       7429       57

   **2**   5be071e44f07bccdf1601d0e       7742       70

   **3**   5be069ddc5ad8b5d83c1a453       2829       15

   **4**   5c5d5d3f65c8f7daf974b770        448        4

   **5**   5c7e670b08263a276d43198d        302        2

   **6**   5c8f873bb34f572ae12bd0b3       1994       23

   **7**   5c8fccf2bf6843025d207058        827       12

   **8**   5ca1b137e4e8ee864f9c8152       1634       14

   **9**   5ca1fd523115bd8cf834fe7d        441        4

  **10**   5cab31b0bacb74464a4cba4e         18        1
-------------------------------------------------------

> pander(tmpDF, justify = 'rrrrrrr', row.names = 1:nrow(tmpDF), split.table = Inf) 

----------------------------------------------------------------------------------------------
                     companyid   nRowsDat   nUsers    firstDate     lastDate   daysInData
-------- -------------------------- ---------- -------- ------------ ------------ ------------
   **1**   5be03792e60b662819bb2068       7429       57   2018-09-06   2019-04-14          220

   **2**   5be071e44f07bccdf1601d0e       7742       70   2018-09-06   2019-04-08          214

   **3**   5be069ddc5ad8b5d83c1a453       2829       15   2018-11-08   2019-02-06           90

   **4**   5c5d5d3f65c8f7daf974b770        448        4   2019-02-25   2019-03-06            9

   **5**   5c7e670b08263a276d43198d        302        2   2019-03-05   2019-04-02           28

   **6**   5c8f873bb34f572ae12bd0b3       1994       23   2019-03-18   2019-04-14           27

   **7**   5c8fccf2bf6843025d207058        827       12   2019-03-26   2019-04-13           18

   **8**   5ca1b137e4e8ee864f9c8152       1634       14   2019-04-01   2019-04-14           13

   **9**   5ca1fd523115bd8cf834fe7d        441        4   2019-04-01   2019-04-13           12

  **10**   5cab31b0bacb74464a4cba4e         18        1   2019-04-08   2019-04-08            0
----------------------------------------------------------------------------------------------

Will look into this more later.

daroczig avatar Apr 15 '19 22:04 daroczig

Interesting, I hadn't tried that on this table nor noticed it with others and I use split.tables = Inf quite a bit but I guess I rarely find myself imposing the 1:nrow() row names.

Really appreciate you looking into it Gergely. I of course bodged things by cbinding in a column for the 1:nrow() labels on the left.

I'd definitely lobby for my feature request of the "row.names = TRUE" option too but that's in my other submission!

Many thanks again,

Chris

From: "Gergely Daróczi" [email protected] To: "Rapporter/pander" [email protected] Cc: "cpsyctc2" [email protected], "Author" [email protected] Sent: Tuesday, 16 April, 2019 00:14:38 Subject: Re: [Rapporter/pander] Seemingly a bug in justify= and rownames=1:nrow() (#339)

Thanks for the report -- this seems to be more of an issue with splitting tables, as the below works:

pander( tmpDF [, 1 : 3 ], justify = rep( ' right ' , 4 ), row.names = 1 : nrow( tmpDF )) ------------------------------------------------------- & nbsp ; companyid nRowsDat nUsers -------- -------------------------- ---------- -------- ** 1 ** 5be03792e60b662819bb2068 7429 57 ** 2 ** 5be071e44f07bccdf1601d0e 7742 70 ** 3 ** 5be069ddc5ad8b5d83c1a453 2829 15 ** 4 ** 5c5d5d3f65c8f7daf974b770 448 4 ** 5 ** 5c7e670b08263a276d43198d 302 2 ** 6 ** 5c8f873bb34f572ae12bd0b3 1994 23 ** 7 ** 5c8fccf2bf6843025d207058 827 12 ** 8 ** 5ca1b137e4e8ee864f9c8152 1634 14 ** 9 ** 5ca1fd523115bd8cf834fe7d 441 4 ** 10 ** 5cab31b0bacb74464a4cba4e 18 1 ------------------------------------------------------- > pander( tmpDF , justify = ' rrrrrrr ' , row.names = 1 : nrow( tmpDF ), split.table = Inf )

& nbsp ; companyid nRowsDat nUsers firstDate lastDate daysInData --------


------------ ** 1 ** 5be03792e60b662819bb2068 7429 57 2018 - 09 - 06 2019 - 04

  • 14 220 ** 2 ** 5be071e44f07bccdf1601d0e 7742 70 2018 - 09 - 06 2019 - 04 - 08 214 ** 3 ** 5be069ddc5ad8b5d83c1a453 2829 15 2018 - 11 - 08 2019 - 02 - 06 90 ** 4 ** 5c5d5d3f65c8f7daf974b770 448 4 2019 - 02 - 25 2019 - 03 - 06 9 ** 5 ** 5c7e670b08263a276d43198d 302 2 2019 - 03 - 05 2019 - 04 - 02 28 ** 6 ** 5c8f873bb34f572ae12bd0b3 1994 23 2019 - 03 - 18 2019 - 04 - 14 27 ** 7 ** 5c8fccf2bf6843025d207058 827 12 2019 - 03 - 26 2019 - 04 - 13 18 ** 8 ** 5ca1b137e4e8ee864f9c8152 1634 14 2019 - 04 - 01 2019 - 04 - 14 13 ** 9 ** 5ca1fd523115bd8cf834fe7d 441 4 2019 - 04 - 01 2019 - 04 - 13 12 ** 10 ** 5cab31b0bacb74464a4cba4e 18 1 2019 - 04 - 08 2019 - 04 - 08 0

Will look into this more later.

— You are receiving this because you authored the thread. Reply to this email directly, [ https://github.com/Rapporter/pander/issues/339#issuecomment-483438369 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/AukAkkqpsenDcBZGLFXQxn_fwyadr9Ovks5vhPnOgaJpZM4cwkxF | mute the thread ] .

-- Chris Evans [email protected] Skype: chris-psyctc Visiting Professor, University of Sheffield [email protected] I do some consultation work for the University of Roehampton [email protected] and other places but this [email protected] remains my main Email address. I have "semigrated" to France, see: https://www.psyctc.org/pelerinage2016/semigrating-to-france/ if you want to book to talk, I am trying to keep that to Thursdays and my diary is now available at: https://www.psyctc.org/pelerinage2016/ecwd_calendar/calendar/ Beware: French time, generally an hour ahead of UK. That page will also take you to my blog which started with earlier joys in France and Spain!

cpsyctc2 avatar Apr 16 '19 05:04 cpsyctc2