R/all_ratios.R

#' Complete processing for Pb isotope ratio data.
#'
#' The function extracts, remove outliers and correct for mass bias Pb isotope ratio data included
#' in a .csv report generated by Perkin Elmer ELAN ICP-MS.
#'
#' @import data.table
#' @importFrom dplyr "%>%"
#'
#' @param filename A data set saved in csv format with "," as field separator and "." as decimal
#'   separator. Such file can be obtained from the .rep report provided by the instrument by opening
#'   it with a spreadsheet editor and saving it as .csv file using a local setting = EN-US or
#'   equivalent. The function identifies standard samples for bracketing when labelled as “SRM” and
#'   substitutes their names with “SRM981_X” where X is a progressive integer. Similarly, QC samples
#'   “CRM” are renamed as “CRM482_X”.
#'
#' @param report A string referring to the type of report generated by the instrument Accepted
#'   values are \code{"short"} or \code{"long"}. \itemize{ \item{\bold{Short}}{ reports have only
#'   information about the sample ID, data and time of the measure, a summary with average
#'   intensities and finally, the intensity values for each replicate.} \item{\bold{Long}}{ reports
#'   contain also information of the "short" counterpart and also some information about the
#'   measurement conditions. Additionally, the summary section is reported after the intensity
#'   values for each replicates. These reports are tipically produced when working in isotope ratio
#'   mode.} }
#'
#' @param print Logical. If \code{TRUE}, the result in printing on screen the ratios. \code{FALSE}
#'   is the default setting.
#'
#' @return A data.table containing Pb isotope ratios filtered for outliers and corrected for mass
#'   bias using the standard bracketing technique. \code{Pb20x20y} columns provide Pb ratio values
#'   for 20xPb/20yPb with \eqn{x, y = 6, 7, 8}. \code{Pb20x20y.U} columns stores the estimated
#'   extended uncertainty (\eqn{U = k u, k = 2}).
#'
#' @examples
#' file.short <- system.file("extdata", "sednya_2015.csv", package = "pbratios")
#' sednya.2015 <- all_ratios(file.short, report = "short", print = TRUE)
#'
#' @seealso \code{\link{extract_data}} \code{\link{calc_ratios}} \code{\link{corr_mbf}}
#'
#' @export
#'
all_ratios <- function(filename, report = c("short", "long"), print = c(FALSE, TRUE)) {
  report <- match.arg(report)

  data <- filename %>%
  extract_data(report = report) %>%
  calc_ratios %>%
  corr_mbf

  if (print == TRUE) data[]

}
# End of function
andreabz/pbratios documentation built on May 12, 2019, 2:42 a.m.