custom_import: Customising Spectral Import

custom_importR Documentation

Customising Spectral Import

Description

Cou can provide your own import function for importing spectral data. The .r file containing this function has to be located in the folder specified in the .Renviron file. (see 'Note' in updateSettings) To tell the package to use your custom function, you have to provide the character "custom@yourFile.r" to the approrpiate arguments (like e.g. the function getFullData), with "yourFile.r" being the name of the .r file containing the function.

Details

The requirements for this .r file are as follows: There need to be two and only to objects in this file, having the names "fileExtension" and "spectralImport". All other objects will be ignored.

  • fileExtension: Provide a character length one containing the extension of your raw-spectra file, e.g. ".txt" for a text file.

  • spectralImport: This is the function itself. The first argument has to be the data file. No additional arguments than the first one will be used. Provide any necessary defaults in the function itself.

Value

The returned value of the function has to be a list with named elements as listed below. If you do not have or want to provide content for an element it has to be set to 'NULL'.

  • sampleNr Data frame or NULL. A data frame with one column containing the sample numbers.

  • conSNr Data frame or NULL. A data frame with one column containing the number of the consecutive scan.

  • timePoints Data frame or NULL. A data frame with one column containing a character representation of the points in time at which the measurements were done.

  • ecrm Data frame or NULL. A data frame with one column containing a character representation to distinguish between 'environmental control' or real measurement'.

  • repl Data frame or NULL. A data frame with one column containing a character representation of the groups in the experiment like e.g. "Cont" for control, ... etc.

  • temp Data frame or NULL. A data frame with one column containing the numerical values of the room temperature.

  • relHum Data frame or NULL. A data frame with one column containing the numerical values of the relative humidity.

  • C_cols Data frame or NULL. A data frame with any number of columns containing only class-variables, i.e. non-numeric variables.

  • Y_cols Data frame or NULL. A data frame with any number of columns containing only numeric variables.

  • timestamp Data frame or NULL. A data frame with one column containing a timestamp in POSIXct format.

  • info A list containing the following named elements:

    • nCharPrevWl Numeric length one, indicating the numbers of characters (if any) before the actual wavelength. Set to '0' if you do not have characters before the wavelength.

  • NIR A matrix containing the NIR-spectra, with the wavelengths as column names and the sample-names as the rownames.

You can use the function imp_searchAskColumns to automatize column asignment.

Note

Every list element except 'NIR' and 'info' can be set to NULL.

See Also

Other Development Functions: custom_TRH, imp_searchAskColumns(), readHeader(), readSpectra()

Examples

## Not run: 
# this could be the content of the .r file for defining a custom function, 
# in this example for an import from an Excel-file.
fileExtension <- ".xlsx"
##
spectralImport <- function(dataFile) {
   require(openxlsx)
   import <- openxlsx::read.xlsx(dataFile)
   #
   sampleNr <- import[1]
   conSNr <- import[2]
   timePoints <- import[3]
   ecrm <- import[4]
   repl <- import[8]
   group <- import[9]
   temp <- import[10]
   relHum <- import[11]
   C_cols <- import[, c(5,7)]
   Y_cols <- import[6]
   timestamp <- NULL
   info <- list(nCharPrevWl = 2)
   NIR <- as.matrix(import[, 12:18])
   rownames(NIR) <- paste("S", 1:nrow(NIR), sep="")
   #
   return(list(sampleNr=sampleNr, conSNr=conSNr, timePoints=timePoints, 
   ecrm=ecrm, repl=repl, group=group, temp=temp, relHum=relHum, C_cols=C_cols, 
   Y_cols=Y_cols, timestamp=timestamp, info=info, NIR=NIR))
   #
 } # EOF

## End(Not run)

bpollner/aquap2 documentation built on June 29, 2024, 5:21 p.m.