ropensci / skimr

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

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

Open mdav43 opened 2 years ago

mdav43 commented 2 years ago

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 commented 2 years ago

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

mdav43 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@michaelquinn32 Any thoughts on this?

michaelquinn32 commented 2 years ago

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 commented 2 years ago

So the key is getting it to use knit_print directly ... I think we should certainly document this somewhere. But the question for me is whether we create a function that aliases that.

On Fri, Dec 17, 2021 at 10:40 PM Michael Quinn @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/ropensci/skimr/issues/671#issuecomment-997135965, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFYI7PTQYGOMGZUZH5MHO3URP7D3ANCNFSM5GLCVOTA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

elinw commented 2 years ago

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 commented 1 year ago

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.