Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

169 wrapping up the long code in the Report #218

Merged
merged 45 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6ebeb49
checking formatR and adding option to tidy options
Sep 26, 2023
007e574
updating news.md
Sep 27, 2023
0c5fdb1
fixing linter
Sep 27, 2023
26ea791
Merge 0c5fdb1db02de98bc2f09090d2aaac76d9fba092 into 4fa942ec6c8c72f46…
kartikeyakirar Sep 27, 2023
bf95d7e
[skip actions] Restyle files
github-actions[bot] Sep 27, 2023
0e7758b
Empty-Commit
Sep 27, 2023
33625e5
removing news
Sep 27, 2023
2dd832b
updating news and fixing linter issue.
Sep 28, 2023
c82fbb8
Merge branch 'main' into 169_wrap_rcode@main
kartikeyakirar Sep 28, 2023
2618a7f
fixing RMD check
Sep 28, 2023
69b6e7c
Merge branch '169_wrap_rcode@main' of https://github.com/insightsengi…
Sep 28, 2023
74cf1b9
exposing global_knitr parameter
Sep 29, 2023
79bd779
adding default options on functions efination.
Sep 29, 2023
a07f0f4
merge back from main
Sep 29, 2023
7bbb7f9
Merge a07f0f4224233e4dd3b5e3658ac60e68908b8693 into 4a2ee336480c9ff85…
kartikeyakirar Sep 29, 2023
9ca057a
[skip actions] Restyle files
github-actions[bot] Sep 29, 2023
8076344
setting teal.reporter.global_knitr.
Sep 29, 2023
684cfaa
Merge branch '169_wrap_rcode@main' of https://github.com/insightsengi…
Sep 29, 2023
d79df80
Merge 684cfaaba995cdec1fbcf81c6298f341b31a562e into 4a2ee336480c9ff85…
kartikeyakirar Sep 29, 2023
7e0e03c
[skip actions] Restyle files
github-actions[bot] Sep 29, 2023
7b06e93
Empty-Commit
Sep 29, 2023
a05d616
fixing lintr and added assertion on global_knitr
Sep 29, 2023
d379ddc
Removing the message from renderrmd and moving it onload()
Oct 2, 2023
5b0e811
adding startupMessage
Oct 2, 2023
07543fa
placing packageStartupMessage .onLoad()
kartikeyakirar Oct 2, 2023
54523a4
fixing cmd check
Oct 3, 2023
706d504
updated .onload()
kartikeyakirar Oct 3, 2023
8fa2e3a
Merge branch 'main' into 169_wrap_rcode@main
kartikeyakirar Oct 3, 2023
a08cca5
merge back from main and updated teal.reporter.global_knitr
kartikeyakirar Oct 3, 2023
cac16b0
Update R/Previewer.R
kartikeyakirar Oct 4, 2023
5f132ef
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 4, 2023
b78d874
Updating documentation
kartikeyakirar Oct 4, 2023
577163f
Merge branch '169_wrap_rcode@main' of https://github.com/insightsengi…
kartikeyakirar Oct 4, 2023
1448099
Fixing linter
kartikeyakirar Oct 4, 2023
19a23f5
adding details for simpleReporter
kartikeyakirar Oct 4, 2023
4379685
Update R/DownloadModule.R
kartikeyakirar Oct 4, 2023
b1ab7c1
Update R/zzz.R
kartikeyakirar Oct 4, 2023
f08f5b8
Update R/DownloadModule.R
kartikeyakirar Oct 4, 2023
17bec72
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 4, 2023
d222ef4
inherits details from simpleReporter
kartikeyakirar Oct 4, 2023
aef6767
empty commit
kartikeyakirar Oct 4, 2023
7b3b89c
use inline code for details and defined the min version of formatR
kartikeyakirar Oct 4, 2023
c5ed90a
Merge 7b3b89c9366f7501f785bd0e3f53a08b809a7061 into b82c2acb63cf2ef80…
kartikeyakirar Oct 4, 2023
bd4a839
[skip actions] Restyle files
github-actions[bot] Oct 4, 2023
71b6d8a
'Empty-Commit'
kartikeyakirar Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL
object_usage_linter = NULL,
indentation_linter = NULL
)
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Imports:
zip (>= 1.1.0)
Suggests:
DT (>= 0.13),
formatR (>= 1.5),
ggplot2 (>= 3.4.0),
lattice (>= 0.18-4),
png,
Expand All @@ -44,8 +45,8 @@ RdMacros:
Config/Needs/verdepcheck: rstudio/bslib, mllg/checkmate,
rstudio/htmltools, yihui/knitr, r-lib/lifecycle, r-lib/R6,
rstudio/rmarkdown, rstudio/shiny, dreamRs/shinyWidgets,
yaml=vubiostat/r-yaml, r-lib/zip, davidgohel/flextable, rstudio/DT,
tidyverse/ggplot2, deepayan/lattice, cran/png,
yaml=vubiostat/r-yaml, r-lib/zip, davidgohel/flextable, rstudio/DT,
yihui/formatR, tidyverse/ggplot2, deepayan/lattice, cran/png,
insightsengineering/rtables, r-lib/testthat, rstudio/tinytex
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization.

* Supports automatic `Rcode` formatting using the suggested `formatR` package in reports.

# teal.reporter 0.2.1

### Miscellaneous
Expand Down
9 changes: 7 additions & 2 deletions R/DownloadModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ download_report_button_ui <- function(id) {
#' For more details see the vignette: `vignette("simpleReporter", "teal.reporter")`.
#' @param id `character(1)` this `shiny` module's id.
#' @param reporter [`Reporter`] instance.
#' @param global_knitr `list` a of `knitr` parameters (passed to `knitr::opts_chunk$set`)
#' for customizing the rendering process.
#' @inheritParams reporter_download_inputs
#' @return `shiny::moduleServer`
#' @details `r global_knitr_details()`
#'
#' @export
download_report_button_srv <- function(id,
reporter,
global_knitr = getOption("teal.reporter.global_knitr"),
rmd_output = c(
"html" = "html_document", "pdf" = "pdf_document",
"powerpoint" = "powerpoint_presentation", "word" = "word_document"
Expand All @@ -48,6 +53,7 @@ download_report_button_srv <- function(id,
toc = FALSE
)) {
checkmate::assert_class(reporter, "Reporter")
checkmate::assert_subset(names(global_knitr), names(knitr::opts_chunk$get()))
checkmate::assert_subset(
rmd_output,
c(
Expand Down Expand Up @@ -134,8 +140,7 @@ download_report_button_srv <- function(id,
shiny::showNotification("Rendering and Downloading the document.")
input_list <- lapply(names(rmd_yaml_args), function(x) input[[x]])
names(input_list) <- names(rmd_yaml_args)
global_knitr <- list()
if (is.logical(input$showrcode)) global_knitr <- list(echo = input$showrcode)
if (is.logical(input$showrcode)) global_knitr[["echo"]] <- input$showrcode
report_render_and_compress(reporter, input_list, global_knitr, file)
},
contentType = "application/zip"
Expand Down
9 changes: 7 additions & 2 deletions R/Previewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ reporter_previewer_ui <- function(id) {
#' For more details see the vignette: `vignette("previewerReporter", "teal.reporter")`.
#' @param id `character(1)` this `shiny` module's id.
#' @param reporter `Reporter` instance
#' @param global_knitr `list` a of `knitr` parameters (passed to `knitr::opts_chunk$set`)
#' for customizing the rendering process.
#' @inheritParams reporter_download_inputs
#' @details `r global_knitr_details()`
#'
#' @export
reporter_previewer_srv <- function(id,
reporter,
global_knitr = getOption("teal.reporter.global_knitr"),
rmd_output = c(
"html" = "html_document", "pdf" = "pdf_document",
"powerpoint" = "powerpoint_presentation",
Expand All @@ -45,6 +50,7 @@ reporter_previewer_srv <- function(id,
toc = FALSE
)) {
checkmate::assert_class(reporter, "Reporter")
checkmate::assert_subset(names(global_knitr), names(knitr::opts_chunk$get()))
checkmate::assert_subset(
rmd_output,
c(
Expand Down Expand Up @@ -179,8 +185,7 @@ reporter_previewer_srv <- function(id,
shiny::showNotification("Rendering and Downloading the document.")
input_list <- lapply(names(rmd_yaml_args), function(x) input[[x]])
names(input_list) <- names(rmd_yaml_args)
global_knitr <- list()
if (is.logical(input$showrcode)) global_knitr <- list(echo = input$showrcode)
if (is.logical(input$showrcode)) global_knitr[["echo"]] <- input$showrcode
report_render_and_compress(reporter, input_list, global_knitr, file)
},
contentType = "application/zip"
Expand Down
22 changes: 12 additions & 10 deletions R/Renderer.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ Renderer <- R6::R6Class( # nolint: object_name_linter.
#' @description getting the `Rmd` text which could be easily rendered later.
#'
#' @param blocks `list` of `c("TextBlock", "PictureBlock", "NewpageBlock")` objects.
#' @param yaml_header `character` a `rmarkdown` `yaml` header.
#' @param global_knitr `list` a global `knitr` parameters, like echo.
#' But if local parameter is set it will have priority.
#' Defaults to empty `list()`.
#' @param yaml_header `character` an `rmarkdown` `yaml` header.
#' @param global_knitr `list` a of `knitr` parameters (passed to `knitr::opts_chunk$set`)
#' for customizing the rendering process.
#' @details `r global_knitr_details()`
#'
#' @return `character` a `Rmd` text (`yaml` header + body), ready to be rendered.
renderRmd = function(blocks, yaml_header, global_knitr = list()) {
renderRmd = function(blocks, yaml_header, global_knitr = getOption("teal.reporter.global_knitr")) {
checkmate::assert_list(blocks, c("TextBlock", "PictureBlock", "NewpageBlock", "TableBlock", "RcodeBlock"))
checkmate::assert_subset(names(global_knitr), names(knitr::opts_chunk$get()))

if (missing(yaml_header)) {
yaml_header <- md_header(yaml::as.yaml(list(title = "Report")))
}
Expand Down Expand Up @@ -84,13 +86,13 @@ Renderer <- R6::R6Class( # nolint: object_name_linter.
#'
#' @param blocks `list` of `c("TextBlock", "PictureBlock", "NewpageBlock")` objects.
#' @param yaml_header `character` an `rmarkdown` `yaml` header.
#' @param global_knitr `list` a global `knitr` parameters, like echo.
#' But if local parameter is set it will have priority.
#' Defaults to empty `list()`.
#' @param ... `rmarkdown::render` arguments, `input` and `output_dir` should not be updated.z
#' @param global_knitr `list` a of `knitr` parameters (passed to `knitr::opts_chunk$set`)
#' for customizing the rendering process.
#' @param ... `rmarkdown::render` arguments, `input` and `output_dir` should not be updated.
#' @details `r global_knitr_details()`
#'
#' @return `character` path to the output
render = function(blocks, yaml_header, global_knitr = list(), ...) {
render = function(blocks, yaml_header, global_knitr = getOption("teal.reporter.global_knitr"), ...) {
args <- list(...)
input_path <- self$renderRmd(blocks, yaml_header, global_knitr)
args <- append(args, list(
Expand Down
2 changes: 1 addition & 1 deletion R/ReportCard.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ReportCard <- R6::R6Class( # nolint: object_name_linter.
self$append_content(TextBlock$new(text, style))
invisible(self)
},
#' @description Appends a `rmarkdown` R chunk to this `ReportCard`.
#' @description Appends an `rmarkdown` R chunk to this `ReportCard`.
#'
#' @param text (`character(0)` or `character(1)`) the text
#' @param ... any `rmarkdown` R chunk parameter and its value.
Expand Down
5 changes: 5 additions & 0 deletions R/SimpleReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ simple_reporter_ui <- function(id) {
#' @param reporter [`Reporter`] instance.
#' @param card_fun `function` which returns a [`ReportCard`] instance,
#' the function has a `card` argument and an optional `comment` argument.
#' @param global_knitr `list` a global `knitr` parameters for customizing the rendering process.
#' @inheritParams reporter_download_inputs
#' @details `r global_knitr_details()`
#'
#' @return `shiny::moduleServer`
#' @export
simple_reporter_srv <- function(id,
reporter,
card_fun,
global_knitr = getOption("teal.reporter.global_knitr"),
rmd_output = c(
"html" = "html_document", "pdf" = "pdf_document",
"powerpoint" = "powerpoint_presentation", "word" = "word_document"
Expand All @@ -68,6 +72,7 @@ simple_reporter_srv <- function(id,
download_report_button_srv(
"download_button_simple",
reporter = reporter,
global_knitr = global_knitr,
rmd_output = rmd_output,
rmd_yaml_args = rmd_yaml_args
)
Expand Down
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,21 @@ split_text_block <- function(x, n) {
ind <- rep(1:nblocks, each = n)[seq_along(lines)]
unname(lapply(split(lines, ind), paste, collapse = "\n"))
}

#' Retrieve text details for global_knitr options
#' This function returns a character string describing the default settings for the global_knitr options.
#' @noRd
#'
#' @keywords internal
global_knitr_details <- function() {
paste0(
c(
" To access the default values for the `global_knitr` parameter,",
" use `getOption('teal.reporter.global_knitr')`. These defaults include:",
" - `echo = TRUE`",
" - `tidy.opts = list(width.cutoff = 60)`",
" - `tidy = TRUE` if `formatR` package is installed, `FALSE` otherwise"
),
collapse = "\n"
)
}
22 changes: 22 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.onLoad <- function(libname, pkgname) {
op <- options()
default_global_knitr <- list(teal.reporter.global_knitr = list(
echo = TRUE,
tidy.opts = list(width.cutoff = 60),
tidy = requireNamespace("formatR", quietly = TRUE)
))

if (!("teal.reporter.global_knitr" %in% names(op))) {
options(default_global_knitr)
}

invisible()
}

.onAttach <- function(libname, pkgname) {
packageStartupMessage(
if (!requireNamespace("formatR", quietly = TRUE)) {
"For better code formatting, consider installing the formatR package."
}
)
}
47 changes: 37 additions & 10 deletions man/Renderer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ReportCard.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/download_report_button_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/reporter_previewer_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading