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

Conversation

kartikeyakirar
Copy link
Contributor

@kartikeyakirar kartikeyakirar commented Sep 26, 2023

this Fixes #169

I've implemented a solution that relies on the formatR package. I've ensured that this solution checks for the package in the namespace; if it's not accessible, the user will be notified. To maintain flexibility, I've included the formatR package in the suggested dependencies, as there are no strict dependencies on it.

In response to the feedback provided by @m7pr in this comment, I've updated the default value of global_knitr to list(echo = TRUE, tidy.opts = list(width.cutoff = 60), tidy = FALSE).

Please note that there was an alternative option to set tidy = "styler", but I opted against it due to the additional dependency it would introduce (the styler package). Feel free to review the changes and let me know if any further adjustments are needed.


This branch utilizes the functionality provided by the 'formatR' package to automatically add spaces and indentations to the code. However, it does create a strong dependency on the 'formatR' package. If the package is not installed, the output will be generated without any formatting.

Additionally, this branch introduces the following changes:

  • It exposes Knitr options to users through the functions 'download_report_button_srv', 'reporter_previewer_srv,' 'simple_reporter_srv,' and the R6 renderer.
  • The Roxygen documentation has been updated to reflect these modifications.

changes in reports are observed as follows.

branch: main
image

branch: 169_wrap_rcode@main
image

@github-actions
Copy link
Contributor

github-actions bot commented Sep 26, 2023

badge

Code Coverage Summary

Filename              Stmts    Miss  Cover    Missing
------------------  -------  ------  -------  -----------------------------------------------------------------------------------
R/AddCardModule.R       144       2  98.61%   162, 199
R/Archiver.R             25       0  100.00%
R/ContentBlock.R         18       2  88.89%   38-44
R/DownloadModule.R      207      49  76.33%   95-101, 143, 168-173, 182-186, 189-193, 201-205, 208-212, 219-223, 226-230, 267-271
R/FileBlock.R            13       0  100.00%
R/NewpageBlock.R          2       0  100.00%
R/PictureBlock.R         30       2  93.33%   15, 79
R/Previewer.R           295      56  81.02%   188, 202, 204-207, 210, 213-221, 330-374
R/RcodeBlock.R           15       0  100.00%
R/Renderer.R            116      22  81.03%   63, 124, 132, 141, 143-164
R/ReportCard.R           77       4  94.81%   180, 219, 224, 245
R/Reporter.R             94       1  98.94%   254
R/ResetModule.R          55       0  100.00%
R/SimpleReporter.R       30       0  100.00%
R/TableBlock.R            9       0  100.00%
R/TextBlock.R            13       0  100.00%
R/utils.R               171      80  53.22%   7, 38-97, 99, 102-109, 163, 175-177, 287-296
R/yaml_utils.R           81       2  97.53%   41, 239
R/zzz.R                  14      10  28.57%   2-13, 19
TOTAL                  1409     230  83.68%

Diff against main

Filename              Stmts    Miss  Cover
------------------  -------  ------  --------
R/Renderer.R             +1       0  +0.16%
R/SimpleReporter.R       +1       0  +100.00%
R/utils.R               +10     +10  -3.31%
R/zzz.R                 +14     +10  +28.57%
TOTAL                   +26     +20  -1.14%

Results for commit: 71b6d8a

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented Sep 26, 2023

Unit Tests Summary

    1 files    18 suites   15s ⏱️
204 tests 204 ✔️ 0 💤 0
346 runs  346 ✔️ 0 💤 0

Results for commit 71b6d8a.

♻️ This comment has been updated with latest results.

@m7pr
Copy link
Contributor

m7pr commented Sep 27, 2023

@pawelru what are your thoughts on this? I know we had some conversation about packages being in Suggests and being checked on a code execution, but this is totally minor and I would accept this the way it is.

@m7pr m7pr requested a review from pawelru September 27, 2023 11:33
@kartikeyakirar kartikeyakirar requested a review from a team September 29, 2023 06:31
R/DownloadModule.R Outdated Show resolved Hide resolved
@kartikeyakirar kartikeyakirar marked this pull request as draft September 29, 2023 10:32
kartikeya and others added 4 commits September 29, 2023 16:02
@kartikeyakirar kartikeyakirar requested a review from m7pr September 29, 2023 13:01
@kartikeyakirar
Copy link
Contributor Author

I have set the default options for global_knitr list(echo = TRUE, tidy.opts = list(width.cutoff = 60), tidy = FALSE)
tidy.opts is set based on https://yihui.org/knitr/options/#chunk-options whereas tidy is FAlSE as default but will be changed to TRUE if formatR package is found in the namespace.

@kartikeyakirar kartikeyakirar marked this pull request as ready for review September 29, 2023 13:16
@kartikeyakirar
Copy link
Contributor Author

I found a better option. If we set tidy = 'formatR', then tidy.opts is not required to remove blank lines and cut the code lines at 60 characters. (making following changes)

@m7pr
Copy link
Contributor

m7pr commented Sep 29, 2023

@kartikeyakirar what if we create

options(teal.reporter.knit.global = list(echo = TRUE, tidy.opts = list(width.cutoff = 60), tidy = FALSE))

on a package startup, and then we reuse getOption('teal.reporter.knit.global') in defaults of functions usage? This way we have code that is repeated in many places, but specified once, and is easy to be edited in package, and also during an R sessionl

@m7pr
Copy link
Contributor

m7pr commented Sep 29, 2023

R/DownloadModule.R Outdated Show resolved Hide resolved
R/DownloadModule.R Outdated Show resolved Hide resolved
R/DownloadModule.R Outdated Show resolved Hide resolved
R/DownloadModule.R Outdated Show resolved Hide resolved
@m7pr
Copy link
Contributor

m7pr commented Oct 4, 2023

@kartikeyakirar please see my changes to one place where you provided those @details.
Can you make those @details a reusable template with @template? So that it is specified once, and not copy pasted in 4 places

R/zzz.R Outdated Show resolved Hide resolved
DESCRIPTION Outdated
@@ -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

kartikeyakirar and others added 6 commits October 4, 2023 15:02
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com>
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com>
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com>
Merge branch '169_wrap_rcode@main' of https://github.com/insightsengineering/teal.reporter into 169_wrap_rcode@main

# Conflicts:
#	man/download_report_button_srv.Rd
@kartikeyakirar
Copy link
Contributor Author

Can you make those @details a reusable template with @template?

@template is superseded instead I have defined the details in simpleReporter.R and reusing with inherit. thanks for suggestion.

@m7pr
Copy link
Contributor

m7pr commented Oct 4, 2023

@kartikeyakirar I wanted you to create roxygen template, not to inherit details.

Please subsitute @inherit simple_reporter_srv details with #' @template roxlate-knitr-details. Also put that in R/SimpleReporter.R instead of details.

Then create a file

man-roxygen/roxlate-knitr-details.R and put below in the content

#' @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 = TRUE`  if `formatR` package is installed, `FALSE` otherwise

@m7pr
Copy link
Contributor

m7pr commented Oct 4, 2023

@kartikeyakirar alrighty, they suggest

Instead of @template and @templateVars write your own function and call it from inline R code.

Can you follow https://rmarkdown.rstudio.com/lesson-4.html ?
Looks like you can use r global_details() which would produce the content of details

Copy link
Contributor

@m7pr m7pr left a comment

Choose a reason for hiding this comment

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

@kartikeyakirar looks good now. That was a long ride.
Would you be able to create a comment that proves that it works? The comparison of a behavior on main with this branch for the usage of all methods/functions that were changed?

@kartikeyakirar
Copy link
Contributor Author

kartikeyakirar commented Oct 4, 2023

The comparison of a behavior on main with this branch for the usage of all methods/functions that were changed?

thanks for review @m7pr , I have updated description for this.

@m7pr
Copy link
Contributor

m7pr commented Oct 4, 2023

coolio 👍

@kartikeyakirar kartikeyakirar merged commit 6a30a56 into main Oct 4, 2023
@kartikeyakirar kartikeyakirar deleted the 169_wrap_rcode@main branch October 4, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically wrap up the long code in the Report
4 participants