rmd_tab_iterator | R Documentation |
RMarkdown tab iterator
rmd_tab_iterator(
tab_list,
fn_list = NULL,
base_fn = NULL,
tab_labels = NULL,
heading_level = 2,
verbose = FALSE,
quiet = TRUE,
htmlOut = TRUE,
envir = NULL,
...
)
tab_list |
|
fn_list |
|
base_fn |
|
heading_level |
|
verbose |
|
quiet |
|
htmlOut |
|
envir |
|
... |
additional arguments are ignored but passed to iterative calls to this function. |
This function is intended to help automate the process of generating tabs in RMarkdown output, particularly when there may be multiple layers of tabs. The driving example plots a figure at the lowest level of tabs, using the options defined by the tabs collectively.
While tabs can be created using for
loops or lapply()
methods,
the RMarkdown code quickly becomes complicated and difficult to maintain.
Each layer of tabs is iterated, and a preparatory function can be called, for example to update data to be used downstream. Any layer is free to create a figure, table, or text output, however it is usually recommended to create output at the lowest layer.
Output can be defined in the final fn_list
layer, however it is cleaner
to use the argument base_fn
to generate final output such as figure
or table. The functions in fn_list
should be limited to those required
for updates during the process.
To store data objects generated within each call to base_fn()
:
First define an output object as list()
upfront.
For example, this call beforehand: output_heatmap_list <- list()
Then inside base_fn
assign data to that object using variables
in tab_list
, using <<-
parent environment assignment.
For example:
output_heatmap_list[[tab_name1]][[tab_name2]] <<- hm_drawn
Of course, multiple types of data can be stored by using different
list
objects.
It may be helpful to catch errors, then display the error message
for debugging. (Error handling is being implemented but may still be
helpful in context of base_fn
to indicate the specific step.)
For example:
tryCatch( { x }, error=function(e){ jamba::printDebugHtml("Error during x:"); jamba::printDebugHtml(e); })
The function jamba::printDebugHtml()
will output HTML formatted
text suitable for use in RMarkdown being rendered into HTML.
An alternative is to use print()
or jamba::printDebug()
,
however the output may not render legibly in HTML format (but in
that case the text will still be readable in the HTML source).
Implement tab visibility within fn_list
so that tabs can be
hidden at the corresponding level of particular tab values.
In this case it should also hide all child tabs.
Consider a situation with three layers of tabs, a particular value in the second layer may be hidden, in which case all values in the third layer will also be hidden.
NULL
invisibly, this function is called for the by-product
of printing RMarkdown-compatible output.
Other jam utility functions:
cardinality()
,
color_complement()
,
convert_PD_df_to_SE()
,
convert_imputed_assays_to_na()
,
curate_se_colData()
,
curate_to_df_by_pattern()
,
design2layout()
,
get_numeric_transform()
,
handle_df_args()
,
merge_proteomics_se()
,
nmat_summary()
,
nmatlist_summary()
,
rowNormScale()
,
summit_from_vector()
tab_labels <- list(
assay_name=c(
raw="raw data",
jammanorm_raw="log ratio normalized",
quantile_raw="quantile normalized"),
centerby_name=c(
global="global-centered",
`1st_control`="centered vs first control")
)
base_fn <- function(...){
plot(x=c(0, 3), y=c(0, 3), asp=1, pch=".")
text(x=c(1, 1.5, 2), y=c(1, 1.5, 2),
c(paste0("assay_name:\n", assay_name),
paste0("formatting:\n", formatting),
paste0("centerby_name:\n", centerby_name)))
}
tab_list <- list(
assay_name=c("raw", "jammanorm_raw", "quantile_raw"),
formatting=c("tab-delimited", "RData"),
centerby_name=c("global", "1st_control"))
rmd_tab_iterator(
tab_list=tab_list,
fn_list=NULL,
base_fn=base_fn,
tab_labels=tab_labels,
heading_level=3,
verbose=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.