knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center" )
library(elco) library(magrittr) library(ggplot2)
This vignette shows how to
Import raw data files (csv files) as exported from the IRMS device in the lab.
Reformat the data to get a tidy data.frame
.
Check the data via plots.
Export the data and metadata as csv files in the tidy format.
Extract and export information on the standards measured alongside the samples.
Correct the calibration in case C contents and masses, or N contents and masses of samples do not match those of the standards used for the construction of the calibration models (i.e. in case of extrapolation).
Warn in case chromatogram peak areas are such small that they are accompanied by too much noise to make accurate enough estimates on isotopes and/or element contents.
Data import and reformatting are done with function elco:elco_irms_import_csv
:
# get names of files to import files <- list.files("./../inst/extdata/irms/", full.names = TRUE) # data import d <- elco::elco_irms_import_csv(files = files) # show first ten rows head(d) # change sample labels of standards to match the labels used by elco (elco::irms_standards) d$sample_label[d$sample_label == "BBOT_CN."] <- "BBOT"
The rows for all standards can be extracted using elco::elco_irms_extract_standards
# etract all rows corresponding to standards in d d_standards <- d %>% elco::elco_irms_extract_standards()
With function elco::elco_irms_write_standards
, the extracted values can be stored in an external rds file (can be imported with readRDS()
). New values will be appended to existing values. If initialize == TRUE
, a new file will b created if file
does not exist yet. Likewise, if initialize == FALSE
, but file
does not exist, this will throw an error.
# save the extracted standards in an external csv file d_standards %>% elco::elco_irms_write_standards(file = "d_standards.rds", initialize = TRUE, verbose = TRUE) # trying this again yields an error try( d_standards %>% elco::elco_irms_write_standards(file = "d_standards.rds", initialize = TRUE, verbose = TRUE) ) # but trying it again with initalize = TRUE will append the values, so that these are now doubled in file d_standards %>% elco::elco_irms_write_standards(file = "d_standards.rds", initialize = FALSE, verbose = TRUE)
d %>% dplyr::mutate( standard = purrr::map_lgl(d$sample_label, function(x) x %in% elco::irms_standards$standard_name), sample_label = factor(ifelse(standard, sample_label, "sample"), levels = c(elco::irms_standards$standard_name, "sample"))) %>% ggplot(aes(x = sample_label, y = `15N_area`)) + geom_point() + scale_y_log10()
# define target variable target_variable = "15N" d %>% elco::elco_irms_extract_standards() %>% dplyr::left_join(elco::irms_standards %>% dplyr::rename(sample_label = standard_name, target_ref = target_variable) %>% dplyr::select(sample_label, target_ref), by = "sample_label") %>% ggplot(aes(x = sample_label, y = as.numeric(`15N`))) + geom_boxplot() + geom_point(aes(y = as.numeric(target_ref)))
Plot the values of extracted standards over time in comparison to their expected values
# define target variable target_variable = "15N" d_standards %>% dplyr::left_join(elco::irms_standards %>% dplyr::rename(sample_label = standard_name, target_ref = target_variable) %>% dplyr::select(sample_label, target_ref), by = "sample_label") %>% ggplot(aes(x = time, y = as.numeric(`15N`))) + geom_point() + geom_path(size = 1) + geom_hline(aes(yintercept = as.numeric(target_ref))) + facet_wrap(~ sample_label)
Isotope signatures can be corrected with a heuristic procedure using elco::elco_irms_correct_isotopes
# correct isotopes d_corrected <- d %>% elco::elco_irms_correct_isotopes(isotope ="13C", t = 5, by_file = TRUE, plotit = TRUE) %>% elco::elco_irms_correct_isotopes(isotope ="15N", t = 5, by_file = TRUE, plotit = TRUE)
Mass fractions of C and N can be corrected with a heuristic procedure using elco::elco_irms_correct_elements
# correct isotopes d_corrected <- d_corrected %>% elco::elco_irms_correct_elements(element ="C", standards = elco::irms_standards$standard_name, by_file = TRUE, plotit = TRUE) %>% elco::elco_irms_correct_elements(element ="N", standards = elco::irms_standards$standard_name, by_file = TRUE, plotit = TRUE)
This Rmarkdown template is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
Title: Importing and Manipulating IRMS data
Authors: Henning Teickner, Klaus-Holger Knorr
Date: 2020-10-01
Data: The data are licensed under the CC-BY-SA-4.0 license. All data for elco were provided by @Gaka.2019.
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.