read_wasatch_csv: Read File Saved by Wasatch's Enlighten.

View source: R/read-wasatch-csv.r

read_wasatch_csvR Documentation

Read File Saved by Wasatch's Enlighten.


Read wavelength and spectral data from the data section of a file as output by Enlighten importing them into R. Parse the header of a file to extract the acquisition time, instrument name and serial number, as well additional metadata related to the instrument and its settings. Function read_wasatch_csv() only accepts "column oriented" CSV files.


  date = NULL,
  geocode = NULL,
  label = NULL,
  tz = NULL,
  locale = readr::default_locale(),
  s.qty = NULL,
  extra.cols = "keep",
  scale.factor = 1,
  simplify = TRUE,





a POSIXct object to use to set the "when.measured" attribute. If NULL, the default, the date and time are extracted from the file header.


A data frame with columns lon and lat used to set attribute "where.measured".


character string, but if NULL the value of file is used, and if NA the "what.measured" attribute is not set.


character Time zone is by default that of the machine's locale.


The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names.


character, possibly named. The name of the quantity using the conventions accepted used in package 'photobiology' that is to be imported from column "Processed" from the file.


character What to do non-processed data columns if present in file. One of "keep", "drop.pixel", "drop" or "split".


numeric vector of length 1, or length equal to the number of rows (= detector pixels). Numeric multiplier applied to returned spectral values.


logical If TRUE, single spectra are returned as individual spectra instead of collections of length one.


additional arguments passed to the constructor of the spectrum object.


Enlighten's column-wise CSV files contain at least two columns, Wavelength and Processed. In the header the Technique used is recorded. Additional data columns can be present. Column Pixel contains the pixel index in the array as integers. Columns Raw, Dark and Reference contain detector counts data. Technique is used to guess the type of spectrum stored in the column named Processed, which can be detector counts or derived values. By default the data are read into a single spectrum object and all columns retained, but only the data in Processed are interpreted as spectral data corresponding to the class of the object. If passed extra.cols = "drop", only Wavelength and Processed are copied to the returned object, while if passed extra.cols = "drop.pixel" only the contents of column Pixel are discarded. If passed extra.cols = "split" all columns containing spectral data are each read into a separate spectrum, these are collected and a "generic_mspct" object containing them returned. extra.cols can be a named vector of mappings, of length at least one but possibly longer. If longer a "generic_mspct" is returned, otherwise a spectrum object as inferred from the name each column is mapped to.


An object of a class derived from generic_spct such as raw_spct or filter_spct. generic_spct is derived from tibble and data frame.


We thank Ruud Niesen from Photon Mission ( for organizing the loan of the spectrometer used to produce the various files needed for the development of this function.


Enlighten, the free software from Wasatch Photonics can save spectra in a variety of additional formats: different types of CSV files, plain text and JSON. Plain text files contain no metadata or even column headers and if the need arises can be read with R function read.table(). JSON files contain the most detailed metadata.


Examples <- 
   system.file("extdata", "enlighten-wasatch-scope.csv",
               package = "photobiologyInOut", mustWork = TRUE)
 wasatch.raw.spct <- 
   read_wasatch_csv(file =

 wasatch.raw.spct <- 
   read_wasatch_csv(file =, s.qty = "counts")

 wasatch.raw.spct <- 
   read_wasatch_csv(file =, s.qty = c(Processed = "counts"))

 wasatch.raw.spct <- 
   read_wasatch_csv(file =, extra.cols = "drop")

photobiologyInOut documentation built on Aug. 15, 2022, 9:09 a.m.