#> Warning: Code evaluation in fileio.Rmd DISABLED!

Consistent naming of file import functions in version >= 0.99

From now on, all import functions have names starting with read.*(). All functions previously named scan.<span class=“sc”>*() have been renamed accordingly.

Supported File Formats

From now on, all import functions have names starting with read.*(). All functions previously named scan.*() have been renamed accordingly.

Package hyperSpec supports several file formats relevant for different types of spectroscopy. This file format is naturally only a subset of the file formats produced by different spectroscopic equipment.

If you use package hyperSpec with data formats not mentioned in this document, please open a new issue in hyperSpec’s GitHub repository so that this document can be updated. The information should include:

  • The type of spectroscopy,
  • Spectrometer model, manufacturer, and software,
  • The “native” file format (including a sample file),
  • Description of relevant procedures to convert the file,
  • R code to import the data together with an example file that is read by R,
  • Documentation, particularly the description of the data format.

If you need help finding out how to import your data, please search and eventually ask on Stackexchange with tags [r] and [spectroscopy].

Reproducing the Examples in this Manual

To run the code examples, create a folder named “fileio” in your working directory and copy the contents of the directory https://github.com/cbeleites/hyperSpec/tree/develop/Vignettes/fileio. This online directory contains the required datasets (via git-lfs).


1 Introduction

This document describes how to import files containing spectra into hyperSpec objects, as well as exportinghyperSpec objects as files.

The most basic funtion to create hyperSpec objects is new("hyperSpec") (section 2). It makes a hyperSpec object from data already in R’s workspace. Thus, after spectra importation into R, conversion to hyperSpec objects is straightforward.

Additionally, the hyperSpec package comes with predefined import functions for different data formats. This document divides the discussion into dealing with ASCII files (section 5) and binary file formats (section 6). If data export for the respective format is possible, we discuss it in the same sections. As sometimes the actual data written by the spectrometer software exhibits peculiarities, package hyperSpec offers several specialized import functions. In general, the naming convention is the data format followed by the manufacturer (e.g., read.ENVI.Nicolet).

Overview lists of the directly supported file formats are in the appendix: sorted by file format (9.1), manufacturer (9.2), and by spectroscopy (9.3).

2 Creating a hyperSpec object with new()

To create a hyperSpec object from data in R’s workspace, use:

spc <- new("hyperSpec", spc, wavelength, data, labels)

With the arguments:

spc the spectra matrix (may also be given as matrix inside column $spc of data)
wavelength the wavelength axis vector
data the extra data (possibly already including the spectra matrix in column spc)
labels a list with the proper labels. Do not forget the wavelength axis label in $.wavelength and the spectral intensity axis label in $spc.

Thus, once the data is in R’s workspace, creating a hyperSpec object is easy. We suggest wrapping the code to import the data and the line joining it into a hyperSpec object by a user-created import function. Users are more than welcome to contribute such import code to package hyperSpec. Secion 8 discusses examples of custom import functions.

2.1 Creating a hyperSpec Object from a Data Matrix (Spectra Matrix)

As spectra matrices are the internal format of hyperSpec, the constructor can directly be used:

spc <- new("hyperSpec", spc, wavelength, data, labels)

2.2 Creating a hyperSpec Object from a Data Cube (Spectra Array)

Roberto Moscetti asked how to convert a hyperspectral data cube into a hyperSpec object:

The problem is that I have a hypercube with the following dimensions: 67 × 41 × 256 y = 67 x = 41 wavelengths = 256

I do not know the way to import the hypercube.

Data cubes (i.e., 3-dimensional arrays of spectral data) result from spectral imaging measurements, where spectra are supplied for each pixel of an \(px.x × px.y\) imaging area. They have three directions, usually \(x\), \(y\), and the spectral dimension.

The solution is to convert the array into a spectra matrix and have separate \(x\) and \(y\) coordinates.

Assume data is the data cube, and x, y and wl hold vectors with the proper \(x\) and \(y\) coordinates and the wavelengths:

data <- array(1:24, 4:2)
wl <- c(550, 630)
x <- c(1000, 1200, 1400)
y <- c(1800, 1600, 1400, 1200)
data

Such data can be converted into a hyperSpec object by:

d <- dim(data)
dim(data) <- c(d[1] * d[2], d[3])

x <- rep(x, each = d[1])
y <- rep(y, d[2])

spectra <- new("hyperSpec",
  spc = data,
  data = data.frame(x, y), wavelength = wl
)

If no proper coordinates (vectors x, y and wl) are available, they can be left out. In the case of \(x\) and \(y\), map plotting will then be impossible, missing wavelengths will be replaced by column indices counting from 1 to d[3] automatically. Of course, such sequences (the row/column/pixel numbers) can be used instead of the original x and y as well:

y <- seq_len(d[1])
x <- seq_len(d[2])

Data cubes often come from spectral imaging systems that use an “image” coordinate system counting \(y\) from top to bottom. Note that this should be accounted for in the decreasing order of the original y vector.

3 General behaviour of file import functions: Options file.keep.name and file.remove.emptyspc

4 Reading Multiple files into one hyperSpec object

Many of the function described below will work on one file, even though derived functions such as read.spc.KaiserMap() (see section ??) may take care of measurements consisting of multiple files.

Usually, the most convenient way to import multiple files into one hyperSpec object is reading all files into a list of hyperSpec objects, and then collapse()ing this list into a single hyperSpec object:

files <- Sys.glob("fileio/spc.Kaisermap/*.spc")
files <- files[seq(1, length(files), by = 2)] # import low wavenumber region only
spc <- lapply(files, read.spc)
length(spc)
spc[[1]]
spc <- collapse(spc)
spc

Note that in this particular case, the spectra are more efficiently read by read.spc.KaiserMap() (see section ??).

If one regularly imports huge maps or images, writing a customized import function is highly encouraged. Users may gain speed and memory by using the internal workhorse functions for the file import. In that case, please open an issue at (hySpc.read.txt’s GitHub repository) for advise (contributions to package hySpc.read.txt are welcome and all authors are listed appropriately in the function help page’s author section).

5 ASCII files

Currently, hyperSpec provides two functions for general ASCII data import:

  • read_txt_long() imports long format ASCII files, i.e., one intensity value per row.
  • read_txt_wide() imports wide format ASCII files, i.e., one spectrum per row.

The import functions immediately return a hyperSpec object.

Internally, they use read.table(), a very powerful ASCII import function. R supplies another ASCII import function, scan(). Function scan() imports numeric data matrices and is faster than read.table(), but cannot import column names. If the data does not contain a header or is not important and can safely be skipped, it may want to import the data using scan().

Note that R allows the use a variety of compressed file formats directly as ASCII files (for example, see section ??). Also, both read_txt_long() and read_txt_wide() accept connections instead of file names.

5.1 ASCII files with samples in columns

Richard Pena asked about importing another ASCII file type:

File Triazine5_31.txt corresponds to X ray powder diffraction data (Bruker AXS). The native files data”ra”are read with EVA software then they are converted into .uxd file with the File Exchange software (Bruker AXS). The .uxd file are opened with Excel software and saved as .txt file, .csv file (ChemoSpec) or .xls.

The first and following columns corresponds to the angle diffraction and the intensity values of samples respectively.

Thus, this file differs from the ASCII formats discussed above in that the samples are actually in columns whereas hyperSpec expects them to be in rows. The header line gives the name of the sample. Import is straightforward, and just the spectra matrix needs to be transposed to make a hyperSpec object:

file <- read.table("fileio/txt.t/Triazine_5_31.txt", header = TRUE, dec = ",", sep = "\t")

triazine <- new("hyperSpec",
  wavelength = file[, 1], spc = t(file[, -1]),
  data = data.frame(sample = colnames(file[, -1])),
  labels = list(
    .wavelength = expression(2 * theta / degree),
    spc = "I / a.u."
  )
)
triazine
plot(triazine[1])

WITec also saves ASCII data with spectra in columns (Export \(\rightarrow\) Table), see 7.5.

5.2 Basic Atomic Spectra from NIST Tables

The NIST (National Institute of Standards and Technology) has published a data base of basic atomic emission spectra see http://physics.nist.gov/PhysRefData/Handbook/periodictable.htm with emission lines tabulated in ASCII (HTML) files.

Here’s an example how to extract the data of the Hg strong lines file:

file <- readLines("fileio/NIST/mercurytable2.htm")
# file <- readLines("http://physics.nist.gov/PhysRefData/Handbook/Tables/mercurytable2.htm")

file <- file[-(1:grep("Intensity.*Wavelength", file) - 1)]
file <- file[1:(grep("</pre>", file)[1] - 1)]
file <- gsub("<[^>]*>", "", file)
file <- file[!grepl("^[[:space:]]+$", file)]

colnames <- file[1]
colnames <- gsub("[[:space:]][[:space:]]+", "\t", file[1])
colnames <- strsplit(colnames, "\t")[[1]]
if (!all(colnames == c("Intensity", "Wavelength (&Aring;)", "Spectrum", "Ref. "))) {
  stop("file format changed!")
}

tablestart <- grep("^[[:blank:]]*[[:alpha:]]+$", file) + 1
tableend <- c(tablestart[-1] - 2, length(file))
tables <- list()
for (t in seq_along(tablestart)) {
  tmp <- file[tablestart[t]:tableend[t]]
  tables[[t]] <- read.fwf(textConnection(tmp), c(5, 8, 12, 15, 9))
  colnames(tables[[t]]) <- c("Intensity", "persistent", "Wavelength", "Spectrum", "Ref. ")
  tables[[t]]$type <- gsub("[[:space:]]", "", file[tablestart[t] - 1])
}
tables <- do.call(rbind, tables)
levels(tables$Spectrum) <- gsub(" ", "", levels(tables$Spectrum))

Hg.AES <- list()
for (s in levels(as.factor(tables$Spectrum))) {
  Hg.AES[[s]] <- new("hyperSpec",
    wavelength = tables$Wavelength[tables$Spectrum == s],
    spc = tables$Intensity[tables$Spectrum == s],
    data = data.frame(Spectrum = s),
    label = list(
      .wavelength = expression(lambda / ring(A)),
      spc = "I"
    )
  )
}
plot(collapse(Hg.AES), lines.args = list(type = "h"), col = 1:2)

5.3 Further ASCII Formats

Further import filters are provided for manufacturer/software specific ASCII formats, see table 9.1 and section 7.1.

5.4 ASCII Export

ASCII export can be done in wide and long format using write_txt_long() and write_txt_wide(). If you need a specific header or footer, use R’s functions for writing files: write.table(), write(), cat() and so on offer fine-grained control of writing ASCII files.

6 Binary file formats

6.1 Matlab Files

Matlab files can be read and written using the package R.matlab, which is available at CRAN and can be installed by install.packages("R.matlab").

spc.mat <- readMat("fileio/spectra.mat")

If the .mat file was saved with compression, the additional package Rcompression is needed. It can be installed from omegahat:

install.packages("Rcompression", repos = "http://www.omegahat.org/R")

See the documentation of package R.matlab for more details and possibly needed further packages.

Function readMat() imports the .mat file’s contents as a list. The variables in the .mat file are appropriately named elements of the list. The hyperSpec object can be created using new(), see section 2.

Again, users probably want to wrap the import of their Matlab files into a function.

6.1.1 Matlab Export

package R.matlab’s function writeMat() can be used to write R objects into .mat files. To save an hyperSpec object x for use in Matlab, you most likely want to save:

  • the wavelength axis as obtained by wl(x),
  • the spectra matrix as obtained by x[[]], and
  • possibly also the extra data as obtained by x$..
  • as well as the axis labels labels(x).
  • Alternatively, x$. yields the extra data together with the spectra matrix.

However, it may be convenient to transform the saved data according to how it is needed in Matlab. The functions as.long.df() and as.wide.df() may prove useful for reshaping the data.

6.1.2 Deriving manufacturer specific import filters

Please note that future changes inside the read.spc function is likely to occur. However, if you just post-process the hyperSpec object returned by read.spc(), you should be fine.

7 Manufacturer-Specific Discussion of File Import

7.1 Manufacturer Specific Import Functions

Many spectrometer manufacturers provide a function to export their spectra into ASCII files. The functions discussed above are written in a very general way and are highly customizable. We recommend wrapping these calls with the appropriate settings for the spectra format in an import function. Please consider contributing such import filters to package hyperSpec: send us the documented code (for details, see the box at the beginning of this document). If there is any format not mentioned in this document (even without the need of new converters), please let me know (details again in the box at the beginning of this document).

7.2 Renishaw ASCII data

An optimized import function for the ASCII files is available: read_txt_Renishaw(). The file may be compressed via gzip, bzip2, xz or lzma. Zip compressed files are read via read_zip_Renishaw(). The ASCII files can easily become very large, particularly with linefocus or streamline imaging. Function read_txt_Renishaw() provides two mechanisms to avoid running out of memory during data import. The file may be imported in chunks of a given number of lines (see the last example). Function read_txt_Renishaw() can calculate the correct number of wavelengths (i.e., data points per spectrum) if the system command wc is available on your computer.

Also, the processing of the long ASCII format into the spectra matrix is done by reshaping the vector of intensities into a matrix. This process does not allow any missing values in the data. Therefore it is not possible to import multi-spectra files with individually “zapped” spectra using read_txt_Renishaw().

The second argument to read_txt_Renishaw() decides what type of experiment is imported. Supported types are:

"xyspc" maps, images, multiple spectra with \(x\) and \(y\) coordinates (default)
"spc" single spectrum
"depth", "zspc" depth series
"ts" time series

Instead of a file name, read_txt_Renishaw() accepts also a connection.

paracetamol <- read_txt_Renishaw(“fileio/txt.Renishaw/paracetamol.txt”, “spc”) paracetamol

Very large files can be read in chunks to save memory:

read_txt_Renishaw(“fileio/txt.Renishaw/chondro.txt”, nlines = 1e5, nspc = 875)

R accepts a variety of compressed file formats for ASCII files:

read_txt_Renishaw(“fileio/txt.Renishaw/chondro.gz”) read_txt_Renishaw(“fileio/txt.Renishaw/chondro.xz”) read_txt_Renishaw(“fileio/txt.Renishaw/chondro.lzma”) read_txt_Renishaw(“fileio/txt.Renishaw/chondro.gz”) read_txt_Renishaw(“fileio/txt.Renishaw/chondro.bz2”) read_zip_Renishaw(“fileio/txt.Renishaw/chondro.zip”)

7.3 Horiba / Jobin Yvon (e.g., LabRAM)

Horiba’s Labspec software (e.g., LabRAM spectrometers) saves spectra in a wide ASCII format which is read by read_txt_Horiba(), e.g.:

spc <- read_txt_Horiba(“fileio/txt.HoribaJobinYvon/ts.txt”, cols = list( t = “t / s”, spc = “I / a.u.”, .wavelength = expression(Delta * tilde(nu) / cm^-1) ) ) spc

Note that Labspec .txt files can contain lots of spectra with zero intensity: Labspec saves a complete rectangular grid even if only part of a map was measured. These spectra are by removed by default if option file.remove.emptyspc is TRUE (the default).

For convenience, functions to further wrappers to import maps (read_txt_Horiba_xy()) and time series (read_txt_Horiba_t()) are provided.

spc <- read_txt_Horiba_xy("fileio/txt.HoribaJobinYvon/map.txt")
if (any(dim(spc) != c(141, 4, 616)) ||
  any(abs(spc) < .Machine$double.eps^.5) ||
  is.null(spc$x) || any(is.na(spc$x)) ||
  is.null(spc$y) || any(is.na(spc$y)) ||
  length(setdiff(wl(spc), 1:616)) == 0L) {
  pkg <- "hySpc.read.txt"
  stop(
    "error in testing read_txt_Horiba_xy(). ",
    "opening an issue at \n",
    packageDescription(pkg)$BugReports
  )
}
spc
spc <- read_txt_Horiba_t("fileio/txt.HoribaJobinYvon/ts.txt")
if (any(dim(spc) != c(100, 3, 1024)) ||
  is.null(spc$t) || any(is.na(spc$t)) ||
  length(setdiff(wl(spc), 1:1024)) == 0L) {
  pkg <- "hySpc.read.txt"
  stop(
    "error in testing read_txt_Horiba_xy(). ",
    "opening an issue at \n",
    packageDescription(pkg)$BugReports
  )
}

spc
rm(spc)

7.4 Andor Solis

Andor Solis exports ASCII files that can be read with read.asc.Andor():

read.asc.Andor("fileio/asc.Andor/ASCII-Andor-Solis.asc")

7.5 WITec

The WITec project software supports exporting spectra as Thermo Galactic .spc files.

read.spc(“fileio/spc.Witec/Witec-timeseries.spc”) read.spc(“fileio/spc.Witec/Witec-Map.spc”)

.spc is in general the recommended format for package hyperSpec import. For imaging data, no spatial information for the set of spectra is provided (in version 2.10, this export option is not supported).

Imaging data (but also single spectra and time series) can be exported as ASCII X and Y files (Save ASCII X and Save ASCII Y, not supported in version 4). These can be read by read_dat_WITec():

read_dat_WITec(“fileio/txt.Witec/Witec-timeseries-x.dat”) read_dat_WITec( filex = “fileio/txt.Witec/Witec-Map-x.dat”, points.per.line = 5, lines.per.image = 5, type = “map” )

Note that the Y data files also contain wavelength information, but (at least WITec Project 2.10) this information is always wavelength in nm, not Raman shift in wavenumbers: this is provided by the X data file only.

Another option is WITec’s txt table ASCII export (Export \(\rightarrow\) Table), which produces ASCII files with each row corresponding to one wavelength. The first column contains the wavelength axis; all further columns contain one spectrum each column. Such files can be read with read_txt_WITec():

read_txt_WITec() determines the number of wavelengths automatically.

Note that there are several Export Filter Options. It is possible to determine which units should be used for the export (see XUnits tab). It is also possible to export two additional header lines containing information about spectra labels and units. Therefore parameters hdr.label and hdr.units have to be set properly. Otherwise, either an error will be displayed like

or the one or two wavelengths will be skipped.

Depending on the used export options the header files should look like:

For imaging data set parameter type to “map”. If the label header is exported, the spatial information can be extracted from this line. Otherwise, at least one, points.per.line or lines.per.image, has to be given manually, if not, a warning will be shown.

For line scans and z-stacks use type = "single" because the provided information is looking the same as for time series, so no further information can be extracted from the header files.

Since version 4 WITec Project offers the Graph ASCII export (Export \(\rightarrow\) Graph ASCII), which produces three ASCII files, named Header containing additional information, X-Axis containing the wavelength values and Y-Axis containing the spectra one spectrum in each column. Data exported in this way can be read with read_txt_Witec_Graph():

read_txt_Witec_Graph(“fileio/txt.Witec/Witec-timeseries (Header).txt”) read_txt_Witec_Graph(“fileio/txt.Witec/Witec-Map (Header).txt”, type = “map”) read_txt_Witec_Graph(“fileio/txt.Witec/nofilename (Header).txt”, encoding = “latin1”)

This function reads the spectra files automatically, if they are appropriately named and extracts additional information of the header file. As for the other Witec functions, it is possible to read image data by selecting type = "map". Line scans and z-stacks should be read as single spectra.

8 Writing your own Import Function

This section gives examples of how to write import functions. The first example implements an import filter for an ASCII file format, basically from scratch. The second example shows how to implement more details for an already existing import filter.

8.1 A new ASCII Import Function: read_txt_PerkinElmer

The raw spectra of the flu data set (see also the separate vignette) are in PerkinElmer’s ASCII file format, one spectrum per file.

We need a function that automatically reads all files specified by a pattern, such as *.txt. To gain speed, users should preallocate the spectra matrix after the first reading of the file.

A short examination of the files (flu*.txt in directory txt.PerkinElmer) reveals that the actual spectrum starts at line 55, after a line containing \#DATA. For now, no other information about the files is to be extracted. It is thus easier to skip the first 54 lines than searching for the line after \#DATA.

A fully-featured import function should support:

  • Reading multiple files by giving a pattern
  • hand further arguments to scan(). This comes handy in case the function is used later to import other data types.
  • Also, skipping 54 lines would be a weird default, so we instead require it to be given explicitly.
  • The same applies to the axis labels: they should default to reasonable settings for fluorescence spectra, but it should be possible to change them.
  • The usual log entry arguments should be supplied.
  • A sanity check should be implemented: stop with an error if a file does not have the same wavelength axis as the others.
  • If no file can be found, an empty hyperSpec object is a consistent result: There is no need to stop with an error, but it is polite to issue an additional warning.
  • Finally, package hyperSpec does some optional common post-processing for all imported files such as attaching the filename (or connection description) to the hyperSpec object (column filename) and deleting empty spectra. These options can be globally switched on or off by options.

# Function -------------------------------------------------------------------

#' Read PerkinElmer file (ASCII/txt)
#'
#' @param file Path to file or several files
#' @param ... Passed to [base::scan()].
#' @param label Labels.
#'
#'
#' @return [hyperSpec][hyperSpec::hyperSpec-class()] object.
#'
#'
#' @export
#'
read_txt_PerkinElmer <- function(file = stop("filenames needed"),
                                 ...,
                                 label = list()) {


  ##  set default labels
  label <- modifyList(
    list(
      .wavelength = expression(lambda / nm),
      spc = expression(I[fl] / "a.u.")
    ),
    label
  )

  if (length(file) == 0) {
    warning("No files found.")
    return(new("hyperSpec"))
  }

  ## read the first file
  buffer <- matrix(scan(file[1], ...), ncol = 2, byrow = TRUE)

  ## first column gives the wavelength vector
  wavelength <- buffer[, 1]

  ## preallocate the spectra matrix:
  ##  one row per file x as many columns as the first file has
  spc <- matrix(ncol = nrow(buffer), nrow = length(file))

  ## the first file's data goes into the first row
  spc[1, ] <- buffer[, 2]

  ## now read the remaining files
  for (f in seq(along = file)[-1]) {
    buffer <- matrix(scan(file[f], ...), ncol = 2, byrow = TRUE)

    ## check whether they have the same wavelength axis
    if (!all.equal(buffer[, 1], wavelength)) {
      stop(paste(file[f], "has different wavelength axis."))
    }

    spc[f, ] <- buffer[, 2]
  }

  ## make the hyperSpec object
  spc <- new("hyperSpec", wavelength = wavelength, spc = spc, label = label)

  ## consistent file import behavior across import functions
  .spc_io_postprocess_optional(spc, file)
}


# Unit tests -----------------------------------------------------------------

# FIXME: add unit tests

imports the spectra. Note how the labels are set. The label with the special name .wavelength corresponds to the wavelength axis, all data columns should have a label with the same name. The spectra are always in a data column called spc.

Thus,

source(“read_txt_PerkinElmer.R”) read_txt_PerkinElmer(Sys.glob(“fileio/txt.PerkinElmer/flu?.txt”), skip = 54)

imports the spectra.

The hyperSpec package does not export this function: while it is already useful for importing files, it is not general enough to work immediately with new data, e.g., completely ignoring the file header. Thus information like the excitation wavelength is lost.

9 Appendix A: File Import Functions

9.1 File Import Functions by Format

Type Format Manufacturer Spectroscopy Function Link Notes
Andor Solis ASCII
ASCII Andor Solis ASCII Andor Raman read.asc.Andor() 7.4
array
binary array 2
ASCII long
ASCII ASCII long read.txt.long() 5
ASCII ASCII long Renishaw Raman read.txt.Renishaw() ??
ASCII ASCII long Kaiser Raman read.txt.long() ?? Not recommended, see discussion
ASCII ASCII long Perkin Elmer Fluorescence read.txt.PerkinElmer() 8.1 Reads multiple files, needs to be sourced.
ASCII long (zipped)
ASCII ASCII long (zipped) Renishaw Raman read.zip.Renishaw() ??
ASCII wide
ASCII ASCII wide read.txt.wide() 5
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba() 7.3 e.g., LabRAM spectrometers
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.xy() 7.3 e.g., LabRAM spectrometer maps
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.t() 7.3 e.g., LabRAM spectrometer time series
ASCII wide transposed
ASCII ASCII wide transposed Witec Raman read.txt.Witec() ?? Export Table
ENVI
binary ENVI read.ENVI() ??
binary ENVI Bruker Infrared Imaging read.ENVI() ??
binary ENVI Nicolet Infrared Imaging read.ENVI.Nicolet() ??
hol
binary hol Kaiser Raman ?? via Matlab
JCAMP-DX
ASCII JCAMP-DX read.jdx() ??
ASCII JCAMP-DX Renishaw Raman read.jdx() ??
ASCII JCAMP-DX Shimadzu GCxGC-MS read.txt.Shimadzu()
ASCII JCAMP-DX PerkinElmer Infrared read.jdx() ?? import for subset of the JCAMP-DX standard
Matlab
binary Matlab Matlab R.matlab::readMat() 6.1
binary Matlab Cytospec read.mat.Cytospec() ??
binary Matlab Witec Raman read.mat.Witec()
matrix
binary matrix 2
Opus
binary Opus Bruker Infrared Imaging ??
other
ASCII other Shimadzu GC,GC-MS read.jdx() ?? import for subset of the JCAMP-DX standard
spc
binary spc read.spc() ??
binary spc Kaiser Raman Map read.spc.KaiserMap() ?? Reads multiple files
binary spc Kaiser Raman read.spc.Kaiser() Efficiently reads multiple files
binary spc Kaiser Raman read.spc.KaiserLowHigh() Reads multiple pairs of low and high wavenumber region spcs
binary spc Kaiser Raman read.spc() ??
binary spc Renishaw Raman read.spc() ?? Not recommended, see discussion of ASCII files.
binary spc Witec Raman read.spc() ?? spc export not available for images
binary spc Horiba Raman read.spc() ??
spe
binary spe Princeton Instruments Raman read.spe() ?? WinSpec
Witec ASCII
ASCII Witec ASCII Witec Raman read.dat.Witec() ?? Save ASCII X, Save ASCII Y
Witec Graph ASCII
ASCII Witec Graph ASCII Witec Raman read.txt.Witec.Graph() ?? Export Table in 3 separate files (Header, X-Axis, Y-Axis)

9.2 File Import Functions by Manufacturer

Type Format Manufacturer Spectroscopy Function Link Notes
Andor
ASCII Andor Solis ASCII Andor Raman read.asc.Andor() 7.4
Bruker
binary ENVI Bruker Infrared Imaging read.ENVI() ??
binary Opus Bruker Infrared Imaging ??
Cytospec
binary Matlab Cytospec read.mat.Cytospec() ??
Horiba
binary spc Horiba Raman read.spc() ??
Horiba Jobin Yvon
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba() 7.3 e.g., LabRAM spectrometers
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.xy() 7.3 e.g., LabRAM spectrometer maps
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.t() 7.3 e.g., LabRAM spectrometer time series
Kaiser
ASCII ASCII long Kaiser Raman read.txt.long() ?? Not recommended, see discussion
binary hol Kaiser Raman ?? via Matlab
binary spc Kaiser Raman Map read.spc.KaiserMap() ?? Reads multiple files
binary spc Kaiser Raman read.spc.Kaiser() Efficiently reads multiple files
binary spc Kaiser Raman read.spc.KaiserLowHigh() Reads multiple pairs of low and high wavenumber region spcs
binary spc Kaiser Raman read.spc() ??
Matlab
binary Matlab Matlab R.matlab::readMat() 6.1
Nicolet
binary ENVI Nicolet Infrared Imaging read.ENVI.Nicolet() ??
Perkin Elmer
ASCII ASCII long Perkin Elmer Fluorescence read.txt.PerkinElmer() 8.1 Reads multiple files, needs to be sourced.
PerkinElmer
ASCII JCAMP-DX PerkinElmer Infrared read.jdx() ?? import for subset of the JCAMP-DX standard
Princeton Instruments
binary spe Princeton Instruments Raman read.spe() ?? WinSpec
Renishaw
ASCII ASCII long Renishaw Raman read.txt.Renishaw() ??
ASCII ASCII long (zipped) Renishaw Raman read.zip.Renishaw() ??
ASCII JCAMP-DX Renishaw Raman read.jdx() ??
binary spc Renishaw Raman read.spc() ?? Not recommended, see discussion of ASCII files.
Shimadzu
ASCII other Shimadzu GC,GC-MS read.jdx() ?? import for subset of the JCAMP-DX standard
ASCII JCAMP-DX Shimadzu GCxGC-MS read.txt.Shimadzu()
Witec
ASCII Witec ASCII Witec Raman read.dat.Witec() ?? Save ASCII X, Save ASCII Y
ASCII ASCII wide transposed Witec Raman read.txt.Witec() ?? Export Table
ASCII Witec Graph ASCII Witec Raman read.txt.Witec.Graph() ?? Export Table in 3 separate files (Header, X-Axis, Y-Axis)
binary Matlab Witec Raman read.mat.Witec()
binary spc Witec Raman read.spc() ?? spc export not available for images
ASCII ASCII long read.txt.long() 5
ASCII ASCII wide read.txt.wide() 5
ASCII JCAMP-DX read.jdx() ??
binary ENVI read.ENVI() ??
binary spc read.spc() ??
binary array 2
binary matrix 2

9.3 File Import Functions by Spectroscopy

Type Format Manufacturer Spectroscopy Function Link Notes
Fluorescence
ASCII ASCII long Perkin Elmer Fluorescence read.txt.PerkinElmer() 8.1 Reads multiple files, needs to be sourced.
GC,GC-MS
ASCII other Shimadzu GC,GC-MS read.jdx() ?? import for subset of the JCAMP-DX standard
GCxGC-MS
ASCII JCAMP-DX Shimadzu GCxGC-MS read.txt.Shimadzu()
Infrared
ASCII JCAMP-DX PerkinElmer Infrared read.jdx() ?? import for subset of the JCAMP-DX standard
Infrared Imaging
binary ENVI Bruker Infrared Imaging read.ENVI() ??
binary Opus Bruker Infrared Imaging ??
binary ENVI Nicolet Infrared Imaging read.ENVI.Nicolet() ??
Raman
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba() 7.3 e.g., LabRAM spectrometers
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.xy() 7.3 e.g., LabRAM spectrometer maps
ASCII ASCII wide Horiba Jobin Yvon Raman read.txt.Horiba.t() 7.3 e.g., LabRAM spectrometer time series
ASCII ASCII long Renishaw Raman read.txt.Renishaw() ??
ASCII ASCII long (zipped) Renishaw Raman read.zip.Renishaw() ??
ASCII ASCII long Kaiser Raman read.txt.long() ?? Not recommended, see discussion
ASCII JCAMP-DX Renishaw Raman read.jdx() ??
ASCII Witec ASCII Witec Raman read.dat.Witec() ?? Save ASCII X, Save ASCII Y
ASCII ASCII wide transposed Witec Raman read.txt.Witec() ?? Export Table
ASCII Witec Graph ASCII Witec Raman read.txt.Witec.Graph() ?? Export Table in 3 separate files (Header, X-Axis, Y-Axis)
ASCII Andor Solis ASCII Andor Raman read.asc.Andor() 7.4
binary Matlab Witec Raman read.mat.Witec()
binary hol Kaiser Raman ?? via Matlab
binary spc Kaiser Raman read.spc.Kaiser() Efficiently reads multiple files
binary spc Kaiser Raman read.spc.KaiserLowHigh() Reads multiple pairs of low and high wavenumber region spcs
binary spc Kaiser Raman read.spc() ??
binary spc Renishaw Raman read.spc() ?? Not recommended, see discussion of ASCII files.
binary spc Witec Raman read.spc() ?? spc export not available for images
binary spc Horiba Raman read.spc() ??
binary spe Princeton Instruments Raman read.spe() ?? WinSpec
Raman Map
binary spc Kaiser Raman Map read.spc.KaiserMap() ?? Reads multiple files
ASCII ASCII long read.txt.long() 5
ASCII ASCII wide read.txt.wide() 5
ASCII JCAMP-DX read.jdx() ??
binary Matlab Matlab R.matlab::readMat() 6.1
binary Matlab Cytospec read.mat.Cytospec() ??
binary ENVI read.ENVI() ??
binary spc read.spc() ??
binary array 2
binary matrix 2

Session Info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21)
#>  os       Ubuntu 22.04.2 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en
#>  collate  C.UTF-8
#>  ctype    C.UTF-8
#>  tz       UTC
#>  date     2023-04-23
#>  pandoc   2.19.2 @ /usr/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────
#>  package        * version      date (UTC) lib source
#>  bookdown         0.33         2023-03-06 [2] RSPM
#>  brio             1.1.3        2021-11-30 [2] RSPM
#>  bslib            0.4.2        2022-12-16 [2] RSPM
#>  cachem           1.0.7        2023-02-24 [2] RSPM
#>  cli              3.6.1        2023-03-23 [2] RSPM
#>  colorspace       2.1-0        2023-01-23 [2] RSPM
#>  deldir           1.0-6        2021-10-23 [2] RSPM
#>  digest           0.6.31       2022-12-11 [2] RSPM
#>  dplyr            1.1.2        2023-04-20 [2] RSPM
#>  evaluate         0.20         2023-01-17 [2] RSPM
#>  fansi            1.0.4        2023-01-22 [2] RSPM
#>  fastmap          1.1.1        2023-02-24 [2] RSPM
#>  generics         0.1.3        2022-07-05 [2] RSPM
#>  ggplot2        * 3.4.2        2023-04-03 [2] RSPM
#>  glue             1.6.2        2022-02-24 [2] RSPM
#>  gtable           0.3.3        2023-03-21 [2] RSPM
#>  highr            0.10         2022-12-22 [2] RSPM
#>  htmltools        0.5.5        2023-03-23 [2] RSPM
#>  httr             1.4.5        2023-02-24 [2] RSPM
#>  hyperSpec      * 0.200.0.9000 2023-04-23 [2] Custom
#>  hySpc.testthat   0.2.1        2020-06-24 [2] RSPM
#>  interp           1.1-4        2023-03-31 [2] RSPM
#>  jpeg             0.1-10       2022-11-29 [2] RSPM
#>  jquerylib        0.1.4        2021-04-26 [2] RSPM
#>  jsonlite         1.8.4        2022-12-06 [2] RSPM
#>  kableExtra       1.3.4        2021-02-20 [2] RSPM
#>  knitr            1.42         2023-01-25 [2] RSPM
#>  lattice        * 0.21-8       2023-04-05 [4] CRAN (R 4.3.0)
#>  latticeExtra     0.6-30       2022-07-04 [2] RSPM
#>  lazyeval         0.2.2        2019-03-15 [2] RSPM
#>  lifecycle        1.0.3        2022-10-07 [2] RSPM
#>  magrittr         2.0.3        2022-03-30 [2] RSPM
#>  munsell          0.5.0        2018-06-12 [2] RSPM
#>  pillar           1.9.0        2023-03-22 [2] RSPM
#>  pkgconfig        2.0.3        2019-09-22 [2] RSPM
#>  png              0.1-8        2022-11-29 [2] RSPM
#>  purrr            1.0.1        2023-01-10 [2] RSPM
#>  R.cache          0.16.0       2022-07-21 [2] RSPM
#>  R.matlab       * 3.7.0        2022-08-25 [2] RSPM
#>  R.methodsS3      1.8.2        2022-06-13 [2] RSPM
#>  R.oo             1.25.0       2022-06-12 [2] RSPM
#>  R.utils          2.12.2       2022-11-11 [2] RSPM
#>  R6               2.5.1        2021-08-19 [2] RSPM
#>  RColorBrewer     1.1-3        2022-04-03 [2] RSPM
#>  Rcpp             1.0.10       2023-01-22 [2] RSPM
#>  rlang            1.1.0        2023-03-14 [2] RSPM
#>  rmarkdown        2.21         2023-03-26 [2] RSPM
#>  rstudioapi       0.14         2022-08-22 [2] RSPM
#>  rvest            1.0.3        2022-08-19 [2] RSPM
#>  sass             0.4.5        2023-01-24 [2] RSPM
#>  scales           1.2.1        2022-08-20 [2] RSPM
#>  sessioninfo      1.2.2        2021-12-06 [2] RSPM
#>  stringi          1.7.12       2023-01-11 [2] RSPM
#>  stringr          1.5.0        2022-12-02 [2] RSPM
#>  styler           1.9.1        2023-03-04 [2] RSPM
#>  svglite          2.1.1        2023-01-10 [2] RSPM
#>  systemfonts      1.0.4        2022-02-11 [2] RSPM
#>  testthat         3.1.7        2023-03-12 [2] RSPM
#>  tibble           3.2.1        2023-03-20 [2] RSPM
#>  tidyselect       1.2.0        2022-10-10 [2] RSPM
#>  utf8             1.2.3        2023-01-31 [2] RSPM
#>  vctrs            0.6.2        2023-04-19 [2] RSPM
#>  viridisLite      0.4.1        2022-08-22 [2] RSPM
#>  webshot          0.5.4        2022-09-26 [2] RSPM
#>  withr            2.5.0        2022-03-03 [2] RSPM
#>  xfun             0.39         2023-04-20 [2] RSPM
#>  xml2             1.3.3        2021-11-30 [2] RSPM
#>  yaml             2.3.7        2023-01-23 [2] RSPM
#> 
#>  [1] /tmp/RtmpWHzGNC/temp_libpath17e24d22b217
#>  [2] /home/runner/work/_temp/Library
#>  [3] /opt/R/4.3.0/lib/R/site-library
#>  [4] /opt/R/4.3.0/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────────────────────────

References