Skip to content

Commit e50b066

Browse files
committed
allow NA values as input to rowcol_from_well
1 parent ff3f26f commit e50b066

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

R/wells.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,22 @@ well_from_rowcol <- function(row, col) {
7272
#' @return A list with two elements: row and col
7373
#' @export
7474
#' @examples
75-
#' rowcol_from_well(c("A1", "B2", "C3"), 48)
75+
#' rowcol_from_well(c("A1", "B2", "C3", NA), 48)
7676
#' # The order is preserved
7777
#' rowcol_from_well(c("H12", "A1"), 96)
7878
rowcol_from_well <- function(well, format) {
7979
format <- as.character(format)
8080
if (!length(format) == 1) {
81-
rlang::abort("Format must be a single element character vector")
81+
rlang::abort("Plate format must be a single element character vector")
8282
}
83-
if (!as.character(format) %in% names(.plateformats)) {
84-
rlang::abort("Format must be one of '24', '48', '96', or '384'")
83+
plfs <- names(.plateformats)
84+
if (!as.character(format) %in% plfs) {
85+
rlang::abort(glue::glue("Plate format must be one of ", paste0("'", plfs, "'", collapse = ", "), "."))
8586
}
8687
if (!is.character(well)) {
8788
rlang::abort("Well must be a character vector")
8889
}
89-
if (any(!well %in% .plateformats[[format]]$wellnames)) {
90+
if (any(!well[!is.na(well)] %in% .plateformats[[format]]$wellnames)) {
9091
rlang::abort(glue::glue("Wells not present in {format}-wells format"))
9192
}
9293
indices <- match(well, .plateformats[[format]]$map$well)

tests/testthat/test-wells.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test_that("Function rowcol_from_well works", {
3636
expect_error(rowcol_from_well(c("A1", "B2"), 90))
3737
})
3838

39-
test_that("Function rowcol_from_well yields error when well is NA", {
40-
expect_error(rowcol_from_well(c("A1", NA), 96))
39+
test_that("Function rowcol_from_well yields no error when well is NA", {
40+
expect_no_error(rowcol_from_well(c("A1", NA), 96))
41+
expect_equal(rowcol_from_well(c("A1", NA), 96), .plateformats[['96']]$map[c(1,NA), c('row', 'col')])
4142
})

0 commit comments

Comments
 (0)