Skip to content

Commit 47fccef

Browse files
committed
Clean up argument checks
1 parent 3058edd commit 47fccef

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

Diff for: DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: msigdbr
33
Title: MSigDB Gene Sets for Multiple Organisms in a Tidy Data Format
4-
Version: 10.0.0
4+
Version: 10.0.0.9000
55
Authors@R:
66
person("Igor", "Dolgalev", , "[email protected]", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0003-4451-126X"))
@@ -19,6 +19,7 @@ BugReports: https://github.com/igordot/msigdbr/issues
1919
Depends:
2020
R (>= 4.1)
2121
Imports:
22+
assertthat,
2223
babelgene (>= 22.9),
2324
dplyr (>= 1.1.1),
2425
lifecycle,

Diff for: NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(msigdbr_collections)
55
export(msigdbr_species)
66
import(tibble)
77
import(tidyselect)
8+
importFrom(assertthat,assert_that)
89
importFrom(babelgene,orthologs)
910
importFrom(babelgene,species)
1011
importFrom(dplyr,arrange)
@@ -20,5 +21,6 @@ importFrom(lifecycle,is_present)
2021
importFrom(methods,is)
2122
importFrom(rlang,.data)
2223
importFrom(rlang,check_installed)
24+
importFrom(rlang,is_installed)
2325
importFrom(utils,install.packages)
2426
importFrom(utils,menu)

Diff for: R/msigdbr-package.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
## usethis namespace: start
55
#' @import tibble
66
#' @import tidyselect
7+
#' @importFrom assertthat assert_that
78
#' @importFrom lifecycle deprecated is_present
89
#' @importFrom methods is
9-
#' @importFrom rlang .data check_installed
10+
#' @importFrom rlang .data check_installed is_installed
1011
## usethis namespace: end
1112
NULL

Diff for: R/msigdbr.R

+27-16
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,46 @@
3434
#' @export
3535
msigdbr <- function(species = "Homo sapiens", db_species = "HS", collection = NULL, subcollection = NULL, category = deprecated(), subcategory = deprecated()) {
3636
# Check parameters
37-
if (!is(species, "character")) {
38-
stop("`species` is not a character string")
39-
}
40-
if (length(species) > 1) {
41-
stop("only one `species` should be specified")
37+
assertthat::assert_that(
38+
is.character(species),
39+
length(species) == 1,
40+
nchar(species) > 1
41+
)
42+
assertthat::assert_that(
43+
is.character(db_species),
44+
length(db_species) == 1,
45+
nchar(db_species) == 2
46+
)
47+
if (!is.null(collection)) {
48+
assertthat::assert_that(
49+
is.character(collection),
50+
length(collection) == 1,
51+
nchar(collection) > 0
52+
)
4253
}
43-
if (!is(db_species, "character")) {
44-
stop("`db_species` is not a character string")
54+
if (!is.null(subcollection)) {
55+
assertthat::assert_that(
56+
is.character(subcollection),
57+
length(subcollection) == 1,
58+
nchar(subcollection) > 0
59+
)
4560
}
4661

4762
# Use only mouse genes for mouse database
4863
db_species <- toupper(db_species)
4964
if (db_species == "MM" && !(species %in% c("Mus musculus", "mouse", "house mouse"))) {
50-
stop("set species to mouse for the mouse database")
65+
stop("Set `species` to mouse for the mouse database.")
5166
}
5267

5368
# Check for deprecated category arguments
5469
if (lifecycle::is_present(category)) {
55-
lifecycle::deprecate_warn("9.0.0", "msigdbr(category)", "msigdbr(collection)")
70+
lifecycle::deprecate_warn("10.0.0", "msigdbr(category)", "msigdbr(collection)")
71+
assertthat::assert_that(is.character(category), length(category) == 1, nchar(category) > 0)
5672
collection <- category
5773
}
5874
if (lifecycle::is_present(subcategory)) {
59-
lifecycle::deprecate_warn("9.0.0", "msigdbr(subcategory)", "msigdbr(subcollection)")
75+
lifecycle::deprecate_warn("10.0.0", "msigdbr(subcategory)", "msigdbr(subcollection)")
76+
assertthat::assert_that(is.character(subcategory), length(subcategory) == 1, nchar(subcategory) > 0)
6077
subcollection <- subcategory
6178
}
6279

@@ -77,9 +94,6 @@ msigdbr <- function(species = "Homo sapiens", db_species = "HS", collection = NU
7794

7895
# Filter by collection
7996
if (is.character(collection)) {
80-
if (length(collection) > 1) {
81-
stop("Please specify only one collection at a time.")
82-
}
8397
if (collection %in% mdb$gs_collection) {
8498
mdb <- dplyr::filter(mdb, .data$gs_collection == collection)
8599
} else {
@@ -89,9 +103,6 @@ msigdbr <- function(species = "Homo sapiens", db_species = "HS", collection = NU
89103

90104
# Filter by sub-collection
91105
if (is.character(subcollection)) {
92-
if (length(subcollection) > 1) {
93-
stop("Please specify only one subcollection at a time.")
94-
}
95106
if (subcollection %in% mdb$gs_subcollection) {
96107
mdb <- dplyr::filter(mdb, .data$gs_subcollection == subcollection)
97108
} else if (subcollection %in% gsub(".*:", "", mdb$gs_subcollection)) {

0 commit comments

Comments
 (0)