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

introduce label to eval_code, within and get_code #248

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

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Mar 27, 2025

Proposition to close #241

#241 is a bit outdated, there no longer is id/index field. We now have @code field that has integers as names.
I decided to introduce label added to @code elements that can be used to trim code with get_code(labels).

I did not decide to change implementation so that it is possible to pass id/name of the @code element because when you pass code to eval_code it might be divided into multiple elements in the output @code. names of @code should be unique so that we can use join_qenv and similar functions. So it's actually hard to know what length of unique ids should be passed in eval_code for a specific code input (that then will be divided into multiple elements).

I decided that you can pass a label that is assigned as an attribute, and can be non-unique between elements of @code.

library(teal.code)

# example 1
object <- within(qenv(), {
  a <- 1
  b <- 2
}, label = "U")
get_code(object)
#> [1] "a <- 1\nb <- 2"
object@code
#> $`1511141524`
#> [1] "a <- 1"
#> attr(,"dependency")
#> [1] "a"  "<-"
#> attr(,"label")
#> [1] "U"
#> 
#> $`1923863218`
#> [1] "b <- 2"
#> attr(,"dependency")
#> [1] "b"  "<-"
#> attr(,"label")
#> [1] "U"
get_code(object, labels = "U")
#> [1] "a <- 1\nb <- 2"

# example 2
object <- qenv()
object <- eval_code(object, 'x <- 1')
object <- eval_code(object, 'y <- 2', label = 'label')
object <- eval_code(object, 'z <- 3', label = 'label2')

names(object@code)
#> [1] "1754984171" "1050465507" "2099130451"
labels <- c('label', 'label2')
get_code(object, labels = labels)
#> [1] "y <- 2\nz <- 3"

Created on 2025-03-27 with reprex v2.1.1

@m7pr m7pr added the core label Mar 27, 2025
@m7pr m7pr requested a review from gogonzo March 27, 2025 21:22
Copy link
Contributor

github-actions bot commented Mar 27, 2025

badge

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  ---------
R/qenv-c.R                          55       0  100.00%
R/qenv-class.R                      12       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       2  96.83%   113, 122
R/qenv-extract.R                    30       0  100.00%
R/qenv-get_code.R                   27       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_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      200       2  99.00%   160, 258
R/utils.R                           30       0  100.00%
TOTAL                              514      46  91.05%

Diff against main

Filename              Stmts    Miss  Cover
------------------  -------  ------  --------
R/qenv-eval_code.R       +6       0  +0.33%
R/qenv-get_code.R        +3       0  +100.00%
TOTAL                    +9       0  +0.16%

Results for commit: 2ff3aeb

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Mar 27, 2025

Unit Tests Summary

  1 files   12 suites   3s ⏱️
157 tests 154 ✅ 3 💤 0 ❌
238 runs  235 ✅ 3 💤 0 ❌

Results for commit 2ff3aeb.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Mar 27, 2025

Unit Test Performance Difference

Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
qenv_eval_code 👶 $+0.01$ it_is_possible_to_pass_label_to_eval_code
qenv_eval_code 👶 $+0.01$ it_is_possible_to_pass_label_to_eval_code_if_such_label_already_exists
qenv_get_code 👶 $+0.02$ it_is_possible_to_pass_labels_of_length_greater_than_1
qenv_get_code 👶 $+0.01$ names_are_ignored_when_labels_are_provided
qenv_get_code 👶 $+0.02$ when_labels_are_passed_only_code_related_to_those_labels_is_extracted

Results for commit 247c88d

♻️ This comment has been updated with latest results.

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.

[Feature Request]: qenv@code to have named index
1 participant