ropensci / skimr

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

changing digits options in chunk doesn't work in a pipe #669

Closed blueja5 closed 2 years ago

blueja5 commented 2 years ago

Hi, I am using skimr to make my descriptives, I am then piping the output to make a latex table. e.g.

Stroops %>% my_skim() %>% yank("numeric") %>% kbl(format = "latex", booktabs = T, caption = "Inhibition diff.n Descriptives") %>% kable_styling(latex_options = c("striped","hold_position", "scale_down"),font_size = 12) %>% save_kable(paste(resultspath,"DescTableStroops.tex",sep=""))

I have skimr_digits set in the chunk but if I pipe to kable it reverts to full digits. I can set the digits in kable which solves my functional problem but took me a long time to work out. Setting the digits works in markdown but not in notebook unless you do a full knit. It would be useful to have some more detailed info about this in the vignette.

michaelquinn32 commented 2 years ago

Hi!

Let me see if I understood your problem.

You are skimming within an Rmarkdown doc/notebook. You've set chunk options within the doc, but you've also exported your skim table via kable to a local file. TBH, I'm not familiar with that familiar kbl() function, but I think you're using the function out of kableExtra.

If this is the case, I'm going to consider this working as intended and close the the issue. The chunk option controls how the table is displayed in the rendered version of your document. It is not meant to set an option for other context for rendering kable() output.

Setting the option in kbl() should solve your problem.

NUMBER_OF_DIGITS <- 4
Stroops %>%
  my_skim() %>%
  yank("numeric") %>%
  kbl(
    digits = NUMBER_OF_DIGITS,
    format = "latex",
    booktabs = T,
    caption = "Inhibition diff.n Descriptives"
  ) %>%
  kable_styling(
    latex_options = c("striped","hold_position", "scale_down"),
    font_size = 12
  ) %>%
  save_kable(paste(resultspath,"DescTableStroops.tex",sep=""))

Best wishes, Michael

blueja5 commented 2 years ago

Thank you it does!! It wasn't obvious to me at all that i couldn't expect it to work in the pipe