Update package check functions, add skip_if_not_pkg_installed()#27
Update package check functions, add skip_if_not_pkg_installed()#27
skip_if_not_pkg_installed()#27Conversation
ddsjoberg
left a comment
There was a problem hiding this comment.
Thank you! This is much simpler! Can we make a few small updates?
- There is a reference to
str_detect(). Can we replace this with the base R function so we don't have a dependency on the stringr standalone file? - Can we rename
skip_if_not_pkg_installed()toskip_if_pkg_not_installed()? - We have
message = "Not all required packages are installed". Can we add the package names here? Or was this one of the requests from Michael that the message is not unique to the package names?
Done!
Yes! I've updated the name.
No, he didn't indicate this in his PRs, so I've gone ahead and updated the skip message. New output: |
|
On second thought, I think the custom error message will result in this same issue Michael flagged with the test logs: insightsengineering/cardx#306 @ddsjoberg what is your interpretation of this? Should we just use one unified error message with no packages listed? |
|
I've updated the message again so now only the first missing package is printed in each test. This results in a somewhat smaller test log but still lists at least some of the packages that are missing. In this case the test log from Michael's issue would look something like this (~33% fewer lines): |
|
Ah, thanks for looking into the details! Let's take his suggestion to only show the message for the first missing pkg. But what I don't love is that we're parsing the DESCRIPTION file so many times. Would something like this work? (I am not sure we need the skip_if_pkg_not_installed <- function(pkgs,
ref = utils::packageName()) {
df_deps <- get_min_version_required(pkgs, ref = ref)
for (i in seq_along(df_deps$pkg)) {
if (rlang::is_installed(df_deps$pkg[i])) {
# skip if any required package is not installed
testthat::skip(
message = paste(
"Required package", shQuote(df_deps$pkg[i], type = "sh"), "is not installed"
)
)
break
}
}
invisible()
} |
I've updated to use Ready for another review whenever you have time!! |
ddsjoberg
left a comment
There was a problem hiding this comment.
Thank you for the update!!
What changes are proposed in this pull request?
skip_if_not_pkg_installed()to skip tests if required packages are not installed.Pre-review Checklist (if item does not apply, mark is as complete)
usethis::pr_merge_main()last-updatedfield has been updated.devtools::test_coverage()Reviewer Checklist (if item does not apply, mark is as complete)
last-updatedfield has been updated.pkgdown::build_site(). Check the R console for errors, and review the rendered website.devtools::test_coverage()When the branch is ready to be merged: