kableExtra collapse_rows not working - reason unknown


I am discovering cool kableExtra features for tables, yet cannot get collapse_rows to work. Can you spot what is wrong with the code?


mtcars <- arrange(mtcars, cyl)
kbl(mtcars) |> kable_classic(full_width=F) |> collapse_rows(columns = 2, valign = "top")
1 Like

Hope this is of some use to you
function to collapse_row

#' Collapse the values within a grouped dataframe
collapse_rows_df <- function(df, variable){
  group_var <- enquo(variable)
  df %>%
    group_by(!! group_var) %>%
    mutate(groupRow = 1:n()) %>%
    ungroup() %>%
    mutate(!!quo_name(group_var) := ifelse(groupRow == 1, as.character(!! group_var), "")) %>%

To execute:

Credit goes to

1 Like

Thanks - this is some workaround indeed.
While the original collapse_rows has nice additional settings, the core task is solved by this function, I will keep it in case nobody has a clue what's wrong with the original, thanks :smiley:

1 Like

Ok, I understand. in connection with kableExtra table, you may please review my video on my channel "Happy Learning-GP". here is the link: Making Awesome HTML Table with kableExtra package in R - YouTube

1 Like

Great, thanks for the link ;D

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Well, sure, but the question has not been answered yet.
@ganapap1 presented a valuable workaround - but the question how to use collapse_rows so it works has not been answered.
Do you think waiting for a solution is futile?

Oh sorry I thought it was :sweat_smile: my bad.

You could also open a Feature request or an issue with kableExtra repo is something is off.

Ok, thanks. To be honest I do not know how to open an issue with kableExtra repo.

And to do that I guess I should be quite sure that it is not my coding mistake, which I am not. :wink:

The repo of the package is here: GitHub - haozhu233/kableExtra: Construct Complex Table with knitr::kable() + pipe.

Ok, thanks, the issue is opened :wink:

1 Like

Sharing link here for reference :

Thanks. This really helped me out!

1 Like