|
1 | 1 | #' Normalize a vector with well names. |
2 | 2 | #' |
3 | 3 | #' @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 |
6 | 13 | #' @export |
7 | 14 | #' @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")) |
9 | 17 | #' |
10 | 18 | #' |
11 | | -normalize_wells <- function(v, format) { |
| 19 | +normalize_wells <- function(v, format = NULL) { |
12 | 20 | v <- as.character(v) |> |
13 | 21 | stringr::str_remove_all(" ") |> |
14 | 22 | stringr::str_to_upper() |> |
15 | 23 | 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 |
17 | 29 | } |
18 | 30 |
|
19 | 31 | #' Check if a vector of well names is in the correct format. |
|
0 commit comments