Skip to content

Commit 4687e61

Browse files
committed
renaming and improving format_wells to normalize_wells; optional plate format argument
1 parent b43e080 commit 4687e61

5 files changed

Lines changed: 52 additions & 33 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(format_wells)
43
export(has_star)
54
export(kvlist_to_table)
65
export(long_to_shortnames)
6+
export(normalize_wells)
77
export(read_data)
88
export(read_guide)
99
export(rowcol_from_well)

R/wells.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#' Normalize a vector with well names.
22
#'
33
#' @param v A vector with potentially sloppy well names
4-
#' @param format A single element character or numeric vector with the format of the plate
5-
#' @return A vector with standardized well names
4+
#' @param format A single element character or numeric vector with the format of the plate, or NULL
5+
#' @description
6+
#' Normalized well names are in the format `A1`, `B2`, `H12`, etc., i.e., an
7+
#' uppercase letter followed by an integer without zero-padding and without
8+
#' spaces. If the well name can not be converted to a normalized value an NA is
9+
#' returned. If the plate format is given then the well names are checked to see
10+
#' if they are present in the format, and are converted to NA if not.
11+
#'
12+
#' @return A vector with normalized well names
613
#' @export
714
#' @examples
8-
#' normalize_wells(c("a01", "A 2", "0", " A 4 ", "A05", "H012"), 96)
15+
#' normalize_wells(c("a01", "A 2", "0", " A 4 ", "A05", "H012", "K12"), 96)
16+
#' normalize_wells(c("a01", "A 2", "0", " A 4 ", "A05", "H012", "K12"))
917
#'
1018
#'
11-
normalize_wells <- function(v, format) {
19+
normalize_wells <- function(v, format = NULL) {
1220
v <- as.character(v) |>
1321
stringr::str_remove_all(" ") |>
1422
stringr::str_to_upper() |>
1523
stringr::str_replace("(?<=[A-Z])0+", "")
16-
check_wells(v , format, returnerror = FALSE)
24+
if (!is.null(format)) {
25+
v <- check_wells(v , format, returnerror = FALSE)
26+
}
27+
v[!stringr::str_detect(v, "^[A-Z]+\\d++$")] <- NA
28+
v
1729
}
1830

1931
#' Check if a vector of well names is in the correct format.

man/format_wells.Rd

Lines changed: 0 additions & 24 deletions
This file was deleted.

man/normalize_wells.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-wells.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ test_that("function normalize_wells", {
55
wells2 <- c(0, 0)
66
expect2 <- as.character(c(NA, NA))
77
expect_equal(normalize_wells(wells2, 96), expect2)
8-
wells3 <- c("A01", " B02", "c03 ", " d0100", "E 50")
9-
expect3 <- c("A1", "B2", "C3", NA, NA)
10-
expect_equal(normalize_wells(wells3, 96), expect3)
8+
wells3 <- c("A01", " B02", "c03 ", " d0100", "E 50", "0", "A")
9+
expect3a <- c("A1", "B2", "C3", NA, NA, NA, NA)
10+
expect3b <- c("A1", "B2", "C3", "D100", "E50", NA, NA)
11+
expect_equal(normalize_wells(wells3, 96), expect3a)
12+
expect_equal(normalize_wells(wells3), expect3b)
1113
})
1214

1315
test_that("Function check_wells works", {

0 commit comments

Comments
 (0)