'Automatically Create Tabbed skim() results with Proper Output format
I'm trying to create dynamically create tabbed output of skim()
results in a R
Notebook, but the output format comes out all funky.
I'm using the asis
results option and this works well when I'm publishing plots. When I tried this code for skim()
```{r eval=TRUE, results='asis', echo=FALSE}
cat("# Main Tab {.tabset}")
cat('\n\n')
cat('## Subtab 1')
cat('\n\n')
iris %>% skim()
```
The Headers and tabs look right, but the output format is off.
I've tried to remove the asis
in the chunk options and use knitr::asis_output()
for the headers, but then the headers don't get tabbed correctly.
Converting the skim()
results into a table via kable()
also doesn't have a great format either when you knit to a notebook.
Eventually, I want to loop through a list of dataframes and skim each one. How can I create the same look as the skim()
output format in each tab for this output?
thanks!
Solution 1:[1]
When I run the following code it looks like this:
---
title: "Test"
author: "Author"
date: '2022-05-13'
output: html_document
---
```{r eval=TRUE, results='asis', echo=FALSE}
library(dplyr)
library(skimr)
cat("# Main Tab {.tabset}")
cat('\n\n')
cat('## Subtab 1')
cat('\n\n')
iris %>% skim()
```
Output:
Sessioninfo
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 12.3.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] nl_NL.UTF-8/nl_NL.UTF-8/nl_NL.UTF-8/C/nl_NL.UTF-8/nl_NL.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] skimr_2.1.3 sjPlot_2.8.10 tm_0.7-8 NLP_0.2-1 cowplot_1.1.1
[6] raster_3.5-15 sp_1.4-6 sf_1.0-7 ggstatsplot_0.9.1 highcharter_0.9.4
[11] plyr_1.8.6 robfilter_4.1.2 MASS_7.3-55 robustbase_0.93-9 ggforce_0.3.3
[16] xgboost_1.5.2.1 ranger_0.13.1 glmnet_4.1-3 Matrix_1.4-0 shiny_1.7.1
[21] pROC_1.18.0 mlbench_2.1-3 RANN_2.6.1 intrval_0.1-2 caret_6.0-90
[26] lattice_0.20-45 gridExtra_2.3 gdtools_0.2.4 kableExtra_1.3.4 hms_1.1.1
[31] knitr_1.37 qwraps2_0.5.2 janitor_2.1.0 readxl_1.3.1 forcats_0.5.1
[36] purrr_0.3.4 readr_2.1.2 tidyr_1.2.0 tibble_3.1.7 tidyverse_1.3.1
[41] fma_2.4 forecast_8.16 plotly_4.10.0 stringr_1.4.0 sportyR_1.0.1
[46] ggplot2_3.3.6 dplyr_1.0.8 tidyquant_1.0.3 quantmod_0.4.18 TTR_0.24.3
[51] PerformanceAnalytics_2.0.4 xts_0.12.1 zoo_1.8-9 lubridate_1.8.0 data.table_1.14.2
[56] magrittr_2.0.3
loaded via a namespace (and not attached):
[1] estimability_1.3 ModelMetrics_1.2.2.2 coda_0.19-4 rpart_4.1.16 hardhat_0.2.0
[6] generics_0.1.2 terra_1.5-21 proxy_0.4-26 future_1.24.0 correlation_0.8.0
[11] tzdb_0.2.0 rlist_0.4.6.2 webshot_0.5.2 xml2_1.3.3 httpuv_1.6.5
[16] wk_0.6.0 assertthat_0.2.1 gower_1.0.0 WRS2_1.1-3 xfun_0.30
[21] evaluate_0.15 promises_1.2.0.1 DEoptimR_1.0-10 fansi_1.0.3 dbplyr_2.1.1
[26] igraph_1.2.11 DBI_1.1.2 htmlwidgets_1.5.4 reshape_0.8.8 Quandl_2.11.0
[31] kSamples_1.2-9 stats4_4.1.0 Rmpfr_0.8-7 paletteer_1.4.0 ellipsis_0.3.2
[36] crosstalk_1.2.0 backports_1.4.1 insight_0.17.0 prismatic_1.1.0 vctrs_0.4.1
[41] sjlabelled_1.1.8 cachem_1.0.6 withr_2.5.0 rgdal_1.5-28 emmeans_1.7.2
[46] svglite_2.1.0 lazyeval_0.2.2 urca_1.3-0 crayon_1.5.1 recipes_0.2.0
[51] pkgconfig_2.0.3 SuppDists_1.1-9.7 slam_0.1-50 labeling_0.4.2 units_0.8-0
[56] tweenr_1.0.2 nlme_3.1-155 statsExpressions_1.3.1 nnet_7.3-17 rlang_1.0.2
[61] globals_0.14.0 lifecycle_1.0.1 MatrixModels_0.5-0 modelr_0.1.8 cellranger_1.1.0
[66] randomForest_4.7-1 polyclip_1.10-0 lmtest_0.9-39 datawizard_0.3.0 mc2d_0.1-21
[71] boot_1.3-28 base64enc_0.1-3 reprex_2.0.1 viridisLite_0.4.0 PMCMRplus_1.9.4
[76] parameters_0.17.0 KernSmooth_2.23-20 shape_1.4.6 classInt_0.4-3 multcompView_0.1-8
[81] s2_1.0.7 parallelly_1.30.0 ggeffects_1.1.1 scales_1.2.0 memoise_2.0.1
[86] compiler_4.1.0 rstantools_2.2.0 RColorBrewer_1.1-3 lme4_1.1-28 snakecase_0.11.0
[91] cli_3.3.0 listenv_0.8.0 patchwork_1.1.1 pbapply_1.5-0 tidyselect_1.1.2
[96] stringi_1.7.6 tseries_0.10-49 yaml_2.3.5 ggrepel_0.9.1 tools_4.1.0
[101] future.apply_1.8.1 parallel_4.1.0 rstudioapi_0.13 foreach_1.5.2 prodlim_2019.11.13
[106] farver_2.1.0 digest_0.6.29 lava_1.6.10 quadprog_1.5-8 BWStest_0.2.2
[111] Rcpp_1.0.8.3 broom_0.7.12 BayesFactor_0.9.12-4.3 performance_0.8.0 later_1.3.0
[116] httr_1.4.2 rsconnect_0.8.25 kernlab_0.9-29 effectsize_0.6.0.1 sjstats_0.18.1
[121] colorspace_2.0-3 rvest_1.0.2 fs_1.5.2 splines_4.1.0 rematch2_2.1.2
[126] systemfonts_1.0.4 xtable_1.8-4 gmp_0.6-5 nloptr_2.0.0 jsonlite_1.8.0
[131] timeDate_3043.102 zeallot_0.1.0 ipred_0.9-12 R6_2.5.1 pillar_1.7.0
[136] htmltools_0.5.2 mime_0.12 minqa_1.2.4 glue_1.6.2 fastmap_1.1.0
[141] class_7.3-20 codetools_0.2-18 mvtnorm_1.1-3 utf8_1.2.2 curl_4.3.2
[146] gtools_3.9.2 survival_3.3-1 repr_1.1.4 rmarkdown_2.13 munsell_0.5.0
[151] e1071_1.7-9 iterators_1.0.14 sjmisc_2.8.9 haven_2.4.3 fracdiff_1.5-1
[156] reshape2_1.4.4 gtable_0.3.0 bayestestR_0.11.5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |