Title: | Functions to Handle and Preprocess Infrared Spectra |
---|---|
Description: | Functions to import and handle infrared spectra (import from '.csv' and Thermo Galactic's '.spc', baseline correction, binning, clipping, interpolating, smoothing, averaging, adding, subtracting, dividing, multiplying, plotting). |
Authors: | Henning Teickner [aut, cre, cph] |
Maintainer: | Henning Teickner <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2024-11-22 03:53:23 UTC |
Source: | https://github.com/henningte/ir |
ir
objects by column valuesArrange rows in ir
objects by column values
arrange.ir(.data, ..., .by_group = FALSE)
arrange.ir(.data, ..., .by_group = FALSE)
.data |
An object of class |
... |
< |
.by_group |
If |
.data
with arranged rows.
Other tidyverse:
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## arrange dplyr::arrange(ir_sample_data, dplyr::desc(sample_type))
## arrange dplyr::arrange(ir_sample_data, dplyr::desc(sample_type))
ir
objectsBind rows of ir
objects
## S3 method for class 'ir' rbind(..., deparse.level = 1) ## S3 method for class 'ir' cbind(..., deparse.level = 1)
## S3 method for class 'ir' rbind(..., deparse.level = 1) ## S3 method for class 'ir' cbind(..., deparse.level = 1)
... |
Objects to bind together. For |
deparse.level |
An integer value; see |
An object of class ir
. rbind
returns all input
ir
objects combined row-wise. cbind
returns the input ir
object and the other objects combined column-wise.
# rbind rbind(ir_sample_data, ir_sample_data) rbind(ir_sample_data %>% dplyr::select(spectra), ir_sample_data %>% dplyr::select(spectra)) # cbind cbind(ir_sample_data, a = seq_len(nrow(ir_sample_data)))
# rbind rbind(ir_sample_data, ir_sample_data) rbind(ir_sample_data %>% dplyr::select(spectra), ir_sample_data %>% dplyr::select(spectra)) # cbind cbind(ir_sample_data, a = seq_len(nrow(ir_sample_data)))
ir
objectsSubset distinct/unique rows in ir
objects
distinct.ir(.data, ..., .keep_all = FALSE)
distinct.ir(.data, ..., .keep_all = FALSE)
.data |
An object of class |
... |
< |
.keep_all |
If |
.data
with distinct rows.
Other tidyverse:
arrange.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## distinct dplyr::distinct(rep(ir_sample_data, 2))
## distinct dplyr::distinct(rep(ir_sample_data, 2))
ir
object into multiple columns using regular expression groupsExtract a character column in an ir
object into multiple columns using regular expression groups
extract.ir( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... )
extract.ir( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... )
data |
An object of class |
col |
Column name or position. This is passed to
This argument is passed by expression and supports quasiquotation (you can unquote column names or column positions). |
into |
Names of new variables to create as character vector.
Use |
regex |
A string representing a regular expression used to extract the
desired values. There should be one group (defined by |
remove |
If |
convert |
If NB: this will cause string |
... |
Additional arguments passed on to methods. |
data
with an extracted character column. See
tidyr::extract()
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## extract ir_sample_data %>% tidyr::extract( id_sample, "a" )
## extract ir_sample_data %>% tidyr::extract( id_sample, "a" )
ir
objectFiltering joins for an ir
object
semi_join.ir(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never")) anti_join.ir(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
semi_join.ir(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never")) anti_join.ir(x, y, by = NULL, copy = FALSE, ..., na_matches = c("na", "never"))
x |
An object of class |
y |
A data frame. |
by |
A character vector of variables to join by. If To join by different variables on To join by multiple variables, use a vector with length > 1.
For example, To perform a cross-join, generating all combinations of |
copy |
If |
... |
Other parameters passed onto methods. |
na_matches |
Should The default, Use |
x
and y
joined. If the spectra
column is renamed, the ir
class is dropped. See filter-joins
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## semi_join set.seed(234) dplyr::semi_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## anti_join set.seed(234) dplyr::anti_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" )
## semi_join set.seed(234) dplyr::semi_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## anti_join set.seed(234) dplyr::anti_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" )
ir
objects using column valuesSubset rows in ir
objects using column values
filter.ir(.data, ..., .preserve = FALSE)
filter.ir(.data, ..., .preserve = FALSE)
.data |
An object of class |
... |
< |
.preserve |
Relevant when the |
.data
with filtered rows.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## filter dplyr::filter(ir_sample_data, sample_type == "office paper")
## filter dplyr::filter(ir_sample_data, sample_type == "office paper")
ir
objects by one or more variablesGroup rows in ir
objects by one or more variables
group_by.ir( .data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data) ) ungroup.ir(.data, ...)
group_by.ir( .data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data) ) ungroup.ir(.data, ...)
.data |
An object of class |
... |
In |
.add |
When This argument was previously called |
.drop |
Drop groups formed by factor levels that don't appear in the
data? The default is |
.data
with grouped rows (group_by.ir()
) or ungrouped rows
(ungroup.ir()
).
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## group_by dplyr::group_by(ir_sample_data, sample_type) ## ungroup dplyr::ungroup(dplyr::group_by(ir_sample_data, sample_type))
## group_by dplyr::group_by(ir_sample_data, sample_type) ## ungroup dplyr::ungroup(dplyr::group_by(ir_sample_data, sample_type))
ir_add
takes two objects of class ir
, x
and
y
, and adds the intensity values of spectra in matching rows from
y
to that of x
.
ir_add(x, y)
ir_add(x, y)
x |
An object of class |
y |
An object of class |
x
where for each spectrum the respective intensity values in
y
are added.
x1 <- ir::ir_add(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_add(ir::ir_sample_data, ir::ir_sample_data[1, ]) # adding a numeric value to an object of class `ir`. x3 <- ir::ir_add(ir::ir_sample_data, 1) # adding a numeric vector from an object of class `ir`. x4 <- ir::ir_add( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
x1 <- ir::ir_add(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_add(ir::ir_sample_data, ir::ir_sample_data[1, ]) # adding a numeric value to an object of class `ir`. x3 <- ir::ir_add(ir::ir_sample_data, 1) # adding a numeric vector from an object of class `ir`. x4 <- ir::ir_add( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
ir
ir_as_ir
ir the generic to convert an object to an object of class
ir
.
ir_as_ir(x, ...) ## S3 method for class 'ir' ir_as_ir(x, ...) ## S3 method for class 'data.frame' ir_as_ir(x, ...)
ir_as_ir(x, ...) ## S3 method for class 'ir' ir_as_ir(x, ...) ## S3 method for class 'data.frame' ir_as_ir(x, ...)
x |
An object. |
... |
Further arguments passed to individual methods.
|
An object of class ir
.
# conversion from an ir object ir::ir_sample_data %>% ir_as_ir() # conversion from a data frame x_ir <- ir::ir_sample_data x_df <- x_ir %>% ir_drop_spectra() %>% dplyr::mutate( spectra = x_ir$spectra ) %>% ir_as_ir() # check that ir_as_ir preserves the input class ir_sample_data %>% structure(class = setdiff(class(.), "ir")) %>% dplyr::group_by(sample_type) %>% ir_as_ir()
# conversion from an ir object ir::ir_sample_data %>% ir_as_ir() # conversion from a data frame x_ir <- ir::ir_sample_data x_df <- x_ir %>% ir_drop_spectra() %>% dplyr::mutate( spectra = x_ir$spectra ) %>% ir_as_ir() # check that ir_as_ir preserves the input class ir_sample_data %>% structure(class = setdiff(class(.), "ir")) %>% dplyr::group_by(sample_type) %>% ir_as_ir()
ir_average
averages infrared spectra within a user-defined group. NA
values are omitted by default.
ir_average(x, ..., na.rm = TRUE, .groups = "drop")
ir_average(x, ..., na.rm = TRUE, .groups = "drop")
x |
An object of class |
... |
Variables in |
na.rm |
A logical value indicating if |
.groups |
Grouping structure of the result.
When
In addition, a message informs you of that choice, unless the result is ungrouped,
the option "dplyr.summarise.inform" is set to |
An object of class ir
where spectra have been averaged within
groups defined by ...
.
# average the sample data spectra across sample types x <- ir_sample_data %>% ir_average(sample_type)
# average the sample data spectra across sample types x <- ir_sample_data %>% ir_average(sample_type)
ir_bc
performs baseline correction for infrared spectra. Baseline
correction is either performed by using a polynomial with user defined
degree fitted to each spectrum (see ChemoSpec::baselineSpectra()
), or by
using a rubberband function that is fitted to each spectrum (see
hyperSpec::spc.rubberband()
), or using a Savitzky-Golay smoothed version of
the input spectra (see ir_bc_sg()
).
ir_bc(x, method = "rubberband", ..., return_bl = FALSE)
ir_bc(x, method = "rubberband", ..., return_bl = FALSE)
x |
An object of class |
method |
A character value indicating which method should be used
for baseline correction. If |
... |
Further arguments passed to |
return_bl |
A logical value indicating if for each spectrum the baseline
should be returned instead of the corrected intensity values
( |
An object of class ir
with the baseline corrected spectra, or if
return_bl = TRUE
, the baselines instead of the spectra in column spectra
.
library(dplyr) # rubberband baseline correction x1 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "rubberband") # polynomial baseline correction x2 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "polynomial", degree = 2) # Savitzky-Golay baseline correction x3 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "sg", p = 3, n = 199, ts = 1, m = 0) # return the baseline instead of the baseline corrected spectra x1_bl <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "rubberband", return_bl = TRUE)
library(dplyr) # rubberband baseline correction x1 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "rubberband") # polynomial baseline correction x2 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "polynomial", degree = 2) # Savitzky-Golay baseline correction x3 <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "sg", p = 3, n = 199, ts = 1, m = 0) # return the baseline instead of the baseline corrected spectra x1_bl <- ir::ir_sample_data %>% dplyr::slice(1:10) %>% ir::ir_bc(method = "rubberband", return_bl = TRUE)
ir_bc_polynomial
performs baseline correction for infrared
spectra using a polynomial.
ir_bc_polynomial
is an extended wrapper function
for ChemoSpec::baselineSpectra()
.
ir_bc_polynomial(x, degree = 2, return_bl = FALSE)
ir_bc_polynomial(x, degree = 2, return_bl = FALSE)
x |
An object of class |
degree |
An integer value representing the degree of the polynomial used for baseline correction. |
return_bl |
A logical value indicating if for each spectrum the baseline
should be returned instead of the corrected intensity values
( |
An object of class ir
with the baseline corrected spectra if
returnbl = FALSE
or the baselines if returnbl = TRUE
.
x2 <- ir::ir_sample_data %>% ir::ir_bc_polynomial(degree = 2, return_bl = FALSE)
x2 <- ir::ir_sample_data %>% ir::ir_bc_polynomial(degree = 2, return_bl = FALSE)
ir_bc_rubberband
performs baseline correction for infrared spectra
using a rubberband algorithm. ir_bc_rubberband
is an extended wrapper
function for hyperSpec::spc.rubberband()
.
ir_bc_rubberband(x, return_bl = FALSE)
ir_bc_rubberband(x, return_bl = FALSE)
x |
An object of class |
return_bl |
A logical value indicating if for each spectrum the baseline
should be returned instead of the corrected intensity values
( |
An object of class ir
with the baseline corrected spectra and,
if returnbl = TRUE
, the baselines.
x1 <- ir::ir_sample_data %>% ir::ir_bc_rubberband(return_bl = FALSE)
x1 <- ir::ir_sample_data %>% ir::ir_bc_rubberband(return_bl = FALSE)
ir_bc_sg
computes a smoothed version of spectra using
ir_smooth()
with method = "sg"
and uses this as baseline
which is subtracted from the spectra to perform a baseline correction
(Lasch 2012).
ir_bc_sg(x, ..., return_bl = FALSE)
ir_bc_sg(x, ..., return_bl = FALSE)
x |
An object of class |
... |
Arguments passed to |
return_bl |
A logical value indicating if for each spectrum the baseline
should be returned instead of the corrected intensity values
( |
An object of class ir
with the baseline corrected spectra and,
if returnbl = TRUE
, the baselines.
Lasch P (2012). “Spectral Pre-Processing for Biomedical Vibrational Spectroscopy and Microspectroscopic Imaging.” Chemometrics and Intelligent Laboratory Systems, 117, 100–114. ISSN 01697439, doi:10.1016/j.chemolab.2012.03.011.
x <- ir::ir_sample_data %>% ir::ir_bc_sg(p = 3, n = 199, ts = 1, m = 0, return_bl = FALSE)
x <- ir::ir_sample_data %>% ir::ir_bc_sg(p = 3, n = 199, ts = 1, m = 0, return_bl = FALSE)
ir_bin
bins intensity values of infrared spectra into bins of a
defined width or into a defined number of bins.
ir_bin(x, width = 10, new_x_type = "start")
ir_bin(x, width = 10, new_x_type = "start")
x |
An object of class |
width |
An integer value indicating the wavenumber width of each resulting bin. |
new_x_type |
A character value denoting how new wavenumber values for
the computed bins should be stored in the spectra of
|
If a wavenumber value exactly matches the boundary of a bin window, the respective intensity value will be assigned to both neighboring bins.
An object of class ir
where spectra have been binned.
# new wavenumber values are the first wavenumber value for each bin x1 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "start") # new wavenumber values are the last wavenumber value for each bin x2 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "mean") # new wavenumber values are the average of the wavenumber values assigned to # each bin x3 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "end") # compare wavenumber values for first spectra. cbind(x1$spectra[[1]]$x, x2$spectra[[1]]$x, x3$spectra[[1]]$x)
# new wavenumber values are the first wavenumber value for each bin x1 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "start") # new wavenumber values are the last wavenumber value for each bin x2 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "mean") # new wavenumber values are the average of the wavenumber values assigned to # each bin x3 <- ir::ir_sample_data %>% ir_bin(width = 50, new_x_type = "end") # compare wavenumber values for first spectra. cbind(x1$spectra[[1]]$x, x2$spectra[[1]]$x, x3$spectra[[1]]$x)
ir_clip
clips infrared spectra to a new, specified, wavenumber range
or multiple new specified wavenumber ranges.
ir_clip(x, range)
ir_clip(x, range)
x |
An object of class |
range |
A
If |
An object of class ir
where spectra have been clipped.
## clipping with one range # define clipping range range <- data.frame(start = 900, end = 1000) # clip x <- ir::ir_sample_data %>% ir::ir_clip(range = range) ## clipping with mutliple ranges range <- data.frame(start = c(900, 1900), end = c(1000, 2200)) # clip x <- ir::ir_sample_data %>% ir::ir_clip(range = range)
## clipping with one range # define clipping range range <- data.frame(start = 900, end = 1000) # clip x <- ir::ir_sample_data %>% ir::ir_clip(range = range) ## clipping with mutliple ranges range <- data.frame(start = c(900, 1900), end = c(1000, 2200)) # clip x <- ir::ir_sample_data %>% ir::ir_clip(range = range)
ir_correct_atmosphere
takes two objects of class ir
with the same number
of spectra in each and corrects the spectra of the first object with the
spectra of the second object according to the procedure presented by
(Perez-Guaita et al. 2013).
ir_correct_atmosphere( x, ref, wn1, wn2, do_interpolate = FALSE, start = NULL, dw = 1, warn = TRUE )
ir_correct_atmosphere( x, ref, wn1, wn2, do_interpolate = FALSE, start = NULL, dw = 1, warn = TRUE )
x |
An object of class |
ref |
An object of class |
wn1 |
A numeric value representing the first wavenumber value to use as reference point (Perez-Guaita et al. 2013). Examples used by Perez-Guaita et al. (2013) are:
|
wn2 |
A numeric value representing the second wavenumber value to use as reference point (Perez-Guaita et al. 2013). Examples used by Perez-Guaita et al. (2013) are:
|
do_interpolate |
A logical value indicating if |
start |
See |
dw |
See |
warn |
A logical value indicating whether warnings about mismatching
wavenumber values should be displayed ( |
x
corrected with the reference spectra in ref
.
The function was not tested yet.
There are no references for Rd macro \insertAllCites
on this help page.
ir_correct_atmosphere(ir_sample_data, ir_sample_data, wn1 = 2361, wn2 = 2349)
ir_correct_atmosphere(ir_sample_data, ir_sample_data, wn1 = 2361, wn2 = 2349)
ir_divide
takes two objects of class ir
, x
and
y
, and divides their intensity values, or it takes one object of
class ir
, x
, and one numeric value, y
, and divides
all intensity values in x
by y
.
ir_divide(x, y)
ir_divide(x, y)
x |
An object of class |
y |
An object of class |
x
where for each spectrum intensity values are divided by
the respective intensity values in y
(if y
is an object of
class ir
), or where all intensity values are divided by y
if
y
is a numeric value.
# division with y as ir object x1 <- ir::ir_divide(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_divide(ir::ir_sample_data, ir::ir_sample_data[1, ]) # division with y being a numeric value x3 <- ir::ir_divide(ir::ir_sample_data, y = 20) # division with y being a numeric vector x4 <- ir::ir_divide( ir::ir_sample_data, seq(from = 0.1, to = 2, length.out = nrow(ir::ir_sample_data)) )
# division with y as ir object x1 <- ir::ir_divide(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_divide(ir::ir_sample_data, ir::ir_sample_data[1, ]) # division with y being a numeric value x3 <- ir::ir_divide(ir::ir_sample_data, y = 20) # division with y being a numeric vector x4 <- ir::ir_divide( ir::ir_sample_data, seq(from = 0.1, to = 2, length.out = nrow(ir::ir_sample_data)) )
spectra
from an object is of class ir
ir_drop_spectra
removes the column spectra
from an object
of class ir
and removes the "ir"
class attribute.
ir_drop_spectra(x)
ir_drop_spectra(x)
x |
An object of class |
x
without column spectra
and without "ir"
class
attribute.
ir::ir_sample_data %>% ir_drop_spectra()
ir::ir_sample_data %>% ir_drop_spectra()
ir
objects for export to csv
Prepares ir
objects for export to csv
files. To export ir
objects to
csv
, the spectra
column has to be converted to an own data frame and be
exported separately from the metadata.
When preparing metadata for export, ir_export_prepare
takes care of
separating measurement units and measurement errors in columns of class
units::units, errors::errors, and quantities::quantities (see the
examples).
ir_export_prepare( x, what = "metadata", measurement_id = as.character(seq_len(nrow(x))) )
ir_export_prepare( x, what = "metadata", measurement_id = as.character(seq_len(nrow(x))) )
x |
An object of class |
what |
A character value defining what to prepare for export.
If |
measurement_id |
A character vector an element for each row in |
A data frame.
This function superseded irp_export_prepare()
from the
'irpeat' package.
x_spectra <- ir_export_prepare(ir_sample_data[1:5, ], what = "spectra") x_metadata <- ir_export_prepare(ir_sample_data[1:5, ], what = "metadata")
x_spectra <- ir_export_prepare(ir_sample_data[1:5, ], what = "spectra") x_metadata <- ir_export_prepare(ir_sample_data[1:5, ], what = "metadata")
ir_flat
ir_flatten_clean
takes an object of class ir_flat
and either
returns all non-empty spectra or all empty spectra as object of class
ir_flat
.
ir_flat_clean(x, return_empty = FALSE)
ir_flat_clean(x, return_empty = FALSE)
x |
An object of class |
return_empty |
A logical value indicating if the empty spectra should be
returned ( |
x
where empty spectra are dropped (if return_empty = TRUE
) or
only empty spectra are returned (return_empty = FALSE
).
ir
to objects of class ir_flat
ir_flatten
takes and object of class ir
, extracts the
spectra
column and combines the spectra into an object of class
ir_flat
. Metadata are not retained during flattening.
ir_flatten(x, measurement_id = as.character(seq_len(nrow(x))))
ir_flatten(x, measurement_id = as.character(seq_len(nrow(x))))
x |
An object of class |
measurement_id |
A character vector an element for each row in |
An object of class ir_flat
.
x_flat <- ir::ir_sample_data %>% ir::ir_flatten()
x_flat <- ir::ir_sample_data %>% ir::ir_flatten()
ir
object for specific spectral channelsir_get_intensity
extracts intensity values of spectra for specific
user-defined spectral channels ("x axis values", e.g. wavenumber values).
ir_get_intensity(x, wavenumber, warn = TRUE)
ir_get_intensity(x, wavenumber, warn = TRUE)
x |
An object of class |
wavenumber |
A numeric vector with spectral channels ("x axis values", e.g. wavenumber values) for which to extract intensities. |
warn |
logical value indicating if warnings should be displayed
( |
x
with an additional column intensity
.
x$intensity
is a list column with each element representing a
data.frame
with a row for each element in wavenumber
and two
columns:
The "x axis values" extracted with
ir_get_wavenumberindex()
applied on wavenumber
and the
corresponding spectrum in x
.
The extracted intensity values
.
x <- ir::ir_sample_data %>% ir::ir_get_intensity(wavenumber = 1090)
x <- ir::ir_sample_data %>% ir::ir_get_intensity(wavenumber = 1090)
ir
ir_get_spectrum
extracts selected spectra from an object of class ir
.
ir_get_spectrum(x, what)
ir_get_spectrum(x, what)
x |
An object of class |
what |
A numeric vector with each element representing a row in |
An integer vector with the same length as wavenumber
with the
row indices of x
corresponding to the wavenumber values in wavenumber
.
x <- ir::ir_sample_data %>% ir::ir_get_spectrum(what = c(5, 9))
x <- ir::ir_sample_data %>% ir::ir_get_spectrum(what = c(5, 9))
ir_get_wavenumberindex
gets for a defined wavenumber value or set of
wavenumber values the corresponding indices (row number) in an object of
class ir
that has been flattened with ir_flatten()
. If the
specified wavenumber values do not match exactly the wavenumber values in the
ir
object, the indices for the next wavenumber values will be
returned, along with a warning.
ir_get_wavenumberindex(x, wavenumber, warn = TRUE)
ir_get_wavenumberindex(x, wavenumber, warn = TRUE)
x |
A data.frame with a column x representing the x units of a spectrum
or several spectra (e.g. in the form of an object of class
|
wavenumber |
A numeric vector with wavenumber values for which to get indices. |
warn |
logical value indicating if warnings should be displayed
( |
An integer vector with the same length as wavenumber
with the
row indices of x
corresponding to the wavenumber values in wavenumber
.
x_index_1090 <- ir::ir_sample_data %>% ir::ir_flatten() %>% ir::ir_get_wavenumberindex(wavenumber = 1090)
x_index_1090 <- ir::ir_sample_data %>% ir::ir_flatten() %>% ir::ir_get_wavenumberindex(wavenumber = 1090)
ir_import_csv
imports raw infrared spectra from one or more .csv
file
that contains at least one spectrum, with x axis values (e.g. wavenumbers) in
the first column and intensity values of spectra in remaining columns. Note
that the function does not perform any checks for the validity of the content
read from the .csv file.
ir_import_csv(filenames, sample_id = "from_filenames", ...)
ir_import_csv(filenames, sample_id = "from_filenames", ...)
filenames |
A character vector representing the complete paths to
the |
sample_id |
Either:
|
... |
Further arguments passed to
|
An object of class ir
containing the
infrared spectra extracted from the .csv
file(s).
# import data from csv files d <- ir::ir_import_csv( system.file(package = "ir", "extdata/klh_hodgkins_mir.csv"), sample_id = "from_colnames")
# import data from csv files d <- ir::ir_import_csv( system.file(package = "ir", "extdata/klh_hodgkins_mir.csv"), sample_id = "from_colnames")
ir_import_spc
imports raw infrared spectra from a Thermo Galactic's
.spc
file or several of such files. ir_import_spc
is a wrapper
function to hyperSpec::read.spc()
.
ir_import_spc(filenames, log.txt = TRUE)
ir_import_spc(filenames, log.txt = TRUE)
filenames |
A character vector representing the complete paths to
the |
log.txt |
A logical value indicating whether to import metadata ( |
Currently, log.txt
must be set to FALSE
due to a bug in
hyperSpec::read.spc()
. This bug fill be fixed in the upcoming weeks and
currently can be circumvented by using the development version of 'hyperSpec'.
See https://github.com/r-hyperspec/hyperSpec/issues/80.
An object of class ir
containing the
infrared spectra extracted from the .spc
file(s) and the metadata as
extracted by hyperSpec::read.spc()
. Metadata variables are:
An integer value representing the number of scans.
The detection gain factor.
The scan speed [kHz].
The wavenumber of the laser.
The name of the detector.
The name of the infrared radiation source.
The duration of purge delay before a measurement [s].
A numeric value representing the zero filling factor.
The name of the apodisation function.
The exponentiation factor used for file compression.
The number of data points in the spectrum
The type of the x variable.
The type of the y variable.
A POSIXct representing the measurement date and time.
The name of the measurement device.
# import a sample .spc file x <- ir::ir_import_spc( system.file("extdata/1.spc", package = "ir"), log.txt = FALSE )
# import a sample .spc file x <- ir::ir_import_spc( system.file("extdata/1.spc", package = "ir"), log.txt = FALSE )
ir
object for new wavenumber valuesir_interpolate
interpolates intensity values for infrared spectra for
new wavenumber values.
ir_interpolate(x, start = NULL, dw = 1)
ir_interpolate(x, start = NULL, dw = 1)
x |
An object of class |
start |
A numerical value indicating the start wavenumber value relative
to which new wavenumber values will be interpolated. The value is not allowed
to be < |
dw |
A numerical value representing the desired wavenumber value difference between adjacent values. |
An object of class ir
containing the interpolated spectra. Any
NA
values resulting from interpolation will be automatically dropped.
x <- ir::ir_sample_data %>% ir::ir_interpolate(start = NULL, dw = 1)
x <- ir::ir_sample_data %>% ir::ir_interpolate(start = NULL, dw = 1)
ir
objectir_interpolate_region
linearly interpolates a user-defined region in
infrared spectra.
ir_interpolate_region(x, range)
ir_interpolate_region(x, range)
x |
An object of class |
range |
A
For each row in |
x
with the defined wavenumber region(s) interpolated linearly.
# interpolation range range <- data.frame(start = 1000, end = 1500) # do the interpolation x <- ir::ir_sample_data %>% ir::ir_interpolate_region(range = range)
# interpolation range range <- data.frame(start = 1000, end = 1500) # do the interpolation x <- ir::ir_sample_data %>% ir::ir_interpolate_region(range = range)
ir_multiply
takes two objects of class ir
, x
and
y
, and multiplies their intensity values, or it takes one object of
class ir
, x
, and one numeric value, y
, and multiplies
all intensity values in x
with y
.
ir_multiply(x, y)
ir_multiply(x, y)
x |
An object of class |
y |
An object of class |
x
where for each spectrum intensity values are multiplied with
the respective intensity values in y
(if y
is an object of
class ir
), or where all intensity values are multiplied with y
if y
is a numeric value.
# multiplication with y as ir object x1 <- ir::ir_multiply(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_multiply(ir::ir_sample_data, ir::ir_sample_data[1, ]) # multiplication with y being a numeric value x3 <- ir::ir_multiply(ir::ir_sample_data, y = -1) # multiplication with y being a numeric vector x4 <- ir::ir_multiply( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
# multiplication with y as ir object x1 <- ir::ir_multiply(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_multiply(ir::ir_sample_data, ir::ir_sample_data[1, ]) # multiplication with y being a numeric value x3 <- ir::ir_multiply(ir::ir_sample_data, y = -1) # multiplication with y being a numeric vector x4 <- ir::ir_multiply( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
ir
ir_new_ir
is the constructor function for objects of class
ir
.
An object of class ir
is a tibble::tbl_df()
with a
sample in each row and a list column containing spectra for each sample.
ir_new_ir(spectra, metadata = tibble::tibble())
ir_new_ir(spectra, metadata = tibble::tibble())
spectra |
A named list in which each element contains spectral data
for one measurement. Each list element must be a |
metadata |
An optional |
An object of class ir
with the following columns:
A list column identical to spectra
.
Additional columns contained in metadata
.
ir_new_ir( spectra = ir_sample_data$spectra, metadata = ir_sample_data %>% dplyr::select(-spectra) )
ir_new_ir( spectra = ir_sample_data$spectra, metadata = ir_sample_data %>% dplyr::select(-spectra) )
ir_flat
ir_new_ir_flat
is the constructor function for objects of class ir_flat
.
An object of class ir_flat
is a data.frame
where the first
column ("x"
) contains unique x values of spectra (e.g. wavenumbers)
and all remaining columns represent intensity values from spectra
corresponding to the x values.
ir_new_ir_flat(x)
ir_new_ir_flat(x)
x |
A |
An object of class ir_flat
.
x_flat <- ir::ir_sample_data %>% ir::ir_flatten()
x_flat <- ir::ir_sample_data %>% ir::ir_flatten()
ir
objectir_normalize
normalizes the intensity values of infrared spectra.
Spectra can be normalized in three ways (value for argument method
):
Normalization so that the intensity values range in [0;1]. Note that for different spectra, for different wavenumber values the intensity may be 1 after normalization, depending on the location of the peak with the maximum height.
Normalization so that the intensity values of each spectrum sum to 1. Note that in the case of negative intensities values, these will be count as negative values during summation.
Normalization so that the intensity at a specified wavenumber value has value 1 and the minimum intensity value is 0.
ir_normalize(x, method = "area") ir_normalise(x, method = "area")
ir_normalize(x, method = "area") ir_normalise(x, method = "area")
x |
An object of class |
method |
A character value specifying which normalization method to
apply. If |
An object of class ir
representing a normalized version of
x
.
# with method = "area" x <- ir::ir_sample_data %>% ir::ir_normalize(method = "area") # normalizing to a specific peak x <- ir::ir_sample_data %>% ir::ir_normalize(method = 1090)
# with method = "area" x <- ir::ir_sample_data %>% ir::ir_normalize(method = "area") # normalizing to a specific peak x <- ir::ir_sample_data %>% ir::ir_normalize(method = 1090)
ir
ir_remove_missing
takes and object of class ir
and removes all
rows in the data.frame
s of the list column spectra
that have
NA
intensity values (column y
). Additionally, one can specify
to remove rows in the ir
object to discard if they contain empty
spectra.
ir_remove_missing(x, remove_rows = FALSE)
ir_remove_missing(x, remove_rows = FALSE)
x |
An object of class |
remove_rows |
A logical value indicating if rows in |
x
with cleaned spectra.
# create sample data with some missing rows and one entire missing spectra x <- ir::ir_sample_data x$spectra[[1]] <- x$spectra[[1]][0, ] x$spectra[[2]][1:100, "y"] <- NA_real_ # remove missing values (but remove no rows in x) x1 <- x %>% ir::ir_remove_missing(remove_rows = FALSE) # remove missing values (and remove rows in x if a compete spectrum is # missing) x2 <- x %>% ir::ir_remove_missing(remove_rows = TRUE) nrow(x) nrow(x1) nrow(x2)
# create sample data with some missing rows and one entire missing spectra x <- ir::ir_sample_data x$spectra[[1]] <- x$spectra[[1]][0, ] x$spectra[[2]][1:100, "y"] <- NA_real_ # remove missing values (but remove no rows in x) x1 <- x %>% ir::ir_remove_missing(remove_rows = FALSE) # remove missing values (and remove rows in x if a compete spectrum is # missing) x2 <- x %>% ir::ir_remove_missing(remove_rows = TRUE) nrow(x) nrow(x1) nrow(x2)
ir
A sample object of class ir
. The data set
contains ATR-MIR spectra for a set of organic reference materials
along with their metadata (types of samples and a description) and
accessory data (Klason lignin mass fraction and holocellulose mass fraction).
ir_sample_data
ir_sample_data
A data frame with 58 rows and 7 variables:
An integer vector with a unique id for each spectrum.
A character vector with a unique id for each sample.
A character vector containing class labels for the types of reference materials.
A character vector containing comments to each sample.
A numeric vector with the mass fractions of Klason lignin in each sample.
A numeric vector with the mass fractions of holocellulose in each sample.
See ir_new_ir()
.
The data set was derived from https://www.nature.com/articles/s41467-018-06050-2 and published by Hodgkins et al. (2018) under the CC BY 4.0 license https://creativecommons.org/licenses/by/4.0/. Hodgkins et al. (2018) originally derived the data on Klason Lignin and Holocellulose content from De La Cruz, Florentino B. et al. (2016).
De La Cruz, Florentino B., Osborne J, Barlaz MA (2016).
“Determination of Sources of Organic Matter in Solid Waste by Analysis of Phenolic Copper Oxide Oxidation Products of Lignin.”
Journal of Environmental Engineering, 142(2), 04015076.
ISSN 0733-9372, doi:10.1061/(ASCE)EE.1943-7870.0001038.
Hodgkins SB, Richardson CJ, Dommain R, Wang H, Glaser PH, Verbeke B, Winkler BR, Cobb AR, Rich VI, Missilmani M, Flanagan N, Ho M, Hoyt AM, Harvey CF, Vining SR, Hough MA, Moore TR, Richard PJH, De La Cruz, Florentino B., Toufaily J, Hamdan R, Cooper WT, Chanton JP (2018).
“Tropical peatland carbon storage linked to global latitudinal trends in peat recalcitrance.”
Nature communications, 9(1), 3640.
doi:10.1038/s41467-018-06050-2.
ir
objectir_smooth
applies smoothing functions to infrared spectra.
ir_smooth
either performs Savitzky-Golay smoothing, using on
signal::sgolayfilt()
, or Fourier smoothing using
fda::smooth.basis()
. Savitzky-Golay smoothing can
also be used to compute derivatives of spectra.
ir_smooth( x, method = "sg", p = 3, n = p + 3 - p%%2, ts = 1, m = 0, k = 111, ... )
ir_smooth( x, method = "sg", p = 3, n = p + 3 - p%%2, ts = 1, m = 0, k = 111, ... )
x |
An object of class |
method |
A character value specifying which smoothing method to apply.
If |
p |
An integer value representing the filter order (i.e. the degree of
the polynom) of the Savitzky-Golay filter if |
n |
An odd integer value representing the length (i.e. the number of
wavenumber values used to construct the polynom) of the Savitzky-Golay filter
if |
ts |
time scaling factor. See |
m |
An integer value representing the mth derivative to compute. This
option can be used to compute derivatives of spectra. See
|
k |
A positive odd integer representing the number of Fourier basis
functions to use as smoothed representation of the spectra if
|
... |
additional arguments (ignored). |
When x
contains spectra with different wavenumber values, the
filters are applied for each spectra only on existing wavenumber values. This
means that the filter window (if method == "sg"
) will be different for
these different spectra.
x
with smoothed spectra.
#' # Savitzky-Golay smoothing x1 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "sg", p = 3, n = 51, ts = 1, m = 0) # Fourier smoothing x2 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "fourier", k = 21) # computing derivative spectra with Savitzky-Golay smoothing (here: first # derivative) x3 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "sg", p = 3, n = 51, ts = 1, m = 1)
#' # Savitzky-Golay smoothing x1 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "sg", p = 3, n = 51, ts = 1, m = 0) # Fourier smoothing x2 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "fourier", k = 21) # computing derivative spectra with Savitzky-Golay smoothing (here: first # derivative) x3 <- ir::ir_sample_data[1:5, ] %>% ir::ir_smooth(method = "sg", p = 3, n = 51, ts = 1, m = 1)
ir_stack
takes a matrix or data frame with infrared spectra and
converts it into a list column corresponding to the column spectra
in
objects of class ir
.
ir_stack(x)
ir_stack(x)
x |
A matrix or data frame with a first column ( |
A tibble::tibble()
with the stacked spectra in column spectra
.
# from data frame x1 <- ir::ir_sample_data %>% ir::ir_flatten() %>% ir::ir_stack() # from matrix x2 <- ir::ir_sample_data %>% ir::ir_flatten() %>% as.matrix() %>% ir::ir_stack()
# from data frame x1 <- ir::ir_sample_data %>% ir::ir_flatten() %>% ir::ir_stack() # from matrix x2 <- ir::ir_sample_data %>% ir::ir_flatten() %>% as.matrix() %>% ir::ir_stack()
ir_subtract
takes two objects of class ir
, x
and
y
, and subtracts the intensity values of spectra in matching rows from
y
from that of x
. Alternatively, takes an object of class
ir
, x
, and a numeric value, y
, and subtracts y
from all intensity values in x
.
ir_subtract(x, y)
ir_subtract(x, y)
x |
An object of class |
y |
An object of class |
x
where for each spectrum the respective intensity values in
y
are subtracted (if y
is an object of class ir
), or
where for each spectrum y
has been subtracted from the intensity
values.
# subtracting two objects of class ir x1 <- ir::ir_subtract(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_subtract(ir::ir_sample_data, ir::ir_sample_data[1, ]) # subtracting a numeric value from an object of class `ir`. x3 <- ir::ir_subtract(ir::ir_sample_data, 20) # subtracting a numeric vector from an object of class `ir`. x4 <- ir::ir_subtract( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
# subtracting two objects of class ir x1 <- ir::ir_subtract(ir::ir_sample_data, ir::ir_sample_data) x2 <- ir::ir_subtract(ir::ir_sample_data, ir::ir_sample_data[1, ]) # subtracting a numeric value from an object of class `ir`. x3 <- ir::ir_subtract(ir::ir_sample_data, 20) # subtracting a numeric vector from an object of class `ir`. x4 <- ir::ir_subtract( ir::ir_sample_data, seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) )
ir_to_transmittance
converts absorbance spectra to transmittance
spectra. ir_to_absorbance
converts transmittance spectra to absorbance
spectra. Note that neither function checks whether the input spectra are
absorbance or transmittance spectra.
ir_to_transmittance(x) ir_to_absorbance(x)
ir_to_transmittance(x) ir_to_absorbance(x)
x |
An object of class |
x
with y values fore each spectrum as transmittance values
(in case of ir_to_transmittance
) or absorbance values (in case of
ir_to_absorbance
).
(Stuart 2004).
Stuart BH (2004). Infrared Spectroscopy: Fundamentals and Applications: Stuart/Infrared Spectroscopy: Fundamentals and Applications, Analytical Techniques in the Sciences. John Wiley \& Sons, Ltd, Chichester, UK. ISBN 978-0-470-01114-0 978-0-470-85428-0, doi:10.1002/0470011149.
# convert from absorbance to transmittance x1 <- ir_sample_data %>% ir_to_transmittance() # convert from transmittance to absorbance x2 <- x1 %>% ir::ir_to_absorbance() vapply( seq_along(x2$spectra), FUN = function(i) all.equal(x2$spectra[[i]], ir::ir_sample_data$spectra[[i]]), FUN.VALUE = logical(1L) ) %>% all()
# convert from absorbance to transmittance x1 <- ir_sample_data %>% ir_to_transmittance() # convert from transmittance to absorbance x2 <- x1 %>% ir::ir_to_absorbance() vapply( seq_along(x2$spectra), FUN = function(i) all.equal(x2$spectra[[i]], ir::ir_sample_data$spectra[[i]]), FUN.VALUE = logical(1L) ) %>% all()
ir
object in a given regionir_variance_region
takes a spectrum x
and, depending on the
arguments computes the following summary:
subtract_smoothed = FALSE
it computes the variance of the
intensity values for each spectrum in x
. If in addition range
is not NULL
, it computes the variance only for the region(s)
represented by range
.
subtract_smoothed = TRUE
it smoothes x
, subtracts
the smoothed x
from the unsmoothed x
and computes the
variance of the difference intensity values. If in addition range
is
not NULL
, it computes the variance only for the region(s)
represented by range
.
ir_variance_region( x, subtract_smoothed = FALSE, do_normalize = FALSE, normalize_method, ..., range = NULL )
ir_variance_region( x, subtract_smoothed = FALSE, do_normalize = FALSE, normalize_method, ..., range = NULL )
x |
An object of class |
subtract_smoothed |
A logical value. If |
do_normalize |
A logical value. If set to |
normalize_method |
See |
... |
Arguments passed to |
range |
See |
x
with two additional columns:
A numeric vector with the computed variances of the intensity values for the respective spectra.
An integer vector with the number of intensity values used during computing the variance.
# Whole spectra variance x1 <- ir::ir_sample_data %>% ir::ir_variance_region( subtract_smoothed = FALSE, do_normalize = TRUE, normalize_method = "area", range = NULL ) # Spectra variance, but only from a specific region range <- data.frame(start = 2700, end = 2800) x2 <- ir::ir_sample_data %>% ir::ir_normalize(method = "area") %>% ir::ir_variance_region( subtract_smoothed = FALSE, do_normalize = TRUE, normalize_method = "area", range = range ) # Spectra variance after subtracting a smoothed version of the spectra and # only from a specific region x3 <- ir::ir_sample_data %>% ir::ir_variance_region( subtract_smoothed = TRUE, do_normalize = FALSE, range = range, p = 3, n = 31, ts = 1, m = 0 )
# Whole spectra variance x1 <- ir::ir_sample_data %>% ir::ir_variance_region( subtract_smoothed = FALSE, do_normalize = TRUE, normalize_method = "area", range = NULL ) # Spectra variance, but only from a specific region range <- data.frame(start = 2700, end = 2800) x2 <- ir::ir_sample_data %>% ir::ir_normalize(method = "area") %>% ir::ir_variance_region( subtract_smoothed = FALSE, do_normalize = TRUE, normalize_method = "area", range = range ) # Spectra variance after subtracting a smoothed version of the spectra and # only from a specific region x3 <- ir::ir_sample_data %>% ir::ir_variance_region( subtract_smoothed = TRUE, do_normalize = FALSE, range = range, p = 3, n = 31, ts = 1, m = 0 )
ir
object by adding new or replacing existing columnsMutate an ir
object by adding new or replacing existing columns
mutate.ir( .data, ..., .keep = c("all", "used", "unused", "none"), .before = NULL, .after = NULL ) transmute.ir(.data, ...)
mutate.ir( .data, ..., .keep = c("all", "used", "unused", "none"), .before = NULL, .after = NULL ) transmute.ir(.data, ...)
.data |
An object of class |
... |
< The value can be:
|
.keep |
Control which columns from
|
.before , .after
|
< |
.data
with modified columns. If the spectra
column is dropped or
invalidated (see ir_new_ir()
), the ir
class is dropped, else the object
is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## mutate dplyr::mutate(ir_sample_data, hkl = klason_lignin + holocellulose) ## transmute dplyr::transmute(ir_sample_data, hkl = klason_lignin + holocellulose)
## mutate dplyr::mutate(ir_sample_data, hkl = klason_lignin + holocellulose) ## transmute dplyr::transmute(ir_sample_data, hkl = klason_lignin + holocellulose)
ir
objectMutating joins for an ir
object
inner_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) left_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) right_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) full_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") )
inner_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) left_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) right_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") ) full_join.ir( x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ..., keep = FALSE, na_matches = c("na", "never") )
x |
An object of class |
y |
A data frame. |
by |
A character vector of variables to join by. If To join by different variables on To join by multiple variables, use a vector with length > 1.
For example, To perform a cross-join, generating all combinations of |
copy |
If |
suffix |
If there are non-joined duplicate variables in |
... |
Other parameters passed onto methods. |
keep |
Should the join keys from both |
na_matches |
Should The default, Use |
x
and y
joined. If the spectra
column is renamed, the ir
class is dropped. See mutate-joins
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## inner_join set.seed(234) dplyr::inner_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## left_join set.seed(234) dplyr::left_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## right_join set.seed(234) dplyr::right_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## full_join set.seed(234) dplyr::full_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" )
## inner_join set.seed(234) dplyr::inner_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## left_join set.seed(234) dplyr::left_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## right_join set.seed(234) dplyr::right_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" ) ## full_join set.seed(234) dplyr::full_join( ir_sample_data, tibble::tibble( id_measurement = c(1:5, 101:105), nitrogen_content = rbeta(n = 10, 0.2, 0.1) ), by = "id_measurement" )
ir
objectNest and un-nest an ir
object
nest.ir(.data, ..., .names_sep = NULL, .key = deprecated()) unnest.ir( data, cols, ..., keep_empty = FALSE, ptype = NULL, names_sep = NULL, names_repair = "check_unique", .drop = deprecated(), .id = deprecated(), .sep = deprecated(), .preserve = deprecated() )
nest.ir(.data, ..., .names_sep = NULL, .key = deprecated()) unnest.ir( data, cols, ..., keep_empty = FALSE, ptype = NULL, names_sep = NULL, names_repair = "check_unique", .drop = deprecated(), .id = deprecated(), .sep = deprecated(), .preserve = deprecated() )
.data |
An object of class |
... |
< :
previously you could write If you previously created new variable in |
.key |
:
No longer needed because of the new |
data |
A data frame. |
cols |
< If you |
keep_empty |
By default, you get one row of output for each element
of the list your unchopping/unnesting. This means that if there's a
size-0 element (like |
ptype |
Optionally, a named list of column name-prototype pairs to
coerce |
names_sep , .names_sep
|
If If a string, the inner and outer names will be used together. In
|
names_repair |
Used to check that output data frame has valid names. Must be one of the following options:
See |
.drop , .preserve
|
:
all list-columns are now preserved; If there are any that you
don't want in the output use |
.id |
:
convert |
.sep |
.data
with nested or unnested columns. If the spectra
column is
dropped or invalidated (see ir_new_ir()
), the ir
class is dropped, else
the object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## nest ir_sample_data %>% tidyr::nest( contents = c(holocellulose, klason_lignin) ) ## unnest ir_sample_data %>% tidyr::nest( contents = c(holocellulose, klason_lignin) ) %>% tidyr::unnest("contents")
## nest ir_sample_data %>% tidyr::nest( contents = c(holocellulose, klason_lignin) ) ## unnest ir_sample_data %>% tidyr::nest( contents = c(holocellulose, klason_lignin) ) %>% tidyr::unnest("contents")
ir
objectsArithmetic operations for ir
objects
## S3 method for class 'ir' Ops(e1, e2)
## S3 method for class 'ir' Ops(e1, e2)
e1 |
An object of class |
e2 |
An object of class |
e1
with intensity values of the spectra added to/subtracted
with/multiplied with/divided by those in e2
:
If e2
is a numeric value, all intensity values in the spectra of e1
are
added/subtracted/multiplied/divided by e2
.
If e2
is an ir
object with one row, it is replicated (see rep.ir) so
that the row numbers match to those of e1
and intensity values are
added/subtracted/multiplied/divided row-wise.
If e2
is an ir
object with the same number of rows as e1
, intensity
values are added/subtracted/multiplied/divided row-wise.
## addition ir::ir_sample_data + ir::ir_sample_data ir::ir_sample_data + 2 ir::ir_sample_data + seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## subtraction ir::ir_sample_data - ir::ir_sample_data ir::ir_sample_data - 2 ir::ir_sample_data - seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## multiplication ir::ir_sample_data * ir::ir_sample_data ir::ir_sample_data * 2 ir::ir_sample_data * seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## division ir::ir_sample_data / ir::ir_sample_data ir::ir_sample_data / 2 ir::ir_sample_data / seq(from = 0.1, to = 2, length.out = nrow(ir::ir_sample_data))
## addition ir::ir_sample_data + ir::ir_sample_data ir::ir_sample_data + 2 ir::ir_sample_data + seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## subtraction ir::ir_sample_data - ir::ir_sample_data ir::ir_sample_data - 2 ir::ir_sample_data - seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## multiplication ir::ir_sample_data * ir::ir_sample_data ir::ir_sample_data * 2 ir::ir_sample_data * seq(from = 0, to = 2, length.out = nrow(ir::ir_sample_data)) ## division ir::ir_sample_data / ir::ir_sample_data ir::ir_sample_data / 2 ir::ir_sample_data / seq(from = 0.1, to = 2, length.out = nrow(ir::ir_sample_data))
ir
object from wide to longPivot an ir
object from wide to long
pivot_longer.ir( data, cols, names_to = "name", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = list(), names_transform = list(), names_repair = "check_unique", values_to = "value", values_drop_na = FALSE, values_ptypes = list(), values_transform = list(), ... )
pivot_longer.ir( data, cols, names_to = "name", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = list(), names_transform = list(), names_repair = "check_unique", values_to = "value", values_drop_na = FALSE, values_ptypes = list(), values_transform = list(), ... )
data |
An object of class |
cols |
< |
names_to |
A character vector specifying the new column or columns to
create from the information stored in the column names of
|
names_prefix |
A regular expression used to remove matching text from the start of each variable name. |
names_sep , names_pattern
|
If
If these arguments do not give you enough control, use
|
names_ptypes , values_ptypes
|
Optionally, a list of column name-prototype
pairs. Alternatively, a single empty prototype can be supplied, which will
be applied to all columns. A prototype (or ptype for short) is a
zero-length vector (like For backwards compatibility reasons, supplying |
names_transform , values_transform
|
Optionally, a list of column
name-function pairs. Alternatively, a single function can be supplied,
which will be applied to all columns. Use these arguments if you need to
change the types of specific columns. For example, If not specified, the type of the columns generated from |
names_repair |
What happens if the output has invalid column names?
The default, |
values_to |
A string specifying the name of the column to create
from the data stored in cell values. If |
values_drop_na |
If |
... |
Additional arguments passed on to methods. |
data
in a long format. If the spectra
column is dropped
or invalidated (see ir_new_ir()
), the ir
class is dropped, else the
object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## pivot_longer ir_sample_data %>% tidyr::pivot_longer( cols = dplyr::any_of(c("holocellulose", "klason_lignin")) )
## pivot_longer ir_sample_data %>% tidyr::pivot_longer( cols = dplyr::any_of(c("holocellulose", "klason_lignin")) )
ir
object from wide to longPivot an ir
object from wide to long
pivot_wider.ir( data, id_cols = NULL, names_from = "name", names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE, names_repair = "check_unique", values_from = "value", values_fill = NULL, values_fn = NULL, ... )
pivot_wider.ir( data, id_cols = NULL, names_from = "name", names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE, names_repair = "check_unique", values_from = "value", values_fill = NULL, values_fn = NULL, ... )
data |
An object of class |
id_cols |
< |
names_from , values_from
|
< If |
names_prefix |
String added to the start of every variable name. This is
particularly useful if |
names_sep |
If |
names_glue |
Instead of |
names_sort |
Should the column names be sorted? If |
names_repair |
What happens if the output has invalid column names?
The default, |
values_fill |
Optionally, a (scalar) value that specifies what each
This can be a named list if you want to apply different fill values to different value columns. |
values_fn |
Optionally, a function applied to the value in each cell
in the output. You will typically use this when the combination of
This can be a named list if you want to apply different aggregations
to different |
... |
Additional arguments passed on to methods. |
data
in a wide format. If the spectra
column is dropped
or invalidated (see ir_new_ir()
), the ir
class is dropped, else the
object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## pivot_wider ir_sample_data %>% tidyr::pivot_longer( cols = dplyr::any_of(c("holocellulose", "klason_lignin")) ) %>% tidyr::pivot_wider(names_from = "name", values_from = "value")
## pivot_wider ir_sample_data %>% tidyr::pivot_longer( cols = dplyr::any_of(c("holocellulose", "klason_lignin")) ) %>% tidyr::pivot_wider(names_from = "name", values_from = "value")
ir
plot.ir
is the plot method for objects of class ir
.
## S3 method for class 'ir' plot(x, ...)
## S3 method for class 'ir' plot(x, ...)
x |
An object of class |
... |
Further arguments, will be ignored. |
An object of class ggplot2
.
# simple plotting plot(ir::ir_sample_data[1:2, ]) # advanced functions plot(ir::ir_sample_data) + ggplot2::facet_wrap(~ sample_type)
# simple plotting plot(ir::ir_sample_data[1:2, ]) # advanced functions plot(ir::ir_sample_data) + ggplot2::facet_wrap(~ sample_type)
range.ir
extracts the range of x axis values (e.g. wavenumbers) or
intensity values of infrared spectra.
min.ir
extracts the minimum x axis value (e.g. wavenumber) or
intensity value of infrared spectra.
max.ir
extracts the maximum x axis value (e.g. wavenumber) or
intensity value of infrared spectra.
median.ir
extracts the median x axis value (e.g. wavenumber) or
intensity value of infrared spectra.
## S3 method for class 'ir' range( x, ..., na.rm = FALSE, .dimension = "y", .col_names = c("y_min", "y_max") ) ## S3 method for class 'ir' min(x, ..., na.rm = FALSE, .dimension = "y", .col_name = "y_min") ## S3 method for class 'ir' max(x, ..., na.rm = FALSE, .dimension = "y", .col_name = "y_max") ## S3 method for class 'ir' median(x, na.rm = FALSE, ..., .dimension = "y", .col_name = "y_median")
## S3 method for class 'ir' range( x, ..., na.rm = FALSE, .dimension = "y", .col_names = c("y_min", "y_max") ) ## S3 method for class 'ir' min(x, ..., na.rm = FALSE, .dimension = "y", .col_name = "y_min") ## S3 method for class 'ir' max(x, ..., na.rm = FALSE, .dimension = "y", .col_name = "y_max") ## S3 method for class 'ir' median(x, na.rm = FALSE, ..., .dimension = "y", .col_name = "y_median")
x |
An object of class |
... |
Further arguments, ignored. |
na.rm |
A logical value. See |
.dimension |
A character value. Must be one of the following:
|
.col_names |
A character vector of length 2 representing the names of the columns in which to store the extracted values. The first element is the name for the column with minima values, the second the name for the column with maxima values. |
.col_name |
A character value representing the name of the column in which to store the extracted values. |
x
with the extracted values.
# range of intensity values x1 <- ir::ir_sample_data %>% range(.dimension = "y") # minimum intensity values x1 <- ir::ir_sample_data %>% min(.dimension = "y") # maximum intensity values x1 <- ir::ir_sample_data %>% max(.dimension = "y") # median intensity values x1 <- ir::ir_sample_data %>% stats::median(.dimension = "y")
# range of intensity values x1 <- ir::ir_sample_data %>% range(.dimension = "y") # minimum intensity values x1 <- ir::ir_sample_data %>% min(.dimension = "y") # maximum intensity values x1 <- ir::ir_sample_data %>% max(.dimension = "y") # median intensity values x1 <- ir::ir_sample_data %>% stats::median(.dimension = "y")
ir
objectsRename columns in ir
objects
rename.ir(.data, ...) rename_with.ir(.data, .fn, .cols = dplyr::everything(), ...)
rename.ir(.data, ...) rename_with.ir(.data, .fn, .cols = dplyr::everything(), ...)
.data |
An object of class |
... |
For For |
.fn |
A function used to transform the selected |
.cols |
< |
.data
with renamed columns. If the spectra
column is renamed,
and no new valid spectra
column is created, the ir
class is dropped, else
the object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## rename dplyr::rename(ir_sample_data, hol = "holocellulose") dplyr::rename(ir_sample_data, spec = "spectra") # drops ir class ## rename_with dplyr::rename_with(ir_sample_data, .cols = dplyr::starts_with("id_"), toupper) dplyr::rename_with(ir_sample_data, toupper) # drops ir class
## rename dplyr::rename(ir_sample_data, hol = "holocellulose") dplyr::rename(ir_sample_data, spec = "spectra") # drops ir class ## rename_with dplyr::rename_with(ir_sample_data, .cols = dplyr::starts_with("id_"), toupper) dplyr::rename_with(ir_sample_data, toupper) # drops ir class
rep.ir
is the replicate method for ir
objects.
Replicating and ir
object means to replicate its rows and bind these
together to a larger ir
object.
## S3 method for class 'ir' rep(x, ...)
## S3 method for class 'ir' rep(x, ...)
x |
An object of class |
... |
See |
An object of class ir
with replicated spectra.
# replicate the sample data x <- rep(ir::ir_sample_data, times = 2) x <- rep(ir::ir_sample_data, each = 2) x <- rep(ir::ir_sample_data, length.out = 3)
# replicate the sample data x <- rep(ir::ir_sample_data, times = 2) x <- rep(ir::ir_sample_data, each = 2) x <- rep(ir::ir_sample_data, length.out = 3)
ir
objects by rowsGroup input ir
objects by rows
rowwise.ir(.data, ...)
rowwise.ir(.data, ...)
.data |
Input data frame. |
... |
< NB: unlike |
data |
An object of class |
data
as row-wise data frame. See dplyr::rowwise()
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## rowwise dplyr::rowwise(ir_sample_data) %>% dplyr::mutate( hkl = mean( units::drop_units(klason_lignin), units::drop_units(holocellulose) ) )
## rowwise dplyr::rowwise(ir_sample_data) %>% dplyr::mutate( hkl = mean( units::drop_units(klason_lignin), units::drop_units(holocellulose) ) )
ir
objects using column names and typesSubset columns in ir
objects using column names and types
select.ir(.data, ...)
select.ir(.data, ...)
.data |
An object of class |
... |
< |
.data
with the selected columns. If the spectra
column is dropped,
the ir
class is dropped, else the object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## select dplyr::select(ir_sample_data, spectra) dplyr::select(ir_sample_data, holocellulose) # drops ir class
## select dplyr::select(ir_sample_data, spectra) dplyr::select(ir_sample_data, holocellulose) # drops ir class
ir
object into multiple rowsSeparate a collapsed column in an ir
object into multiple rows
separate_rows.ir(data, ..., sep = "[^[:alnum:].]+", convert = FALSE)
separate_rows.ir(data, ..., sep = "[^[:alnum:].]+", convert = FALSE)
data |
An object of class |
... |
< |
sep |
Separator delimiting collapsed values. |
convert |
If |
data
with a collapsed column separated into multiple rows. See
tidyr::separate_rows()
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
slice
,
summarize
,
unite.ir()
## separate_rows ir_sample_data %>% tidyr::unite( col = content, holocellulose, klason_lignin ) %>% tidyr::separate_rows( col )
## separate_rows ir_sample_data %>% tidyr::unite( col = content, holocellulose, klason_lignin ) %>% tidyr::separate_rows( col )
ir
object into multiple columns with a regular expression or numeric locationsSeparate a character column in an ir
object into multiple columns with a regular expression or numeric locations
separate.ir( data, col, into, sep = "[^[:alnum:]]+", remove = TRUE, convert = FALSE, extra = "warn", fill = "warn", ... )
separate.ir( data, col, into, sep = "[^[:alnum:]]+", remove = TRUE, convert = FALSE, extra = "warn", fill = "warn", ... )
data |
An object of class |
col |
Column name or position. This is passed to
This argument is passed by expression and supports quasiquotation (you can unquote column names or column positions). |
into |
Names of new variables to create as character vector.
Use |
sep |
Separator between columns. If character, If numeric, |
remove |
If |
convert |
If NB: this will cause string |
extra |
If
|
fill |
If
|
... |
Additional arguments passed on to methods. |
.data
with separated columns. If the spectra
column is
dropped or invalidated (see ir_new_ir()
), the ir
class is dropped, else
the object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate_rows.ir()
,
slice
,
summarize
,
unite.ir()
## separate ir_sample_data %>% tidyr::separate( col = "id_sample", c("a", "b", "c") )
## separate ir_sample_data %>% tidyr::separate( col = "id_sample", c("a", "b", "c") )
ir
objects using their positionsSubset rows in ir
objects using their positions
slice.ir(.data, ..., .preserve = FALSE) slice_sample.ir(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
slice.ir(.data, ..., .preserve = FALSE) slice_sample.ir(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
.data |
An object of class |
... |
For Provide either positive values to keep, or negative values to drop. The values provided must be either all positive or all negative. Indices beyond the number of rows in the input are silently ignored. For |
.preserve |
Relevant when the |
n , prop
|
Provide either If a negative value of If |
weight_by |
Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1. |
replace |
Should sampling be performed with ( |
.data
with subsetted rows.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
summarize
,
unite.ir()
## slice dplyr::slice(ir_sample_data, 1:5) dplyr::slice_min(ir_sample_data, holocellulose, n = 3) dplyr::slice_max(ir_sample_data, holocellulose, n = 3) dplyr::slice_head(ir_sample_data, n = 5) dplyr::slice_tail(ir_sample_data, n = 5) ## slice_sample set.seed(234) dplyr::slice_sample(ir_sample_data, n = 3)
## slice dplyr::slice(ir_sample_data, 1:5) dplyr::slice_min(ir_sample_data, holocellulose, n = 3) dplyr::slice_max(ir_sample_data, holocellulose, n = 3) dplyr::slice_head(ir_sample_data, n = 5) dplyr::slice_tail(ir_sample_data, n = 5) ## slice_sample set.seed(234) dplyr::slice_sample(ir_sample_data, n = 3)
ir
objectsSubsetting ir
objects
## S3 method for class 'ir' x[i, j, ..., exact = TRUE] ## S3 method for class 'ir' x$i ## S3 method for class 'ir' x[[i, j, ..., exact = TRUE]] ## S3 replacement method for class 'ir' x$i, j, ... <- value ## S3 replacement method for class 'ir' i[j, ..., exact = TRUE] <- value ## S3 replacement method for class 'ir' i[[j, ..., exact = TRUE]] <- value
## S3 method for class 'ir' x[i, j, ..., exact = TRUE] ## S3 method for class 'ir' x$i ## S3 method for class 'ir' x[[i, j, ..., exact = TRUE]] ## S3 replacement method for class 'ir' x$i, j, ... <- value ## S3 replacement method for class 'ir' i[j, ..., exact = TRUE] <- value ## S3 replacement method for class 'ir' i[[j, ..., exact = TRUE]] <- value
x |
An object of class |
i , j
|
Row and column indices. If |
... |
Ignored. |
exact |
Ignored, with a warning. |
value |
A value to store in a row, column, range or cell. Tibbles are stricter than data frames in what is accepted here. |
If the subsetting operation preserves a valid spectra
column
(see ir()
), an object of class ir
with
accordingly subsetted rows or columns. Else a tibble::tbl_df()
or
vector.
# subsetting rows ir_sample_data[1, ] ir_sample_data[10:15, ] ir_sample_data[ir_sample_data$sample_type == "office paper", ] # subsetting columns ir_sample_data[, "spectra"] ir_sample_data[["spectra"]] ir_sample_data$spectra # not explicitly selecting the spectra column drops the ir class class(ir_sample_data[, 1]) class(ir_sample_data[, "spectra"]) # subsetting values ir_sample_data[, 1] # drops the ir class ir_sample_data[, c("id_sample", "spectra")] ir_sample_data$id_sample ir_sample_data[[1, 1]] # setting and replacing columns x <- ir::ir_sample_data x$a <- 3 x[, "a"] <- 4 x$sample_type <- "a" x[[1]] <- rev(x[[1]]) # deleting the spectra column drops the ir class x$spectra <- NULL class(x) # setting and replacing rows x <- ir::ir_sample_data x[1, ] <- x[2, ] class(x) # setting invalid values in the spectra column drops the ir class x_replacement <- x[1, ] x_replacement$spectra <- list(1) x[1, ] <- x_replacement class(x) # setting and replacing values x <- ir::ir_sample_data x[[1, 1]] <- 100 # replacing an element in the spectra column by an invalid element drops the # ir class attribute x[[3, "spectra"]] <- list(1) class(x)
# subsetting rows ir_sample_data[1, ] ir_sample_data[10:15, ] ir_sample_data[ir_sample_data$sample_type == "office paper", ] # subsetting columns ir_sample_data[, "spectra"] ir_sample_data[["spectra"]] ir_sample_data$spectra # not explicitly selecting the spectra column drops the ir class class(ir_sample_data[, 1]) class(ir_sample_data[, "spectra"]) # subsetting values ir_sample_data[, 1] # drops the ir class ir_sample_data[, c("id_sample", "spectra")] ir_sample_data$id_sample ir_sample_data[[1, 1]] # setting and replacing columns x <- ir::ir_sample_data x$a <- 3 x[, "a"] <- 4 x$sample_type <- "a" x[[1]] <- rev(x[[1]]) # deleting the spectra column drops the ir class x$spectra <- NULL class(x) # setting and replacing rows x <- ir::ir_sample_data x[1, ] <- x[2, ] class(x) # setting invalid values in the spectra column drops the ir class x_replacement <- x[1, ] x_replacement$spectra <- list(1) x[1, ] <- x_replacement class(x) # setting and replacing values x <- ir::ir_sample_data x[[1, 1]] <- 100 # replacing an element in the spectra column by an invalid element drops the # ir class attribute x[[3, "spectra"]] <- list(1) class(x)
ir
object to fewer rowsSummarize each group in a ir
object to fewer rows
summarize.ir(.data, ..., .groups = NULL) summarise.ir(.data, ..., .groups = NULL)
summarize.ir(.data, ..., .groups = NULL) summarise.ir(.data, ..., .groups = NULL)
.data |
An object of class |
... |
< The value can be:
|
.groups |
Grouping structure of the result.
When
In addition, a message informs you of that choice, unless the result is ungrouped,
the option "dplyr.summarise.inform" is set to |
.data
with summarized columns. If the spectra
column is dropped
or invalidated (see ir_new_ir()
), the ir
class is dropped, else the
object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
unite.ir()
## summarize # select in each sample_type groups the first spectrum ir_sample_data %>% dplyr::group_by(sample_type) %>% dplyr::summarize(spectra = spectra[[1]])
## summarize # select in each sample_type groups the first spectrum ir_sample_data %>% dplyr::group_by(sample_type) %>% dplyr::summarize(spectra = spectra[[1]])
ir
object into one by pasting strings togetherUnite multiple columns in an ir
object into one by pasting strings together
unite.ir(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)
unite.ir(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)
data |
An object of class |
col |
The name of the new column, as a string or symbol. This argument is passed by expression and supports
quasiquotation (you can unquote strings
and symbols). The name is captured from the expression with
|
... |
< |
sep |
Separator to use between values. |
remove |
If |
na.rm |
If |
.data
with united columns. If the spectra
column is
dropped or invalidated (see ir_new_ir()
), the ir
class is dropped, else
the object is of class ir
.
Other tidyverse:
arrange.ir()
,
distinct.ir()
,
extract.ir()
,
filter-joins
,
filter.ir()
,
group_by
,
mutate-joins
,
mutate
,
nest
,
pivot_longer.ir()
,
pivot_wider.ir()
,
rename
,
rowwise.ir()
,
select.ir()
,
separate.ir()
,
separate_rows.ir()
,
slice
,
summarize
## unite ir_sample_data %>% tidyr::separate( "id_sample", c("a", "b", "c") ) %>% tidyr::unite(id_sample, a, b, c)
## unite ir_sample_data %>% tidyr::separate( "id_sample", c("a", "b", "c") ) %>% tidyr::unite(id_sample, a, b, c)