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 35 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
)
1 change: 1 addition & 0 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @kartikeyakirar can you run verdepcheck flow to determine the minimal needed version of this package?
verdepcheck

ggplot2 (>= 3.4.0),
lattice (>= 0.18-4),
png,
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
14 changes: 12 additions & 2 deletions R/DownloadModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ 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 To access the default values for the `global_knitr` parameter,
#' use `getOption("teal.reporter.global_knitr")`.These defaults include:
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
#' - `echo`: `TRUE`
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' - `tidy.opts`: `list(width.cutoff = 60)`
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' - `tidy`: This option is automatically set to `TRUE` if the `formatR` package is present in the namespace;
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
#' otherwise, it is set to `FALSE`.
#'
#' @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 +58,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 +145,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
13 changes: 11 additions & 2 deletions R/Previewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ 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 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`: This option is automatically set to `TRUE` if the `formatR` package is present in the namespace;
#' otherwise, it is set to `FALSE`.
#' @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 +54,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 +189,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
32 changes: 22 additions & 10 deletions R/Renderer.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ 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 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`: This option is automatically set to `TRUE` if the `formatR` package is present in the namespace;
#' otherwise, it is set to `FALSE`.
#'
#' @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 +91,18 @@ 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 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`: This option is automatically set to `TRUE` if the `formatR` package is present in the namespace;
#' otherwise, it is set to `FALSE`.
#'
#' @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
10 changes: 10 additions & 0 deletions R/SimpleReporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ 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 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`: This option is automatically set to `TRUE` if the `formatR` package is present in the namespace;
#' otherwise, it is set to `FALSE`.
#'
#' @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 +77,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
23 changes: 23 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.onLoad <- function(libname, pkgname) {
# adapted from https://r-pkgs.org/code.html#sec-code-onLoad-onAttach
kartikeyakirar marked this conversation as resolved.
Show resolved Hide resolved
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."
}
)
}
49 changes: 39 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.

14 changes: 14 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.

14 changes: 14 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
Loading