Learn R Programming

ChemoSpec (version 4.3.34)

matrix2SpectraObject: Process a Data Matrix in a csv File into a Spectra Object

Description

This function takes a csv-like file, containing frequencies in the first column, and samples in additional columns, and processes it into a Spectra object. The file should contain a header row which includes the sample names. The file can have any combination of delimiters and decimal marks (see below).

Usage

matrix2SpectraObject(gr.crit = NULL, gr.cols = c("auto"), freq.unit = "no frequency unit provided", int.unit = "no intensity unit provided", descrip = "no description provided", in.file = NULL, out.file = "mydata", chk = TRUE, ...)

Arguments

gr.crit
Group Criteria. A vector of character strings which will be searched for among the file names in order to assign an individual spectrum/sample to group membership. Warnings are issued if there are file names that don't match entries in gr.crit or there are entries in gr.crit that don't match any file names. See Details for some nuances.
gr.cols
Group Colors. Either the word "auto", in which case colors will be automatically assigned, or a vector of acceptable color names with the same length as gr.crit. In the latter case, colors will be assigned one for one, so the first element of gr.crit is assigned the first element of gr.col and so forth. See details below for some other issues to consider.
freq.unit
A character string giving the units of the x-axis (frequency or wavelength).
int.unit
A character string giving the units of the y-axis (some sort of intensity).
descrip
A character string describing the data set that will be stored. This string is used in some plots so it is recommended that its length be less than about 40 characters.
in.file
Character. Input file name, including extension.
out.file
A file name acceptable to the save function. The completed object of S3 class Spectra will be written to this file.
chk
Logical. Should the Spectra object be checked for integrity? If you are having trouble importing your data, set this to FALSE and do str(your object) to troubleshoot.
...
Additional arguments to be passed to read.table. In particular, you MUST give a value for sep and decimal, nothing is assumed. This gives maximum flexibility in reading in a variety of formats.

Value

A object of class Spectra. An unnamed object of S3 class Spectra is also written to out.file. To read it back into the workspace, use new.name <- loadObject(out.file) (loadObject is package R.utils).

Warning

Samples whose names are not matched using gr.crit are still incorporated into the Spectra object, but they are not assigned a group or color and therefore don't plot, but they do take up space in a plot!

Details

The linking of groups with colors is handled by groupNcolor.

The matching of gr.crit against the sample file names is done one at a time, in order. This means that the entries in gr.crit must be mutually exclusive. For example, if you have files with names like "Control_1" and "Sample_1" and use gr.crit = c("Control", "Sample") groups will be assigned as you would expect. But, if you have file names like "Control_1_Shade" and "Sample_1_Sun" you can't use gr.crit = c("Control", "Sample", "Sun", "Shade") because each criteria is grepped in order, and the "Sun/Shade" phrases, being last, will form the basis for your groups. Because this is a grep process, you can get around this by using regular expressions in your gr.crit argument to specify the desired groups in a mutually exclusive manner. In this second example, you could use gr.crit = c("Control(.*)Sun", "Control(.*)Shade", "Sample(.*)Sun", "Sample(.*)Shade") to have your groups assigned based upon both phrases in the file names.

References

https://github.com/bryanhanson/ChemoSpec