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

Duplicated rows cause unexpected output with group_rows #161

Closed
steveputman opened this issue Apr 5, 2018 · 3 comments
Closed

Duplicated rows cause unexpected output with group_rows #161

steveputman opened this issue Apr 5, 2018 · 3 comments

Comments

@steveputman
Copy link

Hi, I was testing your earlier commit to see if it fixed my old problem referenced in #145 . Something strange is happening.

library(tidyverse)
#> ── Attaching packages ───────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1.9000     ✔ purrr   0.2.4     
#> ✔ tibble  1.4.2          ✔ dplyr   0.7.4     
#> ✔ tidyr   0.7.2          ✔ stringr 1.3.0     
#> ✔ readr   1.1.1          ✔ forcats 0.2.0
#> ── Conflicts ──────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
#> ✖ dplyr::vars()   masks ggplot2::vars()
library(knitr)
library(kableExtra)

testframe <- tibble(cola = sample(LETTERS, 3), colb = rnorm(3), colc = rnorm(3))
duprow <- testframe[1,]
testframe <- testframe %>% bind_rows(duprow, duprow)

outputtable <- kable(testframe, format = "latex", longtable = T, booktabs = T, linesep = '') %>%
  kable_styling(full_width = F, latex_options = c("repeat_header")) %>%
  group_rows("Label 1", start_row = 1, end_row = 2) %>%
  group_rows("Label 2", start_row = 3, end_row = 3) %>%
  group_rows("Label 3", start_row = 4, end_row = 5)

Knitting outputtable gets you this:
screen shot 2018-04-05 at 1 10 31 am

(In my actual case, I get these behaviors--dropped/out-of-order labels and improperly indented first columns--as well as "narrowed" \toprule, \midrule, and \bottumrule that do not extend to the width of the table data.) I am not a tex debugger unfortunately, but I did notice that the added vphantom are being aggregated at the end of one line rather than spread across the duplicated rows. Also some strange behavior that may tie in to repeat_headers? You get the "continued" tex even when you haven't broken across a page, though it doesn't seem to show up in the caption?

\begin{longtable}{lrr}
\toprule
cola & colb & colc\\
\midrule
\endfirsthead
\multicolumn{3}{@{}l}{\textit{(continued)}}\\
\toprule
cola & colb & colc\\
\midrule
\endhead
\
\endfoot
\bottomrule
\endlastfoot
\addlinespace[0.3em]
\multicolumn{3}{l}{\textbf{Label 3}}\\
\hspace{1em}\hspace{1em}P & -0.1772646 & -0.0321724\vphantom{1}\vphantom{2}\\
\hspace{1em}F & -1.5141957 & -1.3348491\\
\addlinespace[0.3em]
\multicolumn{3}{l}{\textbf{Label 2}}\\
\hspace{1em}T & -0.9069380 & -0.8250501\\
P & -0.1772646 & -0.0321724\\
P & -0.1772646 & -0.0321724\\*

Thanks again for your help and sorry to pester you on this, but kableExtra has become indispensable ever since I discovered it!

Steve

@haozhu233
Copy link
Owner

haozhu233 commented Apr 5, 2018

Hi, @steveputman thanks for raising this before I release this version to CRAN. I look into the problem and found that I can't put vphantom at the end of the line as it will take away the ability to identify duplicated rows. I will change it back to putting it after the first &. Never mind, let me think it through

@steveputman
Copy link
Author

steveputman commented Apr 5, 2018 via email

haozhu233 added a commit that referenced this issue Apr 5, 2018
@haozhu233
Copy link
Owner

Hmm, so in the end I changed it back to the location after first &. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants