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

1012 substitute {assertthat} with {checkmate} in a couple of functions #1046

Merged
merged 35 commits into from
Feb 9, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Feb 7, 2024

Part of #1012
Removed {assertthat} package and substituted with {checkmate} equivalents.
Removed R/dynamic_assertions.R since functions are not used in this package, and not in any other place in pharmaverse.

image

@m7pr m7pr marked this pull request as ready for review February 7, 2024 12:51
R/tm_g_pp_therapy.R Outdated Show resolved Hide resolved
R/tm_t_ancova.R Outdated Show resolved Hide resolved
R/tm_t_events_by_grade.R Outdated Show resolved Hide resolved
@averissimo
Copy link
Contributor

averissimo commented Feb 7, 2024

TODO: need help removing assertthat::on_failure in R/dynamic_assertions.R

I think it's a dynamic helper that helps to assert function results without explicitly calling the validation function. (it adds an attribute to the function)

It also creates a nice verbose message as a benefit

I don't think {checkmate} supports this. An equivalent example would be:

expect_error(validate_enough_rows(teal_enough_rows(data = iris, min_nrow = 1500)))

With assert that you may not skip using validate_enough_rows function explicitly)

library(testthat)
library(assertthat)

teal_enough_rows <- function(data, min_nrow) nrow(data) >= min_nrow

validate_enough_rows <- function(data, min_nrow) {
  shiny::validate(
    shiny::need(
      FALSE,
      label = paste0(
        substitute(data),
        ": Minimum number of records not met: >= ", min_nrow,
        " records required."
      )
    )
  )
}

teal_enough_rows(data = iris, min_nrow = 1500)
#> [1] FALSE
assert_that(teal_enough_rows(data = iris, min_nrow = 1500))
#> Error: teal_enough_rows(data = iris, min_nrow = 1500) is not TRUE

attr(teal_enough_rows, "fail") <- function(call, env) {
  call[[1]] <- validate_enough_rows
  eval(call, envir = env)
}

teal_enough_rows(data = iris, min_nrow = 1500)
#> [1] FALSE
assert_that(teal_enough_rows(data = iris, min_nrow = 1500))
#> Error: iris: Minimum number of records not met: >= 1500 records required. must be provided

Created on 2024-02-07 with reprex v2.0.2

Copy link
Contributor

github-actions bot commented Feb 7, 2024

Unit Tests Summary

  1 files   33 suites   2s ⏱️
150 tests 150 ✅   0 💤 0 ❌
282 runs  170 ✅ 112 💤 0 ❌

Results for commit 970096e.

♻️ This comment has been updated with latest results.

@m7pr
Copy link
Contributor Author

m7pr commented Feb 7, 2024

@averissimo I don't think I understood fully your comment but I get that we are not able to substitute this part with anything from checkmate right? I checked and neither of teal_enough_rows, validate_enough_rows, teal_has_element, validate_has_elements is used in the package so maybe we can delete them?

@m7pr
Copy link
Contributor Author

m7pr commented Feb 8, 2024

@Melkiades are you aware if

teal_enough_rows, validate_enough_rows, teal_has_element, validate_has_elements

are used anywhere outside of this package? We were hoping we can remove those, or at least move to /dev : )

Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

Minor suggestions, overall looks really good!

R/tm_g_pp_patient_timeline.R Outdated Show resolved Hide resolved
R/tm_g_pp_patient_timeline.R Outdated Show resolved Hide resolved
R/tm_g_forest_rsp.R Show resolved Hide resolved
R/tm_g_pp_adverse_events.R Outdated Show resolved Hide resolved
R/tm_g_pp_patient_timeline.R Outdated Show resolved Hide resolved
R/tm_g_pp_patient_timeline.R Outdated Show resolved Hide resolved
R/tm_g_pp_therapy.R Outdated Show resolved Hide resolved
R/tm_g_pp_vitals.R Outdated Show resolved Hide resolved
R/tm_t_events_by_grade.R Show resolved Hide resolved
Merge branch 'main' into 1012_assert_1@main

# Conflicts:
#	R/dynamic_assertions.R
#	man/dyn_assertion.Rd
@m7pr
Copy link
Contributor Author

m7pr commented Feb 8, 2024

I removed R/dynamic_assertions.R in c81fee9 since functions are not used in this package, and not in any other place in pharmaverse.

image

@m7pr
Copy link
Contributor Author

m7pr commented Feb 8, 2024

Looks like 86 tests are failing 👯

@m7pr
Copy link
Contributor Author

m7pr commented Feb 8, 2024

Looks like 86 tests are failing

Should be fixed by now

@averissimo averissimo self-assigned this Feb 9, 2024
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

Looks good to merge, however I think an assertion below will not work, take a look at one of the comments

if (isTRUE(interact_y)) all(sapply(interact_y, checkmate::assert_string))

I also discovered that you can place an if clause inside assert() function and get pretty messages (without having to create a check function) 🥳

R/utils.R Show resolved Hide resolved
R/tm_t_ancova.R Outdated Show resolved Hide resolved
R/tm_t_events_by_grade.R Outdated Show resolved Hide resolved
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
@Melkiades
Copy link
Contributor

Looks good to merge, however I think an assertion below will not work, take a look at one of the comments

if (isTRUE(interact_y)) all(sapply(interact_y, checkmate::assert_string))

I also discovered that you can place an if clause inside assert() function and get pretty messages (without having to create a check function) 🥳

Looking at it now, it is a character vector, so I would just do checkmate::assert_character(...)

Copy link
Contributor

@Melkiades Melkiades left a comment

Choose a reason for hiding this comment

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

For me it is good to go. Thanks @m7pr!! ;)

m7pr and others added 4 commits February 9, 2024 12:38
Co-authored-by: André Veríssimo <[email protected]>
Signed-off-by: Marcin <[email protected]>
Merge branch 'main' of https://github.com/insightsengineering/teal.modules.clinical

# Conflicts:
#	R/dynamic_assertions.R
#	man/dyn_assertion.Rd
@m7pr m7pr merged commit 55fa7c6 into main Feb 9, 2024
25 checks passed
@m7pr m7pr deleted the 1012_assert_1@main branch February 9, 2024 12:02
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.

3 participants