-
Notifications
You must be signed in to change notification settings - Fork 1
Add check_requires() function and update installation docs #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72ee24d
Add check_requires() function
lazappi 4382398
Add tests for check_requires()
lazappi 1d27bb2
Replace requireNamespace() with check_requires()
lazappi 249b752
Add suggested dependencies to installation docs
lazappi 5aacab4
Add rlang to Imports
lazappi f39a16e
Style and lint
lazappi 0983e4d
Update CHANGELOG
lazappi 2c497ce
Merge remote-tracking branch 'origin/main' into issues-46-47/check-su…
lazappi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
Package: laminr | ||
Title: 'LaminDB' Interface in R | ||
Version: 0.1.0 | ||
Authors@R: | ||
c(person("Robrecht", "Cannoodt", | ||
role = c("aut", "cre"), | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood") | ||
), | ||
person( | ||
"Luke", "Zappia", | ||
role = "aut", | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0001-7744-8565", github = "lazappi") | ||
), | ||
person("Data Intuitive", email = "[email protected]", role = c("aut")), | ||
person("Lamin Labs", email = "[email protected]", role = c("aut", "cph"))) | ||
Description: Interact with 'LaminDB' from R. 'LaminDB' is an open-source data framework for biology. | ||
This package allows you to query and download data from 'LaminDB' instances. | ||
Authors@R:c( | ||
person("Robrecht", "Cannoodt", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood")), | ||
person("Luke", "Zappia", , "[email protected]", role = "aut", | ||
comment = c(ORCID = "0000-0001-7744-8565", github = "lazappi")), | ||
person("Data Intuitive", , , "[email protected]", role = "aut"), | ||
person("Lamin Labs", , , "[email protected]", role = c("aut", "cph")) | ||
) | ||
Description: Interact with 'LaminDB' from R. 'LaminDB' is an open-source | ||
data framework for biology. This package allows you to query and | ||
download data from 'LaminDB' instances. | ||
License: Apache License (>= 2) | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.2 | ||
URL: https://laminr.lamin.ai, https://github.com/laminlabs/laminr | ||
BugReports: https://github.com/laminlabs/laminr/issues | ||
Depends: | ||
|
@@ -30,12 +22,17 @@ Imports: | |
httr, | ||
jsonlite, | ||
purrr, | ||
R6 | ||
R6, | ||
rlang | ||
Suggests: | ||
anndata, | ||
quarto, | ||
s3 (>= 1.1.0), | ||
testthat (>= 3.0.0), | ||
withr | ||
VignetteBuilder: quarto | ||
VignetteBuilder: | ||
quarto | ||
Config/testthat/edition: 3 | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.3.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Check required packages | ||
#' | ||
#' Check that required packages are available and give a nice error message with | ||
#' install instructions if not | ||
#' | ||
#' @param what A message stating what the packages are required for. Used at the | ||
#' start of the error message e.g. "{what} requires...". | ||
#' @param requires Character vector of required package names | ||
#' | ||
#' @return `TRUE` invisibly if all packages are available, otherwise calls | ||
#' [cli::cli_abort()] | ||
#' @noRd | ||
check_requires <- function(what, requires) { | ||
is_available <- purrr::map_lgl(requires, requireNamespace, quietly = TRUE) | ||
|
||
if (any(!is_available)) { | ||
missing <- requires[!is_available] | ||
missing_str <- paste0("'", paste(missing, collapse = "', '"), "'") # nolint object_usage_linter | ||
cli_abort( | ||
c( | ||
"{what} requires the {.pkg {missing}} package{?s}", | ||
"i" = paste( | ||
"To continue, install {cli::qty(missing)}{?it/them} using", | ||
"{.code install.packages(c({missing_str}))}" | ||
) | ||
), | ||
call = rlang::caller_env() | ||
) | ||
} | ||
|
||
invisible(TRUE) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
test_that("check_requires works", { | ||
expect_true(check_requires("Imported packages", "cli")) | ||
expect_error( | ||
check_requires("Missing packages", "a_missing_package"), | ||
regexp = "Missing packages requires" | ||
) | ||
}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.