Skip to content

Commit

Permalink
Update documentation, update News.md. Addresses #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningte committed Apr 21, 2022
1 parent ca1d7db commit bca74ea
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
^pkgdown$
^\.github$
^cran-comments\.md$
^man/figures/logo-hex\.svg$
^man/figures/logo-hex\.png$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ir.Rproj
/doc/
/Meta/
docs
/man/figures/logo-hex.svg
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ir 0.1.0.9999
# ir 0.2.0.

* First CRAN release.
* Added a `NEWS.md` file to track changes to the package.
* Added tidyverse methods for `ir` objects.
* `ir` objects no longer require columns `measurement_id` and `sample_id`, but only the column `spectra`.
Expand Down
26 changes: 15 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ knitr::opts_chunk$set(
)
```

# ir
# ir <img src='man/figures/logo-hex.png' align="right" height="139" alt="logo" style="float:right; height:200px;" />

<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![DOI](https://zenodo.org/badge/234117897.svg)](https://zenodo.org/badge/latestdoi/234117897)
[![DOI](https://zenodo.org/badge/234117897.svg)](https://zenodo.org/badge/latestdoi/234117897)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
<!-- badges: end -->


ir is an R package that contains simple functions to import, handle and preprocess infrared spectra. Infrared spectra are stored as list columns in data frames to enable efficient storage of metadata along with the spectra and support further analyses containing other data for the same samples.
## Overview

'ir' is an R package that contains simple functions to import, handle and preprocess infrared spectra. Infrared spectra are stored as list columns in data frames to enable efficient storage of metadata along with the spectra and support further analyses containing other data for the same samples.

**Supported file formats for import are:**

Expand Down Expand Up @@ -55,22 +59,22 @@ ir is an R package that contains simple functions to import, handle and preproce

### How to install

You can install ir from CRAB using R via:
You can install 'ir' from CRAB using R via:

```{r installation-cran}
```{r installation-cran, eval = FALSE}
install.packages("ir")
```


You can install ir from GitHub using R via:
You can install 'ir' from GitHub using R via:

```{r installation-github, eval = FALSE}
remotes::install_github(repo = "henningte/ir")
```

### How to use

You can load ir in R with:
You can load 'ir' in R with:

```{r load_ir}
# load ir package
Expand All @@ -87,7 +91,7 @@ For brief introductions, see below and the two vignettes:

#### Sample workflow

A simple workflow would be, for example, to baseline correct the spectra, then bin them to bins with a width of 10 wavenumber units, then normalize them so that the maximum intensity value is 1 and the minimum intensity value is 0 and then plot the baseline corrected spectra for each sample and sample type. Here's the ir code using the built-in sample data `ir_sample_data`.
A simple workflow would be, for example, to baseline correct the spectra, then bin them to bins with a width of 10 wavenumber units, then normalize them so that the maximum intensity value is 1 and the minimum intensity value is 0 and then plot the baseline corrected spectra for each sample and sample type. Here's the 'ir' code using the built-in sample data `ir_sample_data`.

```{r sample_data_workflow}
ir_sample_data %>% # data
Expand Down Expand Up @@ -127,13 +131,13 @@ Please cite this R package as:

### Companion packages

[irpeat](https://github.com/henningte/irpeat/) builds on ir. irpeat provides functions to analyze infrared spectra of peat (humification indices, prediction models).
[irpeat](https://github.com/henningte/irpeat/) builds on 'ir'. irpeat provides functions to analyze infrared spectra of peat (humification indices, prediction models).



### Licenses

**Text and figures :** [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/)
**Text and figures :** [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

**Code :** See the [DESCRIPTION](DESCRIPTION) file

Expand All @@ -145,7 +149,7 @@ We welcome contributions from everyone. Before you get started, please see our [

### Sources

The complete data in this package is derived from @Hodgkins.2018 and was restructured 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 (http://creativecommons.org/licenses/by/4.0/). The data on Klason lignin and holocellulose content was originally derived from @LaCruz.2016.
The complete data in this package is derived from @Hodgkins.2018 and was restructured 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 was originally derived from @LaCruz.2016.

This packages was developed in R (`r R.Version()$version.string`) [@RCoreTeam.2019] using functions from devtools [@Wickham.2019], usethis [@Wickham.2019b], rrtools [@Marwick.2019] and roxygen2 [@Wickham.2019c].

Expand Down
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# ir
# ir <img src='man/figures/logo-hex.png' align="right" height="139" alt="logo" style="float:right; height:200px;" />

<!-- badges: start -->

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![DOI](https://zenodo.org/badge/234117897.svg)](https://zenodo.org/badge/latestdoi/234117897)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
<!-- badges: end -->

ir is an R package that contains simple functions to import, handle and
preprocess infrared spectra. Infrared spectra are stored as list columns
in data frames to enable efficient storage of metadata along with the
spectra and support further analyses containing other data for the same
samples.
## Overview

‘ir’ is an R package that contains simple functions to import, handle
and preprocess infrared spectra. Infrared spectra are stored as list
columns in data frames to enable efficient storage of metadata along
with the spectra and support further analyses containing other data for
the same samples.

**Supported file formats for import are:**

Expand Down Expand Up @@ -51,15 +53,21 @@ samples.

### How to install

You can install ir from GitHub using R via:
You can install ‘ir’ from CRAB using R via:

``` r
install.packages("ir")
```

You can install ‘ir’ from GitHub using R via:

``` r
remotes::install_github(repo = "henningte/ir")
```

### How to use

You can load ir in R with:
You can load ‘ir’ in R with:

``` r
# load ir package
Expand All @@ -72,7 +80,7 @@ library(ggplot2)

For brief introductions, see below and the two vignettes:

1. [Introduction to the ir package](vignettes/ir-introduction.Rmd)
1. [Introduction to the ‘ir’ package](vignettes/ir-introduction.Rmd)
2. [Introduction to the `ir`class](vignettes/ir-class.Rmd)

#### Sample workflow
Expand All @@ -81,7 +89,7 @@ A simple workflow would be, for example, to baseline correct the
spectra, then bin them to bins with a width of 10 wavenumber units, then
normalize them so that the maximum intensity value is 1 and the minimum
intensity value is 0 and then plot the baseline corrected spectra for
each sample and sample type. Here’s the ir code using the built-in
each sample and sample type. Here’s the ‘ir’ code using the built-in
sample data `ir_sample_data`.

``` r
Expand Down Expand Up @@ -156,13 +164,19 @@ Column `x` represents the x values (in this case wavenumbers
Please cite this R package as:

> Henning Teickner (2022). *ir: Functions to Handle and Preprocess
> Infrared Spectra*. DOI: 10.5281/zenodo.5747170. Accessed 20 Apr 2022.
> Infrared Spectra*. DOI: 10.5281/zenodo.5747170. Accessed 21 Apr 2022.
> Online at <https://zenodo.org/record/5747170>.
### Companion packages

[irpeat](https://github.com/henningte/irpeat/) builds on ‘ir’. irpeat
provides functions to analyze infrared spectra of peat (humification
indices, prediction models).

### Licenses

**Text and figures :** [CC
BY 4.0](http://creativecommons.org/licenses/by/4.0/)
BY 4.0](https://creativecommons.org/licenses/by/4.0/)

**Code :** See the [DESCRIPTION](DESCRIPTION) file

Expand All @@ -180,11 +194,11 @@ participating in this project you agree to abide by its terms.
### Sources

The complete data in this package is derived from Hodgkins et al. (2018)
and was restructured to match the requirements of ir. The original
and was restructured 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
(<http://creativecommons.org/licenses/by/4.0/>). The data on Klason
(<https://creativecommons.org/licenses/by/4.0/>). The data on Klason
lignin and holocellulose content was originally derived from De La Cruz,
Florentino B., Osborne, and Barlaz (2016).

Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ navbar:
articles:
text: Articles
menu:
- text: Introduction to the ir package
- text: Introduction to the 'ir' package
href: articles/ir-introduction.html
- text: Introduction to the `ir`class
href: articles/ir-class.html
Expand Down
5 changes: 3 additions & 2 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Preprocess
Readme
René
Savitzky
Spectra’
Thermo
Tibbles
Tidyverse
Expand All @@ -55,12 +54,12 @@ et
ggplot
github
holocellulose
http
https
humification
hyperspec
ing
irpeat
ir’
magrittr
magrittr's
mth
Expand All @@ -85,9 +84,11 @@ summarise
tibble
tidyr
tidyverse
un
unchopping
ungrouped
unnest
unnested
unnesting
unsmoothed
usethis
Expand Down
Binary file added man/figures/logo-hex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/nest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vignettes/ir-class.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ knitr::opts_chunk$set(

## Purpose

The purpose of this vignette is to describe the structure and methods of objects of class `ir`. `ir` objects are used by the ir package to store spectra and their metadata. This vignette could be helpful if you want to understand better how the ir package works, how to handle metadata, how to manipulate `ir` objects, or if you want to construct a subclass based on the `ir`class.
The purpose of this vignette is to describe the structure and methods of objects of class `ir`. `ir` objects are used by the 'ir' package to store spectra and their metadata. This vignette could be helpful if you want to understand better how the 'ir' package works, how to handle metadata, how to manipulate `ir` objects, or if you want to construct a subclass based on the `ir`class.

This vignette does not give an overview on how to use the ir package, on functions for spectral preprocessing, and on how to plot `ir` objects. For this, see vignette [`r rmarkdown::yaml_front_matter("ir-introduction.Rmd")$title`](ir-introduction.html).
This vignette does not give an overview on how to use the 'ir' package, on functions for spectral preprocessing, and on how to plot `ir` objects. For this, see vignette [`r rmarkdown::yaml_front_matter("ir-introduction.Rmd")$title`](ir-introduction.html).

## Structure

Expand All @@ -43,7 +43,7 @@ In part [Special functions to manipulate `ir objects`], I will present some more

## Preparation

To follow this vignette, you have to install the ir package as described in the Readme file and you have to load it:
To follow this vignette, you have to install the 'ir' package as described in the Readme file and you have to load it:

```{r load-package-ir}
library(ir)
Expand Down Expand Up @@ -269,7 +269,7 @@ ir_sample_data[2, ] / ir_sample_data[3, ]

# Further information

Many more functions and options to handle and process spectra are available in the ir package. These are described in the documentation. In the documentation, you can also read more details about the functions and options presented here.
Many more functions and options to handle and process spectra are available in the 'ir' package. These are described in the documentation. In the documentation, you can also read more details about the functions and options presented here.
To learn more about how `ir` objects can be useful can be plotted, and the spectral preprocessing functions, see the vignette [`r rmarkdown::yaml_front_matter("ir-introduction.Rmd")$title`](ir-introduction.html).


Expand Down
37 changes: 28 additions & 9 deletions vignettes/ir-introduction.Rmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: "Introduction to the ir package"
title: "Introduction to the 'ir' package"
output: rmarkdown::html_vignette
author: Henning Teickner
vignette: >
%\VignetteIndexEntry{Introduction to the ir package}
%\VignetteIndexEntry{Introduction to the 'ir' package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
bibliography: "../inst/REFERENCES.bib"
Expand All @@ -28,7 +28,7 @@ library(kableExtra)

## Purpose

This vignette shows you the main functionalities of the ir package. This includes data import, functions for spectral preprocessing, and plotting.
This vignette shows you the main functionalities of the 'ir' package. This includes data import, functions for spectral preprocessing, and plotting.
This vignette does not explain the data structure of `ir` objects (the objects the package ir uses to store spectra) in detail and it does not describe general data manipulation functions (e.g. subsetting rows or columns, modifying variables) (for this, see vignette [`r rmarkdown::yaml_front_matter("ir-class.Rmd")$title`](ir-class.html)). Moreover, this vignette does not explain the purpose of the spectral preprocessing functions.

## Structure
Expand All @@ -39,13 +39,13 @@ The vignette has three parts:
2. Plotting spectra
3. Spectral preprocessing

In part [Data import and export], I will show how spetra can be imported from `csv` files and from Thermo Galactic's spectral files (file extension `.spc`). I will also show how `ir` objects can be exported as `csv` files. To this end, I will use sample data which comes along with the ir package.
In part [Data import and export], I will show how spetra can be imported from `csv` files and from Thermo Galactic's spectral files (file extension `.spc`). I will also show how `ir` objects can be exported as `csv` files. To this end, I will use sample data which comes along with the 'ir' package.
In part [Plotting spectra], I will show how spectra can be plotted and how these plots can be modified.
In part [Spectral preprocessing] I will demonstrate the main preprocessing functions included in the ir package and how these can be combined to execute complex preprocessing pipelines.
In part [Spectral preprocessing] I will demonstrate the main preprocessing functions included in the 'ir' package and how these can be combined to execute complex preprocessing pipelines.

## Preparation

To follow this vignette, you have to install the ir package as described in the Readme file and you have to load it:
To follow this vignette, you have to install the 'ir' package as described in the Readme file and you have to load it:

```{r load-package-ir}
library(ir)
Expand All @@ -57,7 +57,7 @@ library(ir)

## Data import

To test importing spectra from files, I'll use sample data which is contained in the ir package (in folder `inst/extdata`). First, I'll show how to import spectra from csv files and then how to import Thermo Galactic's spectral files (file extension `.spc`).
To test importing spectra from files, I'll use sample data which is contained in the 'ir' package (in folder `inst/extdata`). First, I'll show how to import spectra from csv files and then how to import Thermo Galactic's spectral files (file extension `.spc`).

### `csv` files

Expand Down Expand Up @@ -124,10 +124,29 @@ d_spc <- ir_import_spc("../inst/extdata/1.spc")
In this case, names for the spectra and other metadata are extracted from the `spc` file(s) and added to the `ir` object. You can inspect `d_spc` to see these additional variables.


## Data export

Data in `ir` objects can in principle be exported in many ways. Here, I show hot to export to a `csv` file with the same format as the sample data we imported in subsection [`csv` files].

To this end, we first have to "flatten" the `spectra` column in `ir_sample_data` (using `ir_flatten()`) and export this as `csv` file using `write.csv()`. Second, to export the metadata, we have to drop the spectra from `ir_sample_data` (using `ir_drop_spectra()`), and then write the remaining data to a separate `csv` file using `write.csv()`:

```{r export-csv-1}
# export only the spectra
ir_sample_data %>%
ir_flatten() %>%
write.csv(tempfile("ir_sample_data_spectra", fileext = "csv"), row.names = FALSE)
# export only the metadata
ir_sample_data %>%
ir_drop_spectra() %>%
write.csv(tempfile("ir_sample_data_metadata", fileext = "csv"), row.names = FALSE)
```



# Plotting spectra

The ir package provides a function to create simple plots of spectra out-of-the box:
The 'ir' package provides a function to create simple plots of spectra out-of-the box:

```{r plot-1}
plot(d_csv)
Expand Down Expand Up @@ -295,7 +314,7 @@ Now, we have a baseline corrected spectrum, `"area"` normalized, clipped to [650

# Further information

Many more functions and options to handle and process spectra are available in the ir package. These are described in the documentation. In the documentation, you can also read more details about the functions and options presented here.
Many more functions and options to handle and process spectra are available in the 'ir' package. These are described in the documentation. In the documentation, you can also read more details about the functions and options presented here.
To learn more about the structure and general functions to handle `ir` objects, see the vignette [`r rmarkdown::yaml_front_matter("ir-class.Rmd")$title`](ir-class.html).


Expand Down

0 comments on commit bca74ea

Please sign in to comment.