Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 8, 2024
1 parent 7bc3b64 commit 85a45af
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ setGeneric(
#' Only used if `select` is `NULL`.
#' @param ... Further arguments to be passed to `select`.
#' @return
#' An [`integer`] vector or `NULL` (if `x` does not have row/column names).
#' An [`integer`] vector or `NULL`.
#' @example inst/examples/ex-seek.R
#' @author N. Frerebeau
#' @docType methods
Expand Down
13 changes: 3 additions & 10 deletions R/seek.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ seek <- function(x, margin = 2, select = NULL, names = NULL, ...) {
if (is.null(nm)) return(NULL)

if (is.null(select)) {
if (!is.null(names)) {
select <- function(i) match(names, i)
} else {
return(seq_len(dm))
}
if (is.null(names)) return(NULL)
select <- function(i) match(names, i)
}

assert_function(select)
i <- select(nm, ...)

if (is.logical(i)) i <- which(i)
if (length(i) == 0 || all(is.na(i))) i <- NULL
if (!is.null(i)) assert_type(i, "integer")
assert_type(i, "integer", allow_null = TRUE)
i
}

Expand All @@ -33,7 +30,6 @@ setMethod(
f = "seek_rows",
signature = c(x = "data.frame"),
definition = function(x, select = NULL, names = NULL, ...) {
# assert_rownames(x)
seek(x, margin = 1, select = select, names = names, ...)
}
)
Expand All @@ -45,7 +41,6 @@ setMethod(
f = "seek_rows",
signature = c(x = "matrix"),
definition = function(x, select = NULL, names = NULL, ...) {
# assert_rownames(x)
seek(x, margin = 1, select = select, names = names, ...)
}
)
Expand All @@ -57,7 +52,6 @@ setMethod(
f = "seek_columns",
signature = c(x = "data.frame"),
definition = function(x, select = NULL, names = NULL, ...) {
# assert_colnames(x)
seek(x, margin = 2, select = select, names = names, ...)
}
)
Expand All @@ -69,7 +63,6 @@ setMethod(
f = "seek_columns",
signature = c(x = "matrix"),
definition = function(x, select = NULL, names = NULL, ...) {
# assert_colnames(x)
seek(x, margin = 2, select = select, names = names, ...)
}
)
8 changes: 4 additions & 4 deletions inst/tinytest/test_seek.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Seek -------------------------------------------------------------------------
expect_null(seek_columns(iris, select = startsWith, prefix = "sepal"))
expect_identical(seek_columns(iris, select = NULL), 1:5)
expect_null(seek_columns(iris))
expect_identical(seek_columns(iris, select = startsWith, prefix = "Sepal"), c(1L, 2L))
expect_identical(seek_columns(iris, select = endsWith, suffix = "Width"), c(2L, 4L))
expect_identical(seek_columns(iris, names = c("Petal.Length", "Petal.Width")), c(3L, 4L))
expect_null(seek_columns(iris, names = c("XXX", "YYY")))
expect_error(seek_columns(iris, names = c(1, 2)), "must be character")
expect_error(seek_columns(iris, names = c(1, 2)))

x <- data.frame(
A = LETTERS,
B = 1:26
)
expect_null(seek_rows(x, select = startsWith, prefix = "BDX"))
rownames(x) <- sprintf("BDX%04d", 1:26)
expect_identical(seek_rows(x, select = NULL), 1:26)
expect_null(seek_rows(x))
expect_identical(seek_rows(x, select = startsWith, prefix = "BDX"), 1:26)
expect_identical(seek_rows(x, select = endsWith, suffix = "6"), c(6L, 16L, 26L))
expect_identical(seek_rows(x, names = c("BDX0010", "BDX0020")), c(10L, 20L))
expect_null(seek_rows(x, names = c("XXX", "YYY")))
expect_error(seek_rows(x, names = c(1, 2)), "must be character")
expect_error(seek_rows(x, names = c(1, 2)))

# Get --------------------------------------------------------------------------
x <- as.matrix(x)
Expand Down
2 changes: 1 addition & 1 deletion man/seek.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85a45af

Please sign in to comment.