Skip to content

Use evaluate #258

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 14 commits into
base: main
Choose a base branch
from
Open

Use evaluate #258

wants to merge 14 commits into from

Conversation

gogonzo
Copy link
Contributor

@gogonzo gogonzo commented Jun 19, 2025

eval_code caches now outputs of the code in the attr(<code line>, "outputs"). See the tests of get_outputs to see how it works.

@gogonzo gogonzo added the core label Jun 19, 2025
Copy link
Contributor

github-actions bot commented Jun 19, 2025

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  ---------
R/qenv-c.R                          55       0  100.00%
R/qenv-class.R                      13       0  100.00%
R/qenv-concat.R                      7       0  100.00%
R/qenv-constructor.R                 1       0  100.00%
R/qenv-errors.R                      4       4  0.00%    6-9
R/qenv-eval_code.R                  60       1  98.33%   40
R/qenv-extract.R                    30       0  100.00%
R/qenv-get_code.R                   24       0  100.00%
R/qenv-get_env.R                     3       1  66.67%   27
R/qenv-get_messages.r                5       0  100.00%
R/qenv-get_outputs.R                 6       0  100.00%
R/qenv-get_var.R                    26       0  100.00%
R/qenv-get_warnings.R                5       0  100.00%
R/qenv-join.R                        7       7  0.00%    137-151
R/qenv-length.R                      2       1  50.00%   2
R/qenv-show.R                       29      29  0.00%    19-50
R/qenv-within.R                      8       0  100.00%
R/utils-get_code_dependency.R      247       2  99.19%   160, 258
R/utils.R                           42       0  100.00%
TOTAL                              574      45  92.16%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  --------
R/qenv-class.R                      +1       0  +100.00%
R/qenv-eval_code.R                  -2       0  -0.05%
R/qenv-get_outputs.R                +6       0  +100.00%
R/utils-get_code_dependency.R       +2       0  +0.01%
R/utils.R                          +12       0  +100.00%
TOTAL                              +19       0  +0.27%

Results for commit: d17b8df

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Jun 19, 2025

Unit Tests Summary

  1 files   14 suites   5s ⏱️
170 tests 167 ✅ 3 💤 0 ❌
260 runs  257 ✅ 3 💤 0 ❌

Results for commit d17b8df.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jun 19, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
get_outputs 👶 $+0.51$ $+16$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
get_outputs 👶 $+0.05$ explicitly_printed_object_uses_newly_registered_print_method_and_returned_as_console_output_string
get_outputs 👶 $+0.04$ explicitly_printed_objects_are_returned_as_console_output_string_in_a_list
get_outputs 👶 $+0.04$ get_output_implicitly_printed_S4_object_is_returned_asis_in_a_list_and_identical_to_the_one_in_the_environment
get_outputs 👶 $+0.05$ implicitly_printed_list_is_returned_asis_even_if_its_print_is_overridden
get_outputs 👶 $+0.09$ implicitly_printed_objects_are_returned_asis_in_a_list_and_are_identical_to_ones_in_the_environment
get_outputs 👶 $+0.03$ intermediate_plots_are_not_kept
get_outputs 👶 $+0.01$ messages_are_returned_asis_in_a_list
get_outputs 👶 $+0.03$ printed_plots_are_returned_as_recordedplot_in_a_list_1_
get_outputs 👶 $+0.03$ printed_plots_are_returned_as_recordedplot_in_a_list_2_
get_outputs 👶 $+0.02$ prints_inside_for_are_bundled_together
get_outputs 👶 $+0.12$ returns_an_empty_list_if_nothing_is_printed
get_outputs 👶 $+0.02$ warnings_are_returned_asis_in_a_list
qenv_eval_code 💀 $0.02$ $-0.02$ alone_comments_at_the_end_of_the_source_are_considered_as_continuation_of_the_last_call
qenv_eval_code 💀 $0.02$ $-0.02$ comments_alone_are_pasted_to_the_next_following_call_element
qenv_eval_code 💀 $0.01$ $-0.01$ comments_at_the_end_of_src_are_added_to_the_previous_call_element
qenv_eval_code 👶 $+0.01$ object_printed_explicitly_is_stored_as_string_in_the_outputs_attribute_of_a_code_element
qenv_eval_code 👶 $+0.02$ object_printed_implicitly_is_stored_asis_in_the_outputs_attribute_of_a_code_element
qenv_eval_code 👶 $+0.03$ plot_cannot_modified_previous_plots_when_calls_are_seperate
qenv_eval_code 👶 $+0.02$ plot_output_is_stored_as_recordedplot_in_the_outputs_attribute_of_a_code_element

Results for commit b53f9e1

♻️ This comment has been updated with latest results.

- mask environment for qenv
- remove semicolon from the code
averissimo and others added 7 commits June 25, 2025 10:39
@gogonzo This might be a better solution that keeps the override under
`evaluate()`, while avoiding changing who the `parent.env` is.

That is, we don't need to check the "`grand.parent.env()`"
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Dawid Kałędkowski <[email protected]>
- make sure get_output is returning the same reference
- check addition of print.class
…d function (#261)

### Changes description

- Remove intermediate plots by default
- Avoids deprecated function in testthat 3rd edition
- Adds some tests
  - Q: Does the S4 test make sense?
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

💯

Fantastic new feature to qenv()!

Left one last comment about adding the information to vignettes

@@ -1,11 +1,16 @@
# teal.code 0.6.1.9003

### Enhancements

* Introduced `get_outputs` function to fetch objects which have been printed or plotted in the `qenv` code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a small section on the vignette as well? in addition to "### Warnings and messages in qenv objects"

diff --git a/vignettes/qenv.Rmd b/vignettes/qenv.Rmd
index 4859e32c..302b6846 100644
--- a/vignettes/qenv.Rmd
+++ b/vignettes/qenv.Rmd
@@ -126,7 +126,7 @@ The feasibility of joining `qenv` objects hinges on the contents of the environm
 
 ### Warnings and messages in `qenv` objects
 
-In cases where warnings or messages arise while evaluating code within a `qenv` environment, these are captured and stored within the `qenv` object. Access these messages and warnings using below
+In cases where warnings or messages arise while evaluating code within a `qenv` environment, these are captured and stored within the `qenv` object. Access these messages and warnings using `get_messages()` and `get_warnings()` functions as shown below.
 
 ```{r}
 q_message <- eval_code(qenv(), quote(message("this is a message")))
@@ -138,6 +138,15 @@ get_warnings(q_warning)
 
 If any of above returns `NULL`m then no warnings nor messages were present.
 
+### Outputs in `qenv` objects
+
+When evaluating code in a `qenv`, the outputs are captured and stored in a list. This includes printed objects, plots, warnings, and messages. You can retrieve these outputs using the `get_outputs()` function.
+
+```{r}
+q_output <- eval_code(qenv(), quote(plot(1:10)))
+get_outputs(q_output)
+```
+
 ## Utilizing `qenv` inside `shiny` applications
 
 These functions can be seamlessly integrated into `shiny` applications to produce reproducible outputs. In the example below, the `rcode` section showcases the code employed for generating the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've included some info about get_outputs(). Please have a look once again before I merge

gogonzo added a commit to insightsengineering/teal.reporter that referenced this pull request Jun 26, 2025
Followup to insightsengineering/teal.code#258

- eval_code adds `attr(code, "outputs")` to the `teal_card` but skips
the warnings and messages (conditions).
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.

2 participants