knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", eval = TRUE )
'ir' is an R package to import, handle and preprocess infrared spectra. Infrared spectra are stored as list columns in data frames which enables efficient storage of metadata along with the spectra and using 'tidyverse' functions for data operations.
Spectra in the following formats can be imported:
csv
files with individual spectra.spc
files with individual spectra.Functions for spectral preprocessing and data handling:
You can install 'ir' from CRAN:
install.packages("ir")
You can install the development version of 'ir' from GitHub:
remotes::install_github(repo = "henningte/ir", ref = "dev")
Load 'ir':
# load ir package library(ir) # load additional packages needed for this tutorial library(ggplot2)
For brief introductions, see below and the two vignettes:
r rmarkdown::yaml_front_matter("vignettes/ir-introduction.Rmd")$title
r rmarkdown::yaml_front_matter("vignettes/ir-class.Rmd")$title
Here is an example preprocessing pipeline for the sample data in the package (ir_sample_data
) which does baseline correction, binning (bin width of 10), normalization (so that the maximum intensity value is 1 and the minimum intensity value is 0), and finally plots the preprocessed spectra for each sample and sample type:
ir_sample_data |> # data ir::ir_bc(method = "rubberband") |> # baseline correction ir::ir_bin(width = 10) |> # binning ir::ir_normalize(method = "zeroone") |> # normalization plot() + ggplot2::facet_wrap(~ sample_type) # plot
You can load the sample data with:
ir::ir_sample_data
ir_sample_data
is an object of class ir
. An Object of class ir
is a data frame where each row represents one infrared measurement and column spectra
contains the infrared spectra (one per row) as list column. This allows to store metadata along each spectrum (for example the N content for each sample) and to manipulate ir
objects with 'tidyverse' functions.
The column spectra
is a list column of data frames, meaning that each cell of spectra
contains a data frame which contains the data for one spectrum. For example, here are the first rows of the first spectrum in ir_smaple_data
:
# View the first ten rows of the first spectrum in ir_sample_data head(ir_sample_data$spectra[[1]])
Column x
contains values for the spectral channel (in this case wavenumbers [cm-1]) and column y
the corresponding intensity values.
Please cite this R package as:
Henning Teickner (
r format(Sys.Date(), "%Y")
). ir: Functions to Handle and Preprocess Infrared Spectra. DOI: 10.5281/zenodo.5747169. Accessedr format(Sys.Date(), "%d %b %Y")
. Online at https://zenodo.org/record/5747169.
The irpeat package provides functions to analyze infrared spectra of peat (humification indices, prediction models) and uses the 'ir' package to handle spectral data.
Text and figures : CC BY 4.0
Code : See the DESCRIPTION file
Data : CC BY 4.0 attribution requested in reuse. See the sources section for data sources and how to give credit to the original author(s) and the source.
We welcome contributions from everyone. Before you get started, please see our contributor guidelines. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
ir_sample_data
is derived from @Hodgkins.2018 and was reformatted to match the requirements of 'ir'. The original article containing the data can be downloaded from https://www.nature.com/articles/s41467-018-06050-2 and is distributed under the Creative Commons Attribution 4.0 International License (https://creativecommons.org/licenses/by/4.0/). The data on Klason lignin and holocellulose content are originally from @DelaCruz.2016.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.