This function defines the translation table used as input to TranslateStoxBiotic and similar functions to translate values of one or more columns to new values given by a table or read from a CSV file.

DefineTranslation(
  processData,
  UseProcessData = FALSE,
  DefinitionMethod = c("ResourceFile", "Table"),
  FileName = character(),
  VariableName = character(),
  Conditional = FALSE,
  ConditionalVariableNames = character(),
  TranslationTable = data.table::data.table(),
  ValueColumn = character(),
  NewValueColumn = character(),
  ConditionalValueColumns = character()
)

Arguments

processData

The current data produced by a previous instance of the function.

UseProcessData

Logical: If TRUE use the existing function output in the process.

DefinitionMethod

Character: A string naming the method to use, one of "ResourceFile", for reading the table from the file given by FileName; and "Table", for defining the TranslationTable directly as an input.

FileName

The csv file holding a table with the TranslationTable. Required columns are given by ValueColumn and NewValueColumn, and, in the case that Conditional == TRUE, ConditionalValueColumns.

VariableName

The name of the variable to translate. This will be the name of the first column of the TranslationTable when generated from the StoX GUI.

Conditional

Logical: If TRUE condition the translation on values of other variables.

ConditionalVariableNames

The names of the variables to condition the translation on. Must be given if Conditional == TRUE. This will be the name(s) of the third column and onwards of the TranslationTable when generated from the StoX GUI.

TranslationTable

A table holding the following columns: The first column holds the values to translate FROM, the second column holds the values to translate TO, and the remaining zero or more columns holds the values for the conditional variables specified in ConditionalVariableNames. I.e., if VariableName = "IndividualAge" and ConditionalVariableNames = "IndividualSex", and the TranslationTable has values 3, 4 and "F" in the first row, female fish at age 3 are translated to age 4. Use NA to translate missing values (shown as "-" in Preview in the StoX GUI, and usually as empty cell in excel). Values in the TranslationTable can be given either as single values or as expressions of functions of the variable specified by the column name. See details of DefineTranslation.

ValueColumn, NewValueColumn

The name of the columns of FileName representing the current values and the values to translate to, respectively.

ConditionalValueColumns

The names of the columns of FileName representing the conditional values.

Value

A Translation object.

Details

The columns of the TranslationTable (except the NewValue column) can be given in one of two ways: (1) A single value or a string to be evaluated and matched using the "%in%" operator, such as "HER" or "c(\"HER\", \"CLU\")"; or (2) a string expressing a function of the variable given by the column name, such as "function(IndividualTotalLength) IndividualTotalLength > 10". When the TranslationnTable is given in the StoX GUI the strings need not be escaped ((1) HER or c("HER", "CLU"); or (2) function(IndividualTotalLength) IndividualTotalLength > 10).

E.g., to set all individuals with missing IndividualMaturity as "Adult" if longer than 10 cm, use function(IndividualMaturity) is.na(IndividualMaturity) in the first column named "IndividualMaturity", Adult in the "NewValue" column, and function(IndividualTotalLength) IndividualTotalLength > 10 in the third (conditional) column named "IndividualTotalLength". To translate all IndividualMaturity to a e.g. NA, use function(IndividualMaturity) TRUE in the "IndividualMaturity" column and NA in the "NewValue" column.