Arguments from config¶
Sometimes it is necessary to make function calls dynamic. To achieve this, you may use the following functions to look up function arguments in a config table.
This is useful for situations where you want to reuse a variable library, while automatically altering its configuration based on where it is used in the company hierarchy.
getFormulaFromConfig
¶
Get a formula from a config table and inject it into the current formula.
getFormulaFromConfig(
TableName,
RowLookup="dynamicRowLookup",
ColumnLookup=varName,
errIgnore=FALSE,
valueOnError=0
)
Arguments¶
TableName
- Name of the config table range. If this is a direct reference, it has to be in quotation marks (e.g.
"t_Inputs"
). RowLookup
- Lookup string to determine the appropriate row index. Defaults to
"dynamicRowLookup"
, which means that the string in the first cell of the table will be used to construct the lookup based on the properties of the projection node. ColumnLookup
- Lookup string to determine the appropriate column index. Defaults to the name of the variable that uses this function.
errIgnore
- Whether to ignore a missing column or row lookup. If
FALSE
, a runtime error will be raised for the missing lookup. The default is to raise an error for missing lookups. valueOnError
- The value to return if the column is missing.
Examples¶
To get the value of the Formula
column of the t_Formulae
table:
getFormulaFromConfig("t_Formulae",,"Formula")
The result can be used inside other formulas:
10 * getFormulaFromConfig("t_Formulae",,"Formula") + 1
You can also use it multiple times in the same formula:
csvToTable(
getFormulaFromConfig("t_PROPHET_TEXT_OUTPUT",,"Path"),
getFormulaFromConfig("t_PROPHET_TEXT_OUTPUT",,"Query"),
…
)
These formulas can get very long and unwieldy. They can be shortened by using runFromConfig
and conf
.
isConfigEmpty
¶
Check whether a config entry cell is empty.
isConfigEmpty(
TableName,
RowLookup="dynamicRowLookup",
ColumnLookup=varName
)
This is similar to getFormulaFromConfig
, but instead of returning the contents of the cell,
it returns TRUE
or FALSE
depending on whether that cell contains anything.
runFromConfig
¶
Run any function, using arguments that were looked up in config tables.
Note that runFromConfig
and conf
should always be used together.
runFromConfig(
TableName,
RowLookup="dynamicRowLookup",
FunctionNameToRun,
Arg1,
Arg2,
Arg3,
...
)
Arguments¶
TableName
- Name of the config table range. If this is a direct reference, it has to be in quotation marks (e.g.
"t_Inputs"
). RowLookup
- Lookup string to determine the appropriate row index. Defaults to
"dynamicRowLookup"
, which means that the string in the first cell of the table will be used to construct the lookup based on the properties of the projection node. FunctionNameToRun
- The function to run with the looked-up arguments.
Arg1
,Arg2
,Arg3
, ...- The arguments to pass to
FunctionNameToRun
.
Examples¶
To look up arguments from the config table inside runFromConfig
, you may use the short conf
function
instead of the longer getFormulaFromConfig
function.
runFromConfig(
"t_Table",
"dynamicRowLookup",
"csvToTable",
conf("Column1", ...),
conf("Column2", ...),
...
)
This resolves to:
csvToTable(
getFormulaFromConfig("t_Table", "dynamicRowLookup", "Column1", ...),
getFormulaFromConfig("t_Table", "dynamicRowLookup", "Column2", ...),
...
)
conf
¶
conf
is a shorthand version of getFormulaFromConfig
, but can only be used within
the *FromConfig
family of functions.
conf(
column=varName,
errIgnore=FALSE,
valueOnError=0
)
Arguments¶
The arguments are the same as for getFormulaFromConfig
, except that TableName
and RowLookup
are inherited from the surrounding runFromConfig
call.
Examples¶
See runFromConfig
.