insightsengineering / teal.code

Code storage and execution class for teal applications
https://insightsengineering.github.io/teal.code/
Other
11 stars 7 forks source link

210 bring `get_code_dependency` #214

Closed m7pr closed 3 weeks ago

m7pr commented 4 weeks ago

BLOCKED by

Closes

Companion to

Description

Brings names parameter to get_code so that you can limit returned code to specific objects (and the lines that create those objects). get_code_dependency was moved from teal.data

Tested with

library(teal.code)

# EVAL CODE
q <- qenv()
q <- eval_code(q, code = c("a <- 1", "b <- 2"))
q@code
#> [1] "a <- 1\nb <- 2"
get_code(q, names = "a")
#> [1] "a <- 1"

# WITHIN
q <- qenv()
q <- within(q, {a <- 1; b <- 2})
q@code
#> [1] "a <- 1\nb <- 2"
get_code(q, names = "a")
#> [1] "a <- 1"

# OLD TEAL.DATA
t <- teal.data::teal_data(a = 5, code = c("a <- 1", "b <- 2"))
t@code
#> [1] "a <- 1\nb <- 2"
teal.data::get_code(t, datanames = 'a')
#> Warning in .local(object, deparse, ...): get_code(datanames) was deprecated in
#> teal.data 0.6.1, use get_code(names) instead.
#> [1] "a <- 1"

Created on 2024-10-16 with reprex v2.1.1

Local tests

> devtools::test()
ℹ Testing teal.code
✔ | F W  S  OK | Context
✔ |         12 | qenv_concat                                                 
✔ |          8 | qenv_constructor                                            
✔ |         26 | qenv_eval_code                                              
✔ |      2  60 | qenv_get_code [1.1s]                                        
✔ |         10 | qenv_get_var                                                
✔ |          7 | qenv_get_warnings                                           
✔ |         40 | qenv_join                                                   
✔ |         14 | qenv_within                                                 
✔ |         12 | utils                                                       

══ Results ══════════════════════════════════════════════════════════════════
Duration: 2.2 s

── Skipped tests (2) ────────────────────────────────────────────────────────
• This is not urgent and can be ommitted with @linksto tag. (1):
  test-qenv_get_code.R:526:3
• We will not resolve this, as this requires code evaluation. (1):
  test-qenv_get_code.R:318:3

[ FAIL 0 | WARN 0 | SKIP 2 | PASS 189 ]

Local R CMD CHECK

── R CMD check results ──────────────────────────────────── teal.code 0.5.0.9010 ────
Duration: 33.5s

❯ checking for future file timestamps ... NOTE
  unable to verify current time

0 errors ✔ | 0 warnings ✔ | 1 note ✖

R CMD check succeeded
github-actions[bot] commented 3 weeks ago

Unit Tests Summary

  1 files    9 suites   1s :stopwatch: 109 tests 107 :white_check_mark: 2 :zzz: 0 :x: 198 runs  196 :white_check_mark: 2 :zzz: 0 :x:

Results for commit ea337f18.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 3 weeks ago

Unit Test Performance Difference

Additional test case details | Test Suite | $Status$ | Time on `main` | $±Time$ | Test Case | |:-----|:----:|:----:|:----:|:-----| | qenv_get_code | 👶 | | $+0.01$ | _linksto_gets_extracted_if_it_s_a_side_effect_on_a_dependent_object_even_of_a_dependent_object_ | | qenv_get_code | 👶 | | $+0.01$ | _linksto_makes_a_line_being_returned_for_an_affected_binding | | qenv_get_code | 👶 | | $+0.01$ | _linksto_returns_the_line_for_an_affected_binding_even_if_the_object_did_not_exist_in_the_same_iteration_of_eval_code | | qenv_get_code | 👶 | | $+0.02$ | code_can_be_retrieved_with_get_code | | qenv_get_code | 👶 | | $+0.01$ | data_call_is_returned_when_data_name_is_provided_as_a_character | | qenv_get_code | 👶 | | $+0.03$ | data_call_is_returned_when_data_name_is_provided_as_is | | qenv_get_code | 👶 | | $+0.01$ | detects_cooccurrence_properly_even_if_all_objects_are_on_lhs | | qenv_get_code | 👶 | | $+0.01$ | detects_every_assign_calls_even_if_not_evaluated_if_there_is_only_one_assignment_in_this_line | | qenv_get_code | 👶 | | $+0.01$ | detects_function_usage_of_the_assignment_operator | | qenv_get_code | 👶 | | $+0.01$ | detects_occurrence_of_a_function_definition_when_a_formal_is_named_the_same_as_a_function | | qenv_get_code | 👶 | | $+0.01$ | detects_occurrence_of_a_function_definition_with_a_linksto_usage | | qenv_get_code | 👶 | | $+0.01$ | detects_occurrence_of_the_function_object | | qenv_get_code | 👶 | | $+0.01$ | does_not_break_if_code_is_separated_by_ | | qenv_get_code | 👶 | | $+0.01$ | does_not_break_if_code_uses_quote_ | | qenv_get_code | 👶 | | $+0.02$ | does_not_break_if_object_is_used_in_a_function_on_lhs | | qenv_get_code | 👶 | | $+0.01$ | does_not_break_if_object_is_used_in_a_function_on_lhs_and_influencers_are_both_on_lhs_and_rhs | | qenv_get_code | 👶 | | $+0.03$ | does_not_fall_into_a_loop | | qenv_get_code | 👶 | | $+0.00$ | does_not_ignore_occurrence_in_function_body_if_object_exsits_in_env | | qenv_get_code | 👶 | | $+0.01$ | extracts_code_of_a_parent_binding_but_only_those_evaluated_before_coocurence | | qenv_get_code | 👶 | | $+0.05$ | extracts_the_code_for_assign_where_x_is_a_literal_string | | qenv_get_code | 👶 | | $+0.00$ | extracts_the_code_for_assign_where_x_is_variable | | qenv_get_code | 👶 | | $+0.01$ | extracts_the_code_of_a_binding_from_character_vector_containing_simple_code | | qenv_get_code | 👶 | | $+0.01$ | extracts_the_code_of_a_parent_binding_if_used_as_an_arg_in_a_function_call | | qenv_get_code | 👶 | | $+0.01$ | extracts_the_code_when_using_ | | qenv_get_code | 👶 | | $+0.01$ | extracts_the_code_without_downstream_usage | | qenv_get_code | 👶 | | $+0.01$ | get_code_does_not_break_if_linksto_is_put_in_the_last_line | | qenv_get_code | 👶 | | $+0.00$ | handles_empty_code_slot | | qenv_get_code | 👶 | | $+0.01$ | handles_the_code_included_in_curly_brackets | | qenv_get_code | 👶 | | $+0.01$ | handles_the_code_of_length_1_when_at_least_one_is_enclosed_in_curly_brackets | | qenv_get_code | 👶 | | $+0.01$ | handles_the_code_without_symbols_on_rhs | | qenv_get_code | 👶 | | $+0.02$ | ignores_occurrence_in_a_function_definition | | qenv_get_code | 👶 | | $+0.04$ | ignores_occurrence_in_a_function_definition_if_there_is_multiple_function_definitions | | qenv_get_code | 👶 | | $+0.02$ | ignores_occurrence_in_a_function_definition_in_lapply | | qenv_get_code | 👶 | | $+0.02$ | ignores_occurrence_in_a_function_definition_that_has_function_in_it | | qenv_get_code | 👶 | | $+0.04$ | ignores_occurrence_in_function_definition_without_curly_brackets | | qenv_get_code | 👶 | | $+0.10$ | library_and_require_are_always_returned | | qenv_get_code | 👶 | | $+0.02$ | lines_affecting_parent_evaluated_after_co_occurrence_are_not_included_in_output_when_using_linksto | | qenv_get_code | 👶 | | $+0.01$ | returns_result_of_length_1_for_non_empty_input | | qenv_get_code | 👶 | | $+0.01$ | starting_with_underscore_is_detected_in_code_dependency | | qenv_get_code | 👶 | | $+0.08$ | understands_usage_and_do_not_treat_rhs_of_as_objects_only_lhs_ | | qenv_get_code | 👶 | | $+0.01$ | warns_if_binding_doesn_t_exist_in_code | | qenv_get_code | 👶 | | $+0.01$ | with_non_native_pipe_is_detected_code_dependency | | qenv_get_code | 👶 | | $+0.01$ | with_non_native_pipe_used_as_function_is_detected_code_dependency | | qenv_get_code | 👶 | | $+0.01$ | with_space_character_is_detected_in_code_dependency | | qenv_get_code | 👶 | | $+0.01$ | without_special_characters_is_cleaned_and_detected_in_code_dependency | | qenv_get_code | 👶 | | $+0.04$ | works_for_assign_detection_no_matter_how_many_parametrers_were_provided_in_assignq_ | | qenv_get_code | 👶 | | $+0.01$ | works_for_datanames_of_length_1 |

Results for commit 12097b692cc5923772d50cdf256908c24b3d2c28

♻️ This comment has been updated with latest results.

m7pr commented 3 weeks ago

I see such error in R CMD CHECKS on github actions on this PR

Error: there is no package called 'random.cdisc.data' 
github-actions[bot] commented 3 weeks ago

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  ---------
R/qenv-concat.R                     10       0  100.00%
R/qenv-constructor.R                16      13  18.75%   54-93
R/qenv-eval_code.R                  52       2  96.15%   100, 109
R/qenv-get_code.R                   28       0  100.00%
R/qenv-get_env.R                     3       3  0.00%    23-31
R/qenv-get_var.R                    19       0  100.00%
R/qenv-get_warnings.R               24       0  100.00%
R/qenv-join.R                       46       0  100.00%
R/qenv-show.R                        1       1  0.00%    19
R/qenv-within.R                      8       0  100.00%
R/utils-get_code_dependency.R      191       1  99.48%   283
R/utils.R                           10       0  100.00%
TOTAL                              408      20  95.10%

Diff against main

Filename                         Stmts    Miss  Cover
-----------------------------  -------  ------  -------
R/qenv-get_code.R                   +8      -1  +5.00%
R/utils-get_code_dependency.R     +191      +1  +99.48%
TOTAL                             +199       0  +4.67%

Results for commit: ea337f18241494064fa303c214b78e23b2fcb133

Minimum allowed coverage is 80%

:recycle: This comment has been updated with latest results

m7pr commented 3 weeks ago

@gogonzo looks like I need a new approval after I provided few commits (incorporated changes from teal.data https://github.com/insightsengineering/teal.data/pull/340/files)