It allows to automatically generate the code necessary to group multiple Rmarkdown chunks into tabs. Concatenating all the chunks into a string that can be later knitted and rendered.
automagic_tabs2( input_data, panel_name, ..., tabset_title = "", tabset_props = ".tabset-fade .tabset-pills", chunk_props = list(echo = FALSE, fig.align = "center"), is_output_distill = TRUE )
input_data | Ungrouped tibble with at least 2 columns, one for the title of the tabs and another with the output to be displayed. |
---|---|
panel_name | column with the ID variable. |
... | nested columns that contain outputs to display. |
tabset_title | string title of the .tabset |
tabset_props | string defining .tabset properties. Only works with is_output_distill = F |
chunk_props | named list with additional parameters that correspond to all those available in rmarkdown chunks (fig.align, fig.width, ...). |
is_output_distill | boolean. is output a distill article. |
concatenated string of all automatically generated chunks.
given a tiblle, which must contain an "ID" column (representing the title of the tabs) and other columns that stores output to be generated (plot, text, code, ...), a string is automatically generated which can be later rendered in a Rmarkdown document.
library(dplyr) library(sknifedatar) library(ggplot2) dataset <- iris %>% group_by(Species) %>% tidyr::nest() %>% mutate( .plot = purrr::map(data, ~ ggplot(.x, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()), .table = purrr::map(data, ~ summary(.x) %>% knitr::kable()) ) %>% ungroup() automagic_tabs2(input_data = dataset, panel_name = Species, .plot, .table)#> | | | 0% | |.......... | 14% #> ordinary text without R code #> #> | |.................... | 29% #> label: `r automagic_chunk_dataset_setosa` (with options) #> List of 2 #> $ echo : logi FALSE #> $ fig.align: chr "center" #> #> | |.............................. | 43% #> ordinary text without R code #> #> | |........................................ | 57% #> label: `r automagic_chunk_dataset_versicolor` (with options) #> List of 2 #> $ echo : logi FALSE #> $ fig.align: chr "center" #> #> | |.................................................. | 71% #> ordinary text without R code #> #> | |............................................................ | 86% #> label: `r automagic_chunk_dataset_virginica` (with options) #> List of 2 #> $ echo : logi FALSE #> $ fig.align: chr "center" #> #> | |......................................................................| 100% #> ordinary text without R code #> #>#> [1] "## { .tabset-fade .tabset-pills} \n\n::::: {.panelset}\n\n::: {.panel}\n\n### setosa \n\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n:::\n::: {.panel}\n\n### versicolor \n\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n:::\n::: {.panel}\n\n### virginica \n\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n```\n## Error in eval(expr, envir, enclos): object 'dataset' not found\n```\n\n::: \n\n:::::"