knitr::opts_chunk$set( 
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  dev = "png",
  dpi = 600
) 

cwrshelpr

Codecov test coverage R-CMD-check

cwrshelpr provides a collection of functions for data analysis tasks at Dalhousie University's Centre for Water Resources Studies.

Installation

You can install the development version from GitHub as follows. If the remotes package is not installed, run install.packages("remotes") first. If you're new to R, R for data science provides an excellent introduction.

remotes::install_github("bentrueman/cwrshelpr")

The examples below rely on the tidyverse family of packages. Run install.packages("tidyverse") if it's not already installed.

ICP-MS

To read and clean ICP-MS data files generated by the Thermo Scientific iCAP-RQ, use the read_icp() function. (N.B., the code below uses external raw data files as examples; replace them with your data.)

library("tidyverse")
library("cwrshelpr")
# example path to example raw data file
files <- list.files(
  # replace this line with the path to your data:
   path = system.file("extdata", package = "cwrshelpr"), 
   full.names = TRUE,
   pattern = ".+\\.xlsx"
)
read_icp(path = files[1]) # read and clean one file
files[1:2] %>% 
  set_names() %>% 
  map_dfr(read_icp, .id = "file") # read and clean multiple files

Use the read_lims() function to read/clean files in the new LIMS format:

read_lims(files[3], work_order = "00A123456")
theme_set(theme_bw())

Fluorescence excitation-emission matrices (FEEM)

To read and clean FEEM data files generated by the Horiba Aqualog, use the read_feem() function. The argument truncate = TRUE may be useful if the corrected first order Rayleigh scattering line includes negative intensities.

files <- list.files(
   path = system.file("extdata", package = "cwrshelpr"), # replace this line with the path to your data
   full.names = TRUE,
   pattern = ".+\\.csv"
)
read_feem(path = files[1]) # read and clean one file
feem_dat <- files %>% 
  set_names() %>% 
  map_dfr(~ read_feem(.x, truncate = TRUE), .id = "file") # read and clean multiple files

Plot FEEM data using the function ggplot2::geom_raster() (among others). Use the column em_regular to avoid horizontal striping due to irregular spacing of the emission wavelengths.

feem_dat %>% 
  ggplot(aes(excitation, em_regular, fill = intensity)) +
  facet_wrap(vars(file)) + 
  geom_raster() + 
  scale_fill_viridis_c()

Here is an example using ggplot2::stat_contour(geom = "polygon"):

feem_dat %>% 
  ggplot(aes(excitation, em_regular, z = intensity, fill = stat(level))) +
  facet_wrap(vars(file)) + 
  stat_contour(geom = "polygon") +
  scale_fill_viridis_c("intensity")

Integrate regions of the FEEM using integrate_regions(). This function uses the regions defined in Chen et al. (2003) by default, but you can supply your own as well.

feem_dat %>% 
  group_by(file) %>% 
  nest() %>% 
  ungroup() %>% 
  mutate(regions = map(data, integrate_regions)) %>% 
  unnest(regions)

The humification and biological indices of each FEEM, as described in Tedetti et al. (2011), can be calculated using calculate_indices():

feem_dat %>% 
  group_by(file) %>% 
  nest() %>% 
  ungroup() %>% 
  mutate(ix = map(data, calculate_indices)) %>% 
  unnest(ix)

Additional resources

Field flow fractionation data

Read, clean, and analyze field flow fractionation data using fffprocessr, available here.

Coagulation modeling

An implementation of the Edwards (1997) model in R is available here, or via install.packages("edwards97").

Geochemical modeling

Dewey Dunnington's tidyphreeqc (available here) provides an interface to PHREEQC in R, and pbcusol is designed specifically for lead and copper solubility modeling (available here).

References

Chen, W., Westerhoff, P., Leenheer, J. A., & Booksh, K. (2003). Fluorescence excitation−emission matrix regional integration to quantify spectra for dissolved organic matter. Environmental science & technology, 37(24), 5701-5710.

Edwards, M. (1997). Predicting DOC removal during enhanced coagulation. Journal American Water Works Association, 89(5), 78-89.

Tedetti, M., Cuet, P., Guigue, C., & Goutx, M. (2011). Characterization of dissolved organic matter in a coral reef ecosystem subjected to anthropogenic pressures (La Réunion Island, Indian Ocean) using multi-dimensional fluorescence spectroscopy. Science of the total environment, 409(11), 2198-2210.



bentrueman/cwrshelpr documentation built on July 1, 2023, 4:29 a.m.