ropensci / skimr

A frictionless, pipeable approach to dealing with summary statistics
https://docs.ropensci.org/skimr
1.11k stars 79 forks source link

loading kableExtra seems to break the skim html output #637

Open ArthurAndrews opened 3 years ago

ArthurAndrews commented 3 years ago

First of all, thanks for the great package!

I haven't been able to use skimr and kableExtra in the same Markdown document. If I have a library(kableExtra) statement, the skim table doesn't print correctly in the knit document.

I was able to create these two simple documents to illustrate the problem. I'm on Windows 10 and using skimr 2.1.2.

This one has the issue

title: "skim test"
output: html_document
---

```{r}
library(skimr)
library(knitr)
library(kableExtra) # this messes up the skim table
```

```{r}
skim(iris)
```

This one works

title: "skim test"
output: html_document
---

```{r}
library(skimr)
library(knitr)
```

```{r}
skim(iris)
```
michaelquinn32 commented 3 years ago

Hi Arthur!

I'm wording if if we somehow have a namespace clash. Can you please install the reprex package and call the following:

reprex::reprex({
  library(skimr)
  library(knitr)
  library(kableExtra)
})

Otherwise, could you let me know what else you mean by doesn't print correctly"? Is it a unicode character issue or something else?

Thanks!

elinw commented 3 years ago

Yes I definitely see some formatting issues in html, PDF and Word.

elinw commented 3 years ago

kableExtra does have its own exported kable() function. So that could be causing a clash.

ArthurAndrews commented 3 years ago

reprex::reprex({ library(skimr) library(knitr) library(kableExtra) })

Here's my reprex output. Doesn't seem to throw any errors. I don't get any warnings, even about function conflicts.

library(skimr)
library(knitr)
library(kableExtra)

Created on 2021-02-22 by the reprex package (v1.0.0)

ArthurAndrews commented 3 years ago

Otherwise, could you let me know what else you mean by doesn't print correctly"? Is it a unicode character issue or something else?

No problem. Seems to be a combination of unicode issue and formatting. Unicode issues for the histograms, where I see output like "U+2586". Formatting issues where the fonts seem too large and the column titles overlap and the column entries don't line up nicely.

elinw commented 3 years ago

You are on Windows, and we explain in the documentation that R on Windows at this point does not support unicode.

elinw commented 3 years ago

I really feel this is a problem of kableExtra, but still we may need to fix. It also impacts printing on the console. I checked our code and any time we use the knitr() function we namespace it, but it's probably that there is another namespace issue buried inside knitr. Is there a way we can explicitly unload kableExtra?

elinw commented 3 years ago

So the explanation is the kableExtra changes the default to html. We could possibly try to change the default back but I guess the question is why use kableExtra when using skimr?

ArthurAndrews commented 3 years ago

So the explanation is the kableExtra changes the default to html. We could possibly try to change the default back but I guess the question is why use kableExtra when using skimr?

Any time a person wants to display html tables and data frame summary statistics in the same markdown document, they might use the two packages. They have different purposes.

elinw commented 3 years ago

Right now, I think until kableExtra comes up with a less intrusive way of doing things, you would need to change the default before and after skimming. I have no idea if that will actually work. I'm really surprised that CRAN allowed this.

elinw commented 2 years ago

@haozhu233 Were you ever able to address this issue in kableExtra?

haozhu233 commented 2 years ago

@elinw Sure, sorry for the delay. There is an option in kableExtra that controls this behavior.

options(kableExtra.auto_format = FALSE)

If you turn the auto_format option off, kableExtra will no longer automatically set the global environment for knitr::kable. How about adding the above option to zzz.R in skimr? It will change the default behavior of kableExtra but I think that's the best thing we can do at this moment.

michaelofrancis commented 2 years ago

Is it possible to put a note about this in the skimr vignette? I'm new to skimr and just spent a couple hours trying to fix this before coming across this solution in the post. Might save others some time in the future.

michaelquinn32 commented 1 year ago

Really sorry for the inconvenience!

I'd be happy to accept a PR to add this. If you're interested, please check out the contributing guide.

Thanks!