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

Using skimr with purr:map does not generate html format #671

Open
mdav43 opened this issue Oct 20, 2021 · 9 comments
Open

Using skimr with purr:map does not generate html format #671

mdav43 opened this issue Oct 20, 2021 · 9 comments

Comments

@mdav43
Copy link

mdav43 commented Oct 20, 2021

Using the package to print summary information across a list (of tibbles usually), I can't get the package to ouput to html in an R Notebook - using the Knit command.

Example below.

a <- 1:3
b <- letters[4:6]
list = lst(a, b)
list %>% map(skim) # prints in raw format
skim(a) # prints in html format AS EXPECTED

Not sure if this is a bug or I'm just using skimr incorrectly with the map.

@elinw
Copy link
Collaborator

elinw commented Oct 24, 2021

This is what I got in a regular markdown file.
https://rpubs.com/elinw/skimmap

@mdav43
Copy link
Author

mdav43 commented Oct 26, 2021

In your above example, the output of list %>% map(skim) plain text. The last line skim(a) is missing.

Referring to this link - https://rpubs.com/dav43/adfg - you can see that skim(a) -> produces HTML, where as the list %>% map(skim) still produces raw text output.

Just wanting to clarify if this is a bug or not. If not, I assumed that list %>% map(skim) should produce a list of consecutive HTML format tables.

@elinw
Copy link
Collaborator

elinw commented Nov 1, 2021

So the issue is (I think) that knit_print is not kicking in because the print method for list calls the regular print. I could potentially see a few possible ways to make it work.

@elinw
Copy link
Collaborator

elinw commented Nov 2, 2021

So something like this

a <- 1:3
b <- letters[4:6]
list = lst(a, b)
xl <- list %>% map(skim

knit_print_list_skim <- function(x)  {
  results <- character()
  for(i in (1:length(x))){

    results <- c(results,"\nn",
                 skimr:::knit_print.skim_df(x[[i]]))
  }
  asis_output(results)
}
knit_print_list_skim(xl)

Starts to get at the issue, but the formatting isn't right on the subtables..

It's not an issue with purrr or map specifically, it is anything with having a list of skim_df objects. These have to go into a somewhat complicated process if you want to do anything besides individually naming the elements of the list. I guess what happens is that the dispatch for printing lists is already a big complex and the knit_print adds to that.

@elinw
Copy link
Collaborator

elinw commented Dec 4, 2021

@michaelquinn32 Any thoughts on this?

@michaelquinn32
Copy link
Collaborator

We don't have a knit_print method for a list of skim_df objects. You can hack something together:

library(skimr)
library(purrr)
library(knitr)

a <- 1:3 
b <- letters[4:6] 


list(a, b)  %>%
  purrr::map(skim) %>%
  purrr::map_chr(knitr::knit_print, options = list(skimr_include_summary = FALSE)) %>%
  knitr::asis_output()

My version of Rstudio (actually Rstudio server running on WSL), does something weird with the summaries, so I turned that off. Otherwise, the results look about right to me.

@elinw
Copy link
Collaborator

elinw commented Dec 18, 2021 via email

@elinw
Copy link
Collaborator

elinw commented Dec 21, 2021

Here's an rpubs rendering with @michaelquinn32 's code
https://rpubs.com/elinw/map

I'm really sure that including summary would be problematic because of how the code is structured. If anything I would separately run just the summaries and then if you really wanted you could potentially merge them back together.

Also we do have knit_print.skim_df but it's not exported.

@elinw
Copy link
Collaborator

elinw commented Dec 23, 2022

I think we should consider dealing with making summary more functional should be one of the goals for 2.2. I would actually like to export the print for skim_df since I think it gives some more flexibility to users to customize reports. One of the big issues is still dealing with the lines that are too wide for the paper/slides when people knit. Wow this was 12 months ago.

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

3 participants