Skip to content

Simplification of environmental handling - #303

Merged
llrs-roche merged 20 commits into
mainfrom
272_valid_reproducible
Nov 18, 2026
Merged

llrs-roche merged 20 commits into
mainfrom
272_valid_reproducible

Conversation

@llrs-roche

@llrs-roche llrs-roche commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Pull Request

Fixes #272

Replaces the base environment to an "empty", only those packages loaded by default. These are found via a new helper default_env() added. Note that the private function is used also on tests, but I am not sure if there is any work around that avoids duplicating it.

Check out if .eval_code() should be amended too, it is the only place where if I replace it something starts to fail, but I don't understand the evaluate framework enough to know if this is a mistake or not.

Also check the tests added. They should be skipped online but run locally. Checking with R CMD check --as-cran locally didn't trigger any Note about undeclared package.

Last not not least. This might create havoc across modules and apps, if we forgot to add a dependency inside qenv, once this is merged it will reveal itself.

To verify the fix run these lines that the last one should fail:

library("teal.code")
library("teal.modules.clinical")
within(qenv(), {ADSL <- tmc_ex_adsl})

In relation to #201, we might want to change some environment to the environment of the object before the evaluation.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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                  63       1  98.41%   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                    13       1  92.31%   13
R/qenv-get_warnings.R                5       0  100.00%
R/qenv-join.R                        1       1  0.00%    13
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      258       3  98.84%   160, 258, 326
R/utils.R                           55       1  98.18%   108
TOTAL                              582      42  92.78%

Diff against main

Filename      Stmts    Miss  Cover
----------  -------  ------  -------
R/utils.R       +13      +1  -1.82%
TOTAL           +13      +1  -0.01%

Results for commit: 8ce829c

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
qenv_constructor 👶 $+0.04$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_but_doesn_t_mess_up_with_library_calls_inside_qenv
qenv_constructor 👶 $+0.03$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_cannot_get_variable_after_subsetting
qenv_constructor 👶 $+0.01$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_does_not_change_the_original_environment_when_used_to_create
qenv_constructor 👶 $+0.03$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_does_not_get_variables_from_current_environment
qenv_constructor 👶 $+0.02$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_does_not_get_variables_from_global_environment
qenv_constructor 👶 $+0.03$ parent_of_qenv_environment_is_the_parent_of_.GlobalEnv_with_the_right_environment

Results for commit a6eaa5f

♻️ This comment has been updated with latest results.

@averissimo averissimo self-assigned this Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files   14 suites   7s ⏱️
205 tests 201 ✅ 4 💤 0 ❌
303 runs  299 ✅ 4 💤 0 ❌

Results for commit 62c0e18.

♻️ This comment has been updated with latest results.

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left a comment thread so we can discuss this

Comment thread R/qenv-eval_code.R Resolved
Comment thread R/qenv-c.R Resolved
Comment thread tests/testthat/test-qenv_constructor.R Resolved
Comment thread R/qenv-class.R Resolved
@llrs-roche llrs-roche changed the title Qenv use default environment not global environment Simplification of environmental handling Nov 17, 2026
@llrs-roche
llrs-roche enabled auto-merge (squash) November 17, 2026 10:49

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Last round of comments as I think we need to revert to use parent of (now) default_env

I recommend adding a few more tests to protect the package against the initial design principles and what we learned here

Comment thread R/qenv-class.R Resolved
Comment thread R/qenv-eval_code.R Resolved
Comment thread R/qenv-extract.R Resolved
Comment thread R/qenv-extract.R Resolved
Comment thread tests/testthat/test-qenv_constructor.R Resolved

@averissimo averissimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome! We couldn't deal with the issue, but this PR makes the package more robust

@llrs-roche
llrs-roche merged commit 95b1679 into main Nov 18, 2026
24 checks passed
@llrs-roche
llrs-roche deleted the 272_valid_reproducible branch November 18, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: qenv is valid but code is not reproducible

2 participants