imp_searchAskColumns: Search and Ask for Column Representation

View source: R/prep_importData.r

imp_searchAskColumnsR Documentation

Search and Ask for Column Representation

Description

This function can be used in a custom import function. All required list elements except 'timestamp', 'info' and 'NIR' will be assigned in the environment from where this function was called.

Usage

imp_searchAskColumns(
  allC_var,
  allY_var,
  slType = get(".slType", pos = gl_ap2GD),
  oT = FALSE
)

Arguments

allC_var

A data frame containing only class variables.

allY_var

A data frame containing only numerical variables.

slType

What type of sample list is used during the import. If no additional sample list is used (slType = 'NULL'), the function stops if no column for the nr. of consec. scan is present or gets assigned. You can get the current slType with 'get(".slType", pos=gl_ap2GD)' - see example.

oT

Logical. Only used for testing. Leave at the default FALSE.

Details

This function checks if any of the in the settings.r file defined standard column names are present in the provided class-variables and numerical variables. If no exact match is found, the function asks which one of the provided columns is representing each of the standard columns. Those columns that do not get assigned to one of the standard columns will be imported under their respective name with the corresponding prefix for class- or numerical variables.

Value

All the list elements needed in the custom_import function except 'timestamp', 'info' and 'NIR get assigned in the environment from where this function was called.

See Also

Other Development Functions: custom_TRH, custom_import, 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)
   #
   allY_var <- import[,c(1,2,10,11,6)]
   allC_var <- import[, c(3,4,8,9,5,7)] 
   info <- list(nCharPrevWl = 2)
   NIR <- as.matrix(import[, 12:18])
   rownames(NIR) <- paste("S", 1:nrow(NIR), sep="")
   timestamp <- NULL
   imp_searchAskColumns(allC_var, allY_var, get(".slType", pos=gl_ap2GD)) 
   # assigns all list elements except timestamp, info and NIR
   #
   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 March 29, 2024, 7:33 a.m.