Create HTML DOM Details block for Markdown documents with summary as optional.
details(
object,
...,
summary = NULL,
tooltip = "Click to Expand",
open = FALSE,
lang = "r",
output = c("console", "clipr", "edit", "character", "html"),
imgur = TRUE,
comment = NA
)
object, object to put in details block
arguments to pass to print method of the object
character, text to put in summary block, Default: NULL
character, text for tooltip on the summary, Default: 'Click to Expand'
logical, is the details open (TRUE) or closed (FALSE), Default: FALSE
character, language of block (for markdown highlighting) Default: 'r'
character, where to output the file console (Default), clipboard or R file editor, Default: c('console','clipr','file.edit','character')
logical, upload device outputs to imgur, Default: TRUE
character, the prefix to be put before source code output, Default: NA
character
To remove summary or tooltip set them to NULL. If the object is a file path, it will automatically it's lines will be read in internally.
If lang is 'none' then the output will not be wrapped in a code block and will display the raw output (useful for HTML)
When using details in knitr/rmarkdown documents there is no need to set the results to 'asis', there are already predefined print methods for these environments.
... is passed to objects that do not invoke an image device.
#basic
details::details('test')
#> <details closed>
#>
#> ```r
#>
#> test
#>
#> ```
#>
#> </details>
#> <br>
#sessionInfo
details::details(sessionInfo(), summary = 'sessionInfo')
#> <details closed>
#> <summary> <span title='Click to Expand'> sessionInfo </span> </summary>
#>
#> ```r
#>
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
#> [4] LC_COLLATE=C LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
#> [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] details_0.4.0
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 httr_1.4.7 cli_3.6.3 knitr_1.49
#> [5] rlang_1.1.5 xfun_0.50 png_0.1-8 purrr_1.0.2
#> [9] glue_1.8.0 clipr_0.8.0 htmltools_0.5.8.1 fansi_1.0.6
#> [13] rmarkdown_2.29 rappdirs_0.3.3 grid_4.4.2 evaluate_1.0.3
#> [17] tibble_3.2.1 fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4
#> [21] httr2_1.1.0 memoise_2.0.1 whisker_0.4.1 compiler_4.4.2
#> [25] sessioninfo_1.2.2 fs_1.6.5 downlit_0.4.4 pkgconfig_2.0.3
#> [29] digest_0.6.37 R6_2.5.1 curl_6.2.0 pillar_1.10.1
#> [33] magrittr_2.0.3 tools_4.4.2 withr_3.0.2 pkgdown_2.1.1
#> [37] xml2_1.3.6 cachem_1.1.0 desc_1.4.3
#>
#> ```
#>
#> </details>
#> <br>
#data.frame
details::details(head(mtcars))
#> <details closed>
#>
#> ```r
#>
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
#> Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
#> Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
#> Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
#>
#> ```
#>
#> </details>
#> <br>
#plots
# \donttest{
details(
plot(x = mtcars$mpg, y = mtcars$wt),
summary = 'Plots', imgur = interactive())
#> [1] "<details closed>\n<summary> <span title='Click to Expand'> Plots </span> </summary>\n\n/tmp/Rtmpv9PB4y/file2eb572fe0d02.png\n\n</details>\n<br>"
#> attr(,"file")
#> [1] "/tmp/Rtmpv9PB4y/file2eb572fe0d02.png"
#> attr(,"class")
#> [1] "details_image"
# }
#output options
#character
details::details('test', output = 'character')
#> [1] "<details closed>" "" "```r" ""
#> [5] "test" "" "```" ""
#> [9] "</details>" "<br>"
#clipboard
if(clipr::clipr_available()){
details::details('test', output = 'clipr')
clipr::read_clip()
}
#file.edit
# \donttest{
details::details('test', output = 'edit')
#> Warning: Not an interactive enviornment, falling back to output = "console"
#> <details closed>
#>
#> ```r
#>
#> test
#>
#> ```
#>
#> </details>
#> <br>
# }