#' Read and clean ICP-MS data files generated by the iCAP-RQ
#'
#' @param path Relative path to the ICP-MS (.xlsx) input files.
#' @param int_stds A character vector of internal standards to be removed from the output.
#'
#' @return A tibble with columns `date`, `sample`, `value`, and `param`.
#' @importFrom readxl read_excel
#' @importFrom rlang set_names .data
#' @importFrom tidyr pivot_longer
#' @importFrom tidyselect matches
#' @importFrom dplyr filter transmute
#' @importFrom stringr str_extract str_remove str_detect
#' @importFrom purrr map_dfr
#' @export
#'
#' @examples
#' path <- system.file("extdata", package = "fffprocessr")
#' load_direct_quant(path = paste0(path, "/direct_quantification"))
load_direct_quant <- function(path, int_stds = c("45Sc", "115In", "159Tb")) {
path %>%
list.files(pattern = "\\.xlsx$", full.names = TRUE) %>%
set_names() %>%
map_dfr(read_excel, .id = "file") %>%
filter(.data$`Sample Type` == "UNKNOWN") %>%
pivot_longer(matches("^\\d"), names_to = "param") %>%
filter(!str_detect(.data$param, paste(int_stds, collapse = "|"))) %>%
transmute(
date = str_extract(.data$file, "\\d{4}-\\d{2}-\\d{2}") %>%
as.Date(),
sample = .data$Label,
value = str_remove(.data$value, ",") %>% as.numeric(),
param = str_extract(.data$param, "\\d+[A-Z][a-z]?")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.