Categories

Versions

You are viewing the RapidMiner Studio documentation for version 10.3 - Check here for latest version

Macros

What is a Macro?

A macro is a key–value pair that is only available during the process execution. Predefined macros contain context related information like the current iteration of a loop or the process name. Macros can be defined during runtime with the Set Macros, Generate Macros or Extract Macro operator, and used in nearly every operator parameter field. It is also possible to define static macros in the Context Panel (View➟Show Panel➟Context).

Debugging Macros

User defined macros can be watched with the Macros Panel (View➟Show Panel➟Macros). In this panel the current values of the macros are displayed. Use breakpoints before and after you set the macro to see the change.

List of predefined Macros

Process Macros

Macro Value Description
%{process_name} 02_LinearRegression current process name
%{process_file} 02_LinearRegression.rmp
02_LinearRegression
process file name (opened as file)
process name (opened from repository)
%{process_path} C:\02_LinearRegression.rmp
//Repo/02_LinearRegression
file path (opened as file)
repository path (opened from repository)
%{process_start} 2017_12_24-PM_00_01_25 process start date and time
%{t} 2017_12_24-PM_00_01_30 current date and time

For higher accuracy requirements use the date_now() function instead of %{t}.

Operator Macros

Macro Value Description
%{execution_count}
%{a}
1 number of times the current operator is executed
%{b} 2 execution_count + 1
%{operator_name}
%{n}
Generate Data (user given) name of the current operator
%{c} com.rapidminer.GenerateData package and class of the current operator

Operators like Loop, or Handle Exception provide additional macros.

Macros and functions

Parsing Numbers

We've seen before that %{b} returns execution_count + 1, but what if we need execution_count - 1?
This can be achieved with the function expression parse(%{execution_count})-1 for the Generate Macro operator.

Parsing Dates

To parse a date macro into a date we can use date_parse_custom(%{process_start},"yyyy_MM_dd-a_KK_mm_ss"). A table of all pattern letters can be found under SimpleDateFormat.

Evaluating Macros

It is possible to store an expression as an nominal value with the Set Macros operator and execute it afterwards with the eval(%{macro}) function. Please be aware that the evalfunction, like all other functions, is only available for selected operators. To use the evaluated macro value in every field, use the Generate Macro operator beforehand and store the result of the evaluation in a new macro.