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

collapse_rows not working as expected? #595

Closed
SPFL-Analysis opened this issue Mar 11, 2021 · 14 comments
Closed

collapse_rows not working as expected? #595

SPFL-Analysis opened this issue Mar 11, 2021 · 14 comments

Comments

@SPFL-Analysis
Copy link

Hello, I've been using this package for a while and all was great but today I updated to rvest v1.0.0 and it seems to have stopped the collapse_rows() function working as it did, please see example below.

df <- data.frame("col1" = c("a", "a", "b"), "col2" = 1:3)
kableExtra::collapse_rows(knitr::kable(df), columns = 1)

For me this no longer collapses the first 2 rows of col1 with the "a" values.
Any help would be much appreciated.
Thanks.

@unDocUMeantIt
Copy link

same here. i suspect this is due to rvest:::html_table() having changed its output format. a quickfix to get the expected data frame back could be wrapping it in as.data.frame(html_table()).

@haozhu233
Copy link
Owner

@SPFL-Analysis @unDocUMeantIt Fixed now. Thank you for reporting and making that suggestion!

@motocci
Copy link

motocci commented Mar 27, 2021

Same above. (v. 1.3.4)
I'm looking forward to the features coming to work.

@unDocUMeantIt
Copy link

i'm happy to confirm that the commit is fixing the issue.

I'm looking forward to the features coming to work.

until there's a new official release of the package, you can install the fixed version directly from github:

devtools::install_github(repo="haozhu233/kableExtra", ref="a6af5c0")

ref here is the bugfix commit mentioned above. you should start a fresh R session afterwards.

@motocci
Copy link

motocci commented Mar 28, 2021

i'm happy to confirm that the commit is fixing the issue.

I'm looking forward to the features coming to work.

until there's a new official release of the package, you can install the fixed version directly from github:

devtools::install_github(repo="haozhu233/kableExtra", ref="a6af5c0")

ref here is the bugfix commit mentioned above. you should start a fresh R session afterwards.

It is the same display as the document and is the ideal display.
I appreciate it.

@motocci
Copy link

motocci commented Mar 28, 2021

Sorry.
I tested git one.
Another problem has occurred.

If I use the table below,

C1C2C3C4
Aa10
21
30
b40
51
Ba61
71
80
b90
101
110
Cb121
131
141
Da150
160
171
Ea180
191
201
b210
221

It appears llike below.

C1C2C3C4
Aa10
21
30
b40
51
Ba61
71
80
b90
101
110
C121
131
141
Da150
160
171
E180
191
201
b210
221

C1=C 's C2 (C3=12) and C1=E 's C2 (C3=18) not appeared.
Regards.

@christopherkn
Copy link

collapse_rows() is still not working for me, even with the version installed directly from github @unDocUMeantIt can you explain what you meant by "a quickfix to get the expected data frame back could be wrapping it in as.data.frame(html_table())." What is the "it" you wrap in that? I'm just working with the data from the kableExtra documentation:

collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
                               C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
                               C3 = 1:15,
                               C4 = sample(c(0,1), 15, replace = TRUE))
kbl(collapse_rows_dt, align = "c") %>%
  kable_paper(full_width = F) %>%
  column_spec(1, bold = T) %>%
  collapse_rows(columns = 1:2, valign = "top")

wrapping the whole thing in as.data.frame(html_table()) :

as.data.frame(html_table(kbl(collapse_rows_dt, align = "c") %>%
  kable_paper(full_width = F) %>%
  column_spec(1, bold = T) %>%
  collapse_rows(columns = 1:2, valign = "top")))

gives Error in UseMethod("html_table") : no applicable method for 'html_table' applied to an object of class "c('kableExtra', 'knitr_kable')"

wrapping just the dataframe:

kbl(as.data.frame(html_table(collapse_rows_dt)), align = "c") %>%
  kable_paper(full_width = F) %>%
  column_spec(1, bold = T) %>%
  collapse_rows(columns = 1:2, valign = "top")

which gives: Error in UseMethod("html_table") : no applicable method for 'html_table' applied to an object of class "data.frame"

@unDocUMeantIt
Copy link

can you explain what you meant by "a quickfix to get the expected data frame back could be wrapping it in as.data.frame(html_table())."

i was refering to the source code of kableExtra, which is what was added with a6af5c0 .

@cmstewart-sca
Copy link

It isn't working for me either. Using rvest 1.0 and kableextra 1.3.4. I've been using it for a blogdown post and it previously worked but has now ceased to do anything.

@jacpete
Copy link

jacpete commented Aug 26, 2021

It isn't working for me either. Using rvest 1.0 and kableextra 1.3.4. I've been using it for a blogdown post and it previously worked but has now ceased to do anything.

I was having the same issue, but you still need the development version as of 2021-08-26. The version of {kableExtra} on CRAN does not have the a6af5c0 commit yet. See my comment on #624 for more details. @unDocUMeantIt mentioned this right after the commit was implemented:

i'm happy to confirm that the commit is fixing the issue.

I'm looking forward to the features coming to work.

until there's a new official release of the package, you can install the fixed version directly from github:

devtools::install_github(repo="haozhu233/kableExtra", ref="a6af5c0")

ref here is the bugfix commit mentioned above. you should start a fresh R session afterwards.

Looks like the CRAN version will have to be > 1.3.4 to have this fix included.

@dholstius
Copy link

I installed 1.3.4.9000 from GitHub. The example from ?collapse_rows doesn't seem to work:

dt <- data.frame(a = c(1, 1, 2, 2), b = c("a", "a", "a", "b"))
(x <- knitr::kable(dt, format = "markdown"))
a b
1 a
1 a
2 a
2 b
collapse_rows(x)
a b
1 a
1 a
2 a
2 b

In addition:

Warning message:
In collapse_rows(x) :
  Please specify format in kable. kableExtra can customize either HTML or LaTeX outputs. See https://haozhu233.github.io/kableExtra/ for details.

I'm expecting three rows of output, like:

a b
1 a
2 a
2 b

@Robsteranium
Copy link

a6af5c0 with rvest 1.0.2 works for me

@burgerga
Copy link

burgerga commented May 25, 2022

At @dholstius, collapse_rows doesn't work on "markdown" format (see https://github.com/haozhu233/kableExtra/blob/master/R/collapse_rows.R#L56-L61) so you just get your input back

@Robsteranium Apparently the CRAN release is quite old, the master branch includes that commit and works as well (see #706 )

@fthielen
Copy link

fthielen commented Nov 3, 2023

This is still not resolved. Is the package still maintained?

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