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

211 [.teal_data S3 method #346

Merged
merged 40 commits into from
Nov 8, 2024
Merged

211 [.teal_data S3 method #346

merged 40 commits into from
Nov 8, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Oct 28, 2024

Companion to insightsengineering/teal.code#216

Introduces [.teal_data S3 method for teal_data that is based on [.qenv but also limits join_keys.

Copy link
Contributor

github-actions bot commented Oct 28, 2024

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  --------------------
R/cdisc_data.R                   1       0  100.00%
R/deprecated.R                  71      65  8.45%    19-380
R/dummy_function.R               2       2  0.00%    14-15
R/formatters_var_labels.R       61       0  100.00%
R/join_key.R                    38       0  100.00%
R/join_keys-c.R                 12       0  100.00%
R/join_keys-extract.R          128       0  100.00%
R/join_keys-names.R             15       0  100.00%
R/join_keys-parents.R           30       0  100.00%
R/join_keys-print.R             45       0  100.00%
R/join_keys-utils.R             73       3  95.89%   35-38
R/join_keys.R                   21       0  100.00%
R/teal_data-class.R             35       4  88.57%   71, 119-121
R/teal_data-constructor.R       31      16  48.39%   33, 36-42, 52-58, 61
R/teal_data-extract.R            3       0  100.00%
R/teal_data-get_code.R          13       8  38.46%   114-120, 124
R/teal_data-names.R              8       1  87.50%   31
R/teal_data-show.R               4       4  0.00%    14-19
R/testhat-helpers.R             26       0  100.00%
R/topological_sort.R            32       0  100.00%
R/verify.R                      42      11  73.81%   67, 97-101, 104-108
TOTAL                          691     114  83.50%

Diff against main

Filename                     Stmts    Miss  Cover
-------------------------  -------  ------  --------
R/teal_data-class.R            +21      +4  -11.43%
R/teal_data-constructor.R      +31     +16  +48.39%
R/teal_data-extract.R           +3       0  +100.00%
TOTAL                          +55     +20  -0.01%

Results for commit: a24bac3

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

Unit Tests Summary

  1 files   13 suites   1s ⏱️
162 tests 162 ✅ 0 💤 0 ❌
219 runs  219 ✅ 0 💤 0 ❌

Results for commit 967c1c5.

Copy link
Contributor

github-actions bot commented Oct 28, 2024

Unit Tests Summary

  1 files   14 suites   1s ⏱️
161 tests 161 ✅ 0 💤 0 ❌
216 runs  216 ✅ 0 💤 0 ❌

Results for commit a24bac3.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

Once I read in detail the code and documentation I have some feedback.
I think the examples will be very helpful, I am not sure if the current changes on documentation have the desired consequences.

More importantly matching base's generic argument and take advantage of the S3 methods used here will probably make developing and maintaining the code easier.

When I checked locally the examples failed (It could be my setup), but running interactively shows it too (so there might be some undeclared expectations/dependencies):

d> data["a"]
Error en get(x, envir = ns, inherits = FALSE): 
  objeto '[.qenv' no encontrado
d> traceback()
4: get(x, envir = ns, inherits = FALSE)
3: utils::getFromNamespace("[.qenv", "teal.code") at teal_data-extract.R#33
2: `[.teal_data`(data, "a")
1: data["a"]
d> packageVersion("teal.code")
[1] '0.5.0.9011'
d> packageVersion("teal.data")
[1] '0.6.0.9015'

R/teal_data-extract.R Show resolved Hide resolved
R/teal_data-extract.R Outdated Show resolved Hide resolved
R/teal_data-extract.R Show resolved Hide resolved
R/teal_data-extract.R Show resolved Hide resolved
@m7pr
Copy link
Contributor Author

m7pr commented Oct 29, 2024

@llrs-roche

objeto '[.qenv' no encontrado

Any chance you can change your local setup to English : P ?

Sys.setlocale("LC_ALL","English")

https://stackoverflow.com/questions/16347731/how-to-change-the-locale-of-r

@m7pr
Copy link
Contributor Author

m7pr commented Oct 29, 2024

@llrs-roche you need to install teal.code from 211_subset@main, the same as teal.data from 211_subset@main. Looks like you did not had teal.code installed from 211_subset@main, hence you could not find a function [.qenv.
This is how we prepare PRs for multiple repositories - if functionality is shared between multiple packages, then you need to install all packages from a specific branch to run and check the code.

Thanks for the attempt!

R/teal_data-extract.R Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Oct 29, 2024

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
extract 👶 $+0.09$ $+6$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
extract 👶 $+0.02$ _._preserves_verified_field
extract 👶 $+0.04$ _._subsets_join_keys_also
extract 👶 $+0.03$ _._warns_and_subsets_if_names_are_present_in_code
teal_data 👶 $+0.01$ empty_teal_data_returns_empty_code_and_verified_TRUE
teal_data 💀 $0.02$ $-0.02$ empty_teal_data_returns_empty_code_id_wartnings_and_messages_and_verified_TRUE
verify 👶 $+0.03$ verify_raises_error_if_code_does_not_restore_objects_in_.xData
verify 💀 $0.01$ $-0.01$ verify_raises_error_if_code_does_not_restore_objects_in_env

Results for commit 9c92975

♻️ This comment has been updated with latest results.

llrs-roche
llrs-roche previously approved these changes Oct 29, 2024
Copy link
Contributor

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. I think this is mostly ready for merging, I just added a petition to have a test for a numeric and NA_character_.

I think, the workaround with NextMethod() come from defining it differently than the generic, but seem easy enough.

I tried loading teal.code@211_subset@main and running [.qenv exampels still got the same problems object 'parsed_code' not found, so it might be something related to my environment.

R/teal_data-extract.R Show resolved Hide resolved
R/teal_data-extract.R Show resolved Hide resolved
R/teal_data-extract.R Show resolved Hide resolved
@m7pr
Copy link
Contributor Author

m7pr commented Oct 30, 2024

I tried loading teal.code@211_subset@main and running [.qenv exampels still got the same problems object 'parsed_code' not found, so it might be something related to my environment.

And you did good. I actually left teal.code in unstable state yesterday when I left the office insightsengineering/teal.code#216 (comment) so it was broken. You got the very same error as I got : )

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.

Minor comments

R/teal_data-extract.R Outdated Show resolved Hide resolved
R/teal_data-extract.R Outdated Show resolved Hide resolved
tests/testthat/test-extract.R Outdated Show resolved Hide resolved
tests/testthat/test-extract.R Outdated Show resolved Hide resolved
R/teal_data-constructor.R Outdated Show resolved Hide resolved
m7pr and others added 2 commits October 30, 2024 14:27
Co-authored-by: Dawid Kałędkowski <[email protected]>
Signed-off-by: Marcin <[email protected]>
Co-authored-by: Dawid Kałędkowski <[email protected]>
Signed-off-by: Marcin <[email protected]>
@llrs-roche
Copy link
Contributor

Feel free to merge but I still have problems with executing the code with the latest update from teal.code@211_subset@main:

d> data <- teal_data()
d> data <- eval_code(data, "a <- 1;b<-2")
Error in parse(text = code_split[[i]], keep.source = FALSE) : 
  <text>:1:12: unexpected symbol
1: a <- 1;b<-2a
               ^
d> data["a"]
✅︎ verified teal_data object
<environment: 0x00000171ebb781d0> [L]
Parent: <environment: devtools_shims>
Warning message:
In `[.teal_data`(data, "a") :
  None of `names` elements exist in `teal_data`. Returning empty `teal_data`.
d> data[c("a", "b")]
✅︎ verified teal_data object
<environment: 0x00000171ea8c9710> [L]
Parent: <environment: devtools_shims>
Warning message:
In `[.teal_data`(data, c("a", "b")) :
  None of `names` elements exist in `teal_data`. Returning empty `teal_data`.
d> 
d> session_info()
─ Session info ───────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.1 (2024-06-14 ucrt)
 os       Windows 11 x64 (build 22631)
 system   x86_64, mingw32
 ui       RStudio
 language en
 collate  Spanish_Spain.utf8
 ctype    Spanish_Spain.utf8
 tz       Europe/Madrid
 date     2024-10-30
 rstudio  2024.09.0+375 Cranberry Hibiscus (desktop)
 pandoc   3.5 @ C:\\Users\\sanchosl\\AppData\\Local\\Pandoc\\pandoc.exePackages ───────────────────────────────────────────────────────────────────────────
 !  package     * version    date (UTC) lib source
    backports     1.5.0      2024-05-23 [2] CRAN (R 4.4.0)
    brio          1.1.5      2024-04-24 [2] CRAN (R 4.4.1)
    cachem        1.1.0      2024-05-16 [2] CRAN (R 4.4.1)
    callr         3.7.6      2024-03-25 [2] CRAN (R 4.4.1)
    checkmate     2.3.2      2024-07-29 [2] CRAN (R 4.4.1)
    cli           3.6.3      2024-06-21 [2] CRAN (R 4.4.1)
    curl          5.2.3      2024-09-20 [2] CRAN (R 4.4.1)
    desc          1.4.3      2023-12-10 [2] CRAN (R 4.4.1)
    devtools    * 2.4.5      2022-10-11 [2] CRAN (R 4.4.1)
    digest        0.6.37     2024-08-19 [2] CRAN (R 4.4.1)
    ellipsis      0.3.2      2021-04-29 [2] CRAN (R 4.4.1)
    fastmap       1.2.0      2024-05-15 [2] CRAN (R 4.4.1)
    fs            1.6.4      2024-04-25 [2] CRAN (R 4.4.1)
    glue          1.8.0      2024-09-30 [2] CRAN (R 4.4.1)
    htmltools     0.5.8.1    2024-04-04 [2] CRAN (R 4.4.1)
    htmlwidgets   1.6.4      2023-12-06 [2] CRAN (R 4.4.1)
    httpuv        1.6.15     2024-03-26 [2] CRAN (R 4.4.1)
    later         1.3.2      2023-12-06 [2] CRAN (R 4.4.1)
    lifecycle     1.0.4      2023-11-07 [2] CRAN (R 4.4.1)
    magrittr      2.0.3      2022-03-30 [2] CRAN (R 4.4.1)
    memoise       2.0.1      2021-11-26 [2] CRAN (R 4.4.1)
    mime          0.12       2021-09-28 [2] CRAN (R 4.4.0)
    miniUI        0.1.1.1    2018-05-18 [2] CRAN (R 4.4.1)
    pkgbuild      1.4.4      2024-03-17 [2] CRAN (R 4.4.1)
    pkgload       1.4.0      2024-06-28 [2] CRAN (R 4.4.1)
    processx      3.8.4      2024-03-16 [2] CRAN (R 4.4.1)
    profvis       0.4.0      2024-09-20 [2] CRAN (R 4.4.1)
    promises      1.3.0      2024-04-05 [2] CRAN (R 4.4.1)
    ps            1.8.0      2024-09-12 [2] CRAN (R 4.4.1)
    purrr         1.0.2      2023-08-10 [2] CRAN (R 4.4.1)
    R6            2.5.1      2021-08-19 [2] CRAN (R 4.4.1)
    Rcpp          1.0.13     2024-07-17 [2] CRAN (R 4.4.1)
    remotes       2.5.0      2024-03-17 [2] CRAN (R 4.4.1)
    rlang         1.1.4      2024-06-04 [2] CRAN (R 4.4.1)
    rprojroot     2.0.4      2023-11-05 [2] CRAN (R 4.4.1)
    rstudioapi    0.17.1     2024-10-22 [2] CRAN (R 4.4.1)
    sessioninfo   1.2.2      2021-12-06 [2] CRAN (R 4.4.1)
    shiny         1.9.1      2024-08-01 [2] CRAN (R 4.4.1)
    teal.code   * 0.5.0.9012 2024-10-30 [1] Github (insightsengineering/teal.code@a32939c)
 VP teal.data   * 0.6.0.9015 2024-10-21 [?] Github (insightsengineering/teal.data@b5ccb1d) (on disk 0.6.0.9012)
    testthat    * 3.2.1.1    2024-04-14 [2] CRAN (R 4.4.1)
    urlchecker    1.0.1      2021-11-30 [2] CRAN (R 4.4.1)
    usethis     * 3.0.0      2024-07-29 [2] CRAN (R 4.4.1)
    vctrs         0.6.5      2023-12-01 [2] CRAN (R 4.4.1)
    withr         3.0.1      2024-07-31 [2] CRAN (R 4.4.1)
    xtable        1.8-4      2019-04-21 [2] CRAN (R 4.4.1)

 [1] C:/Users/sanchosl/R-dev
 [2] C:/Users/sanchosl/AppData/Local/R/win-library/4.4
 [3] C:/Program Files/R/R-4.4.1/library

 V ── Loaded and on-disk version mismatch.
 P ── Loaded and on-disk path mismatch.

@gogonzo gogonzo self-assigned this Nov 6, 2024
@m7pr m7pr marked this pull request as ready for review November 8, 2024 08:26
@m7pr
Copy link
Contributor Author

m7pr commented Nov 8, 2024

Since insightsengineering/teal.code#216 is ready, I open this PR for the review. Let's see results of CI/CD checks

R/teal_data-class.R Outdated Show resolved Hide resolved
R/teal_data-class.R Outdated Show resolved Hide resolved
R/teal_data-extract.R Outdated Show resolved Hide resolved
R/teal_data-extract.R Outdated Show resolved Hide resolved
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 enabled auto-merge (squash) November 8, 2024 18:19
@gogonzo gogonzo merged commit 8464745 into main Nov 8, 2024
28 checks passed
@gogonzo gogonzo deleted the 211_subset@main branch November 8, 2024 18:19
@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 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.

4 participants