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

210 bring get_code_dependency #214

Merged
merged 12 commits into from
Oct 22, 2024
Merged

210 bring get_code_dependency #214

merged 12 commits into from
Oct 22, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Oct 16, 2024

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:3We 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.5schecking for future file timestamps ... NOTE
  unable to verify current time

0 errors| 0 warnings| 1 noteR CMD check succeeded

@m7pr m7pr added the core label Oct 16, 2024
@m7pr m7pr added the blocked label Oct 17, 2024
@m7pr m7pr marked this pull request as ready for review October 17, 2024 12:28
Copy link
Contributor

github-actions bot commented Oct 17, 2024

Unit Tests Summary

  1 files    9 suites   1s ⏱️
109 tests 107 ✅ 2 💤 0 ❌
198 runs  196 ✅ 2 💤 0 ❌

Results for commit ea337f1.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Oct 17, 2024

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 12097b6

♻️ This comment has been updated with latest results.

@m7pr
Copy link
Contributor Author

m7pr commented Oct 17, 2024

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

Error: there is no package called 'random.cdisc.data' 

@gogonzo gogonzo self-assigned this Oct 17, 2024
Copy link
Contributor

github-actions bot commented Oct 18, 2024

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: ea337f1

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

gogonzo
gogonzo previously approved these changes Oct 21, 2024
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

👍

@gogonzo gogonzo removed the blocked label Oct 22, 2024
@gogonzo gogonzo dismissed their stale review October 22, 2024 13:43

copied functions changed in source

@m7pr m7pr requested a review from gogonzo October 22, 2024 14:41
@m7pr
Copy link
Contributor Author

m7pr commented Oct 22, 2024

@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)

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

checked again, everything is fine here

@m7pr m7pr merged commit 03d952d into main Oct 22, 2024
29 checks passed
@m7pr m7pr deleted the 218_deprecate_get_code@main branch October 22, 2024 15:03
m7pr added a commit to insightsengineering/teal.data that referenced this pull request Oct 22, 2024
Part of 
- insightsengineering/teal.code#210

Companion to
- insightsengineering/teal#1388
- insightsengineering/teal.code#214

# Description

Deprecates the usage of `datanames` parameter in
`teal.data::get_code(datanames)` in favour of
`teal.code::get_code(names)`.

VBUMP package version locally to something greater than `0.6.1` during
testing.

``` r
library(teal.data)
#> Loading required package: teal.code
tdata1 <- within(teal_data(), {a <- 1; b <- 2})
get_code(tdata1)
#> [1] "a <- 1\nb <- 2"
get_code(tdata1, datanames = "a")
#> Warning: The `datanames` argument of `get_code()` is deprecated as of teal.data 0.6.1.
#> ℹ Please use the `names` argument of `teal.code::get_code()` instead.
#> ℹ The deprecated feature was likely used in the teal.data package.
#>   Please report the issue at
#>   <https://github.com/insightsengineering/teal.data/issues>.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> [1] "a <- 1"
```

<sup>Created on 2024-10-17 with [reprex
v2.1.1](https://reprex.tidyverse.org)</sup>

---------

Signed-off-by: Marcin <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pawel Rucki <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement names argument in get_code to subset code for specific objects.
2 participants