Skip to content

{teal} module returns a teal_report object that extends from teal_data #331

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

Open
wants to merge 196 commits into
base: main
Choose a base branch
from

Conversation

averissimo
Copy link
Contributor

@averissimo averissimo commented Jun 3, 2025

Pull Request

Fixes:

Built on top of:

Companion PRs:

Changes description

  • Adds new object called teal_report that extends teal_data
    • The card/report for a module is built automatically with eval_code() and eval_code(cache = TRUE)
      • (adding code and print objects respectively)
    • Report slot can be manipulated with report(<teal_report>)
  • Rename of report_document to doc/document/page (final name TBD)

vedhav and others added 30 commits October 4, 2024 22:48
Signed-off-by: Marcin <[email protected]>
Signed-off-by: Marcin <[email protected]>
Signed-off-by: Marcin <[email protected]>
@averissimo averissimo marked this pull request as ready for review June 5, 2025 13:10
Copy link
Contributor

github-actions bot commented Jun 5, 2025

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  -----------------------------------------------------
R/AddCardModule.R              143       3  97.90%   158, 196, 203
R/ContentBlock.R                15       2  86.67%   43-49
R/DownloadModule.R             196      11  94.39%   133, 141, 173-174, 179, 234-238, 258
R/Editor.R                     168     168  0.00%    4-269
R/FileBlock.R                   13       0  100.00%
R/HTMLBlock.R                    9       0  100.00%
R/LoadReporterModule.R          98      19  80.61%   95-100, 103-108, 114-119, 131
R/NewpageBlock.R                 2       0  100.00%
R/PictureBlock.R                30       2  93.33%   20, 118
R/Previewer.R                  154      61  60.39%   106-108, 111-112, 129, 156-165, 169-181, 185, 191-230
R/RcodeBlock.R                  18       0  100.00%
R/ReportCard.R                  90       4  95.56%   189, 258, 263, 289
R/Reporter.R                   146      13  91.10%   56, 138-139, 168, 234, 360-365, 440-441
R/ResetModule.R                 54       0  100.00%
R/SimpleReporter.R              27       0  100.00%
R/TableBlock.R                   9       0  100.00%
R/teal_card.R                   65      16  75.38%   53, 64-85, 139-143, 175, 262-263
R/teal_report-class.R           28      28  0.00%    50-111
R/teal_report-eval_code.R       13      13  0.00%    6-20
R/teal_report-extract.R          3       3  0.00%    3-5
R/TextBlock.R                   15       0  100.00%
R/to_rmd.R                     123      62  49.59%   54, 68, 77-92, 124, 126-175, 201-217
R/toHTML.R                      39      39  0.00%    8-127
R/utils.R                       84      49  41.67%   26-57, 85, 109-117, 154-163
R/yaml_utils.R                  81       2  97.53%   78, 289
R/zzz.R                         16      15  6.25%    2-19, 24-26
TOTAL                         1639     510  68.88%

Diff against main

Filename                     Stmts    Miss  Cover
-------------------------  -------  ------  --------
R/AddCardModule.R               -4      +1  -0.74%
R/DownloadModule.R             -43     -56  +22.42%
R/Editor.R                    +168    +168  +100.00%
R/LoadReporterModule.R          -6       0  -1.12%
R/Previewer.R                 -215     -36  -13.32%
R/ReportCard.R                  +4      +1  -0.96%
R/Reporter.R                   +39      +7  -3.30%
R/SimpleReporter.R              -5       0  +100.00%
R/teal_card.R                  +65     +16  +75.38%
R/teal_report-class.R          +28     +28  +100.00%
R/teal_report-eval_code.R      +13     +13  +100.00%
R/teal_report-extract.R         +3      +3  +100.00%
R/to_rmd.R                    +123     +62  +49.59%
R/toHTML.R                     +39     +39  +100.00%
R/utils.R                      -42     -37  +9.92%
R/zzz.R                         +3      +3  -1.44%
TOTAL                         +170    +212  -10.05%

Results for commit: 6d38378

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Jun 5, 2025

Unit Tests Summary

  1 files   20 suites   38s ⏱️
215 tests 211 ✅ 4 💤 0 ❌
395 runs  391 ✅ 4 💤 0 ❌

Results for commit b791939.

Copy link
Contributor

github-actions bot commented Jun 5, 2025

Unit Tests Summary

  1 files   20 suites   37s ⏱️
214 tests 210 ✅ 4 💤 0 ❌
390 runs  386 ✅ 4 💤 0 ❌

Results for commit b7c4623.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jun 5, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
PreviewerReportModule 💚 $1.84$ $-1.52$ $-6$ $0$ $0$ $0$
PreviewerReportModule-shinytest2 👶 $+0.08$ $+4$ $+4$ $0$ $0$
Renderer 💀 $2.73$ $-2.73$ $-5$ $0$ $0$ $0$
Reporter 💔 $2.57$ $+6.30$ $+4$ $0$ $0$ $0$
SimpleReporter 💔 $0.71$ $+4.71$ $+1$ $0$ $0$ $0$
card 👶 $+0.14$ $+50$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
LoadReporterModule 👶 $+0.14$ report_load_srv_loading_reporter_with_ReportCard_restores_saved_content_with_old_blocks_
PreviewerReportModule-shinytest2 👶 $+0.03$ reporter_previewer_card_editing_works
PreviewerReportModule-shinytest2 👶 $+0.03$ reporter_previewer_card_removal_works
PreviewerReportModule-shinytest2 👶 $+0.01$ reporter_previewer_card_reordering_works
PreviewerReportModule-shinytest2 👶 $+0.02$ reporter_previewer_download_functionality_works
PreviewerReportModule 💀 $0.17$ $-0.17$ reporter_previewer_srv_card_down
PreviewerReportModule 💀 $0.17$ $-0.17$ reporter_previewer_srv_card_up
PreviewerReportModule 💀 $0.32$ $-0.32$ reporter_previewer_srv_card_up_and_down_compensate
PreviewerReportModule 👶 $+0.05$ reporter_previewer_srv_previewer_buttons_parameter
PreviewerReportModule 💀 $0.25$ $-0.25$ reporter_previewer_srv_remove_a_card
PreviewerReportModule 💀 $0.49$ $-0.49$ reporter_previewer_srv_render_and_downlaod_a_document
PreviewerReportModule 💀 $0.31$ $-0.31$ reporter_previewer_srv_up_with_first_card_and_down_with_last_card_does_not_induce_change
PreviewerReportModule 👶 $+0.06$ reporter_previewer_ui_returns_a_shiny_tag_list
PreviewerReportModule 💀 $0.01$ $-0.01$ reporter_previewer_ui_returns_a_tagList
Renderer 💀 $0.01$ $-0.01$ Renderer_object_can_be_created
Renderer 💀 $0.00$ $-0.00$ new_returns_an_object_of_type_Renderer
Renderer 💀 $2.23$ $-2.23$ renderRmd_asserts_the_argument_is_a_list_of_TextBlocks_PictureBlock_NewpageBlock_TableBlock
Renderer 💀 $0.49$ $-0.49$ render_returns_the_same_path_as_get_last_output_file
Reporter 👶 $+0.06$ Reporter_with_ReportCard_The_deep_copy_constructor_copies_the_content_files_to_new_files
Reporter 👶 $+2.00$ Reporter_with_ReportCard_get_blocks_by_default_adds_NewpageBlock_new_between_cards
Reporter 👶 $+2.05$ Reporter_with_ReportCard_get_blocks_returns_the_same_blocks_which_was_added_to_reporter_sep_NULL
Reporter 👶 $+1.98$ Reporter_with_ReportCard_get_cards_returns_the_same_cards_which_was_added_to_reporter
Reporter 💀 $0.01$ $-0.01$ append_metadata_accept_only_named_list
Reporter 💀 $0.01$ $-0.01$ append_metadata_accept_only_unique_names_which_could_not_be_repeated
Reporter 💚 $2.31$ $-2.31$ default_reporter_id
Reporter 💀 $0.00$ $-0.00$ from_jsondir_returns_identical_equal_object
Reporter 💀 $0.01$ $-0.01$ from_reporter_does_not_return_identical_equal_object_form_other_reporter
Reporter 👶 $+0.09$ from_reporter_from_reporter_does_not_return_identical_equal_object_form_other_reporter
Reporter 👶 $+0.09$ from_reporter_from_reporter_persists_the_cards_structure
Reporter 👶 $+0.11$ from_reporter_from_reporter_persists_the_cards_structure_but_not_the_name
Reporter 👶 $+0.05$ from_reporter_from_reporter_returns_identical_equal_object_from_the_same_reporter
Reporter 💀 $0.01$ $-0.01$ from_reporter_persists_the_cards_structure
Reporter 💀 $0.01$ $-0.01$ from_reporter_persists_the_reactive_add_card_count
Reporter 👶 $+0.11$ from_reporter_returns_different_object_if_id_has_already_been_set
Reporter 💀 $0.01$ $-0.01$ from_reporter_returns_identical_equal_object_from_the_same_reporter
Reporter 👶 $+0.09$ from_reporter_returns_same_object_from_the_same_reporter
Reporter 💀 $0.01$ $-0.01$ get_metadata
Reporter 👶 $+0.01$ metadata_append_metadata_accept_only_named_list
Reporter 👶 $+0.02$ metadata_append_metadata_accept_only_unique_names_which_could_not_be_repeated
Reporter 👶 $+0.01$ metadata_get_metadata
Reporter 💀 $0.01$ $-0.01$ reactive_add_card
Reporter 👶 $+0.01$ reorder_cards_returns_the_correct_order
Reporter 👶 $+0.01$ reorder_cards_returns_the_correct_order_after_adding_new_card_at_the_end_
Reporter 👶 $+0.01$ reorder_cards_returns_the_correct_order_after_removal
Reporter 💀 $0.02$ $-0.02$ swap_cards
Reporter 💀 $0.02$ $-0.02$ to_jsondir_and_from_jsondir_could_be_used_to_save_and_retrive_a_Reporter
Reporter 👶 $+0.16$ to_jsondir_from_jsondir_returns_identical_equal_object
Reporter 💀 $0.01$ $-0.01$ to_jsondir_require_the_existing_directory_path
Reporter 💀 $0.00$ $-0.00$ to_jsondir_returns_the_same_dir_it_was_provided_to_it
Reporter 👶 $+0.17$ to_jsondir_to_jsondir_and_from_jsondir_could_be_used_to_save_and_retrive_a_Reporter
Reporter 👶 $+0.06$ to_jsondir_to_jsondir_require_the_existing_directory_path
Reporter 👶 $+0.10$ to_jsondir_to_jsondir_returns_the_same_dir_it_was_provided_to_it
Reporter 💀 $0.02$ $-0.02$ to_list_and_from_list_could_be_used_to_save_and_retrive_a_Reporter_
Reporter 👶 $+0.16$ to_list_to_list_and_from_list_could_be_used_to_save_and_retrieve_a_Reporter_blocks
Reporter 👶 $+0.28$ to_list_to_list_and_from_list_could_be_used_to_save_and_retrieve_a_Reporter_card
SimpleReporter 👶 $+0.27$ simple_reporter_srv_add_a_Card_ReportCard_to_Reporter
SimpleReporter 👶 $+0.10$ simple_reporter_srv_add_a_Card_teal_card_to_Reporter
SimpleReporter 💀 $0.28$ $-0.28$ simple_reporter_srv_add_a_Card_to_Reporter
SimpleReporter 💔 $0.41$ $+4.63$ simple_reporter_srv_render_and_downlaod_a_document
card 👶 $+0.02$ _.card_subsets_and_retains_class
card 👶 $+0.01$ c.card_combines_with_NULL_and_retains_class
card 👶 $+0.01$ c.card_combines_with_card_with_multiple_elements_and_retains_class
card 👶 $+0.01$ c.card_combines_with_character_and_retains_class
card 👶 $+0.01$ c.card_combines_with_ggplot_and_retains_class
card 👶 $+0.01$ c.card_combines_with_ggplot_with_title_and_retains_class
card 👶 $+0.01$ c.card_combines_with_list_and_retains_class
card 👶 $+0.01$ card_creates_a_document_with_initial_elements
card 👶 $+0.01$ card_creates_an_empty_document
card 👶 $+0.02$ edit_card_appends_elements
card 👶 $+0.02$ edit_card_modifies_and_appends
card 👶 $+0.01$ edit_card_modifies_elements
card 👶 $+0.01$ edit_card_preserves_attributes
utils 💀 $0.01$ $-0.01$ get_bs_version

Results for commit f2b6b10

♻️ This comment has been updated with latest results.

averissimo and others added 15 commits June 5, 2025 15:38
Changed names

- `teal_reporter@report` ->  `teal_reporter@teal_card`
- `teal.reporter::doc()` ->  `teal.reporter::teal_card()`
- `teal.reporter::report()` ->  `teal.reporter::teal_card()`

So now you can use

```r
data <- teal.reporter::teal_report()  # teal_report() class
data@teal_card                        # teal_card class
teal.reporter::teal_card(data)        # teal_card class
```

Also `teal_card` is the creator, the getter and the setter

```r
data <- teal.reporter::teal_report()
teal_card(data) <- teal_card()       # setter + creator
teal_card(data)                      # getter
data@teal_card                       # direct slot access
```

Companion to:
- insightsengineering/teal#1542
- insightsengineering/teal.modules.general#885
- insightsengineering/teal.code#256

---------

Signed-off-by: Marcin <[email protected]>
Signed-off-by: André Veríssimo <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
#' @examples
#' # Create a new empty card
#' report <- teal_card()
#' class(report) # Check the class of the object
Copy link
Contributor

Choose a reason for hiding this comment

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

Class names are rather internal names. Let's remove it from user-facing docs

Suggested change
#' class(report) # Check the class of the object

#' It enables users to create, manipulate, and serialize report-related data efficiently.
#'
#' The `teal_card()` function serves two purposes:
#' 1. When called with a `teal_report` object, it acts as a getter and returns the card slot
Copy link
Contributor

Choose a reason for hiding this comment

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

not only with a teal_report object but that object must be a first argument

Comment on lines +8 to +10
#' The `teal_card()` function serves two purposes:
#' 1. When called with a `teal_report` object, it acts as a getter and returns the card slot
#' 2. When called with other arguments, it creates a new `teal_card` object from those arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

this adds ambiguity. can we keep it as a constructor only?

Comment on lines +13 to +18
# Manual import instead of using backports and adding 1 more dependency
if (getRversion() < "4.4") {
`%||%` <- function(x, y) if (is.null(x)) y else x
assign("`%||%`", `%||%`, envir = getNamespace(pkgname))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we already import rlang - let's take it from there instead of rewriting

Copy link
Contributor

Choose a reason for hiding this comment

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

  • what's our strategy for eval_code? I thought we are discouraging the usage of this and here I can see the opposite
  • (related to above) do we plan to have the same for within?

#' These objects are typically processed later to generate the final R Markdown text.
#'
#' @param code A character string containing the R code.
#' @param ... Additional named parameters to be included as chunk options (e.g., `echo = TRUE`).
Copy link
Contributor

Choose a reason for hiding this comment

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

  • please expand on the documentation that these parameters are further used in the markdown code chunks - is it this? https://yihui.org/knitr/options/
  • add assert that the list must be named

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.

5 participants