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

Group_rows not working properly for longer latex table #9

Closed
Jaeoc opened this issue Jun 6, 2017 · 5 comments
Closed

Group_rows not working properly for longer latex table #9

Jaeoc opened this issue Jun 6, 2017 · 5 comments

Comments

@Jaeoc
Copy link

Jaeoc commented Jun 6, 2017

Hello!

I'm really liking your package, but have run into an issue when trying to group by rows in a slightly longer latex table. When using the group_rows on a row starting on row 17 or beyond, this has no effect on the table when knitting to pdf, i.e. the table is produced as if that line of code didn't exist. It works perfectly fine when knitting to HTML.

The code I'm using looks like this, and I've tried both the CRAN-version and the github version of the kableExtra package.

library(knitr)
library(kableExtra)

kable(marginal$table, caption = "Table 1", booktabs = T, align = "c") %>%
  kable_styling() %>%
  group_rows("Other data", 11, 16) %>%
  group_rows("Our data", 17, 22)
@haozhu233
Copy link
Owner

Hi, @Jaeoc, thanks for reporting this bug. In fact, I just fixed a very similar bug last night which causes similar behavior when you have symbols like % present. Can you try to re-install from github and let me know if this bug has gone away?

@Jaeoc
Copy link
Author

Jaeoc commented Jun 6, 2017

Hi,

it seems like I was mistaken with what the cause of the problem was. I fiddled around with the mtcars dataset to try to reproduce the issue, and it seems to have to do with the structure of the dataframe used for the table. In my original table I had some variables where I'd used paste0 to create columns with two values, one being in parentheses, like so: "3452 (3.2)". It appears that for those rows where this is the case, the group_rows function does not work. The code below reproduces this for the mtcars dataset. Not sure what the problem is exactly though, since there is no problem if I just force a column to be a factor or character value...

library(knitr)
library(kableExtra)
for (i in 1:nrow(mtcars)) {
  mtcars$hp[i] <- paste0(mtcars$hp[i], " (", 1, ")")
}
kable(head(mtcars, n = 20), caption = "test", booktabs = T) %>%
  kable_styling() %>%
  group_rows("these rows", 4, 16) %>%
  group_rows("Those rows", 17,20)

@haozhu233
Copy link
Owner

I see. I just reproduced the error. I know where the problem is but the fix is a little tricky. I'll see what I can do.

@haozhu233
Copy link
Owner

Hi, @Jaeoc, I just fixed the bug. Do you want to try out the latest github version and let me know the results?

@haozhu233 haozhu233 reopened this Jun 7, 2017
@Jaeoc
Copy link
Author

Jaeoc commented Jun 8, 2017

Hi, just tried it out, and now it works nicely. Appreciate the quick fix :)

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