MicroStrategy ONE

The R Integration Pack is no longer supported as of December 2024.

Preparing Scripts for MicroStrategy Deployment

After implementing R analytics in an R script that is ready to be deployed to MicroStrategy, you must define how MicroStrategy interacts with the script by capturing the its signature. The script's signature is a description of the number and nature of the inputs and outputs to the R script, along with any other information needed for MicroStrategy to execute the script properly.

The deployR utility is an R-based utility that analyzes an R script, captures its signature, and creates the metric expressions that execute the function within MicroStrategy. The following image shows the deployR utility.

The standard workflow for using the deployR utility to capture the signature of your R analytic and deploy it to MicroStrategy follows.

To prepare R scripts using the deployR utility

  1. From an R console, open the deployR utility using the following commands:

    Copy
    library(MicroStrategyR)
    deployR() 
  2. Click Open at the upper left to open your R script.

    After you open your R script, the deployR utility parses the script to identify all potential variables.

    • If this script contains the MicroStrategy header block at the top, then the header information is used to configure the utility. Any unidentified variables are displayed in the Unused Variables column.
    • If the script does not contain a MicroStrategy header block, the deployR utility attempts to determine whether a variable is an input or an output, based on the first occurrence of that variable in the script. If the variable's first occurrence assigns it a value, it is considered an output; otherwise, it is designated as an input.
    • For new variables, the default Data Type is Numeric and the default Parameter Type is Vector.
  3. Determine the path that is used for the R script using one of the following methods:
    • To include the selected R script's file name and path in the metric expression, clear the Use R Script Folder check box. When executed, the R script file name and path you specify will be used. If the R script is not found, execution will fail and an error will be logged, if possible.

      If you clear this check box, the same folder path must exist or be accessible on the machines where this R script is provided to support execution in MicroStrategy.

    • To include only the file name of the R script in the metric expression, select the Use R Script Folder check box. When executed, the R Script Folder is searched for the specified script. If the R script is not found, execution will fail and an error will be logged, if possible. The default location for the R Script Folder is RIntegrationPackInstallFolder\RScripts. This location is controlled by the HKLM\SOFTWARE\\MicroStrategy\R Integration Pack\RScriptsFolder registry key.
  4. Modify the definition of each variable as required to match the function's logic.
  5. Drag and drop variables to place them in the appropriate columns:
    • Unused Variables: Variables that appear in the R script but are not passed between MicroStrategy and R as either inputs, outputs, or parameters. The order of unused variables does not affect the R script execution.
    • Input: Data that is imported into R from MicroStrategy. The order of inputs, from top to bottom, determines the order of arguments passed in from MicroStrategy, from left to right.
    • Parameter: Data that is passed as one of the various function parameters available for passing scalar values from MicroStrategy to R. These function parameters include Boolean parameters, numbers, and strings. Parameters are typically used for values that are changed infrequently or values that are not determined from other metrics.

      Use the Parameter drop-down list to specify which parameter to use. Each parameter can only be used for one variable. The order of parameters does not affect the R script execution.

    • Output: Data that is returned from R to MicroStrategy. If there is more than one output, the first output is considered the default output. The order of any additional outputs does not affect the signature.
  6. Set Data Type to one of the following options:
    • Numeric: Indicates variables that contain numbers.
    • String: Indicates variables that contain text.
    • Default: Indicates that the data type defined by MicroStrategy should be used. This setting can be used for inputs only. It is useful for scripts that use categorical variables, such as Month. This type of categorical variable can be strings (such as Jan, Feb, Mar, and so on) or numbers.
  7. Set Parameter Type to one of the following options:
    • Vector: Indicates a variable that contains one or more values.
    • Scalar: Indicates a variable that contains only one value.
  8. If one or more of the input variables form a repeated argument, define a value for Repeat Count.

    This option identifies an input that can vary in quantity; such variables are known as repeated arguments because they represent a varying number of variables. The Repeat Count value specifies how many of the input variables can be repeated, counting backwards from the last variable. These variables always occur at the end of the list of arguments. These variables appear in the Inputs column with an asterisk (*). Examples include:

    • A predictive analytical function supports one target variable Y (the dependent variable) and an indeterminate number of explanatory variables X (independent variables). Establish this configuration by defining Y as the first variable, defining X as the second variable, and defining a Repeat Count value of 1. The deployR utility recognizes that Y is the first argument passed into the function, followed by one or more X variables.
    • A predictive analytical function supports one target variable Y (the dependent variable) and an indeterminate number of explanatory, independent variable pairs, X1 and X2. X1 is a numeric identifier for an item and X2 is its text description. By defining Y as the first input, X1 as the second, X2 as the third, and a Repeat Count value of 2, the deployR utility recognizes that Y is the first argument and there can be one or more pairs of X1 and X2 variables passed into the R script.

      While defining a Repeat Count allows for additional metrics to be included as inputs passed back to R, the number of inputs provided in the metric expression generated by deployR is not affected by the value specified for Repeat Count. Additional metrics can be included in the metric expression when including the R script in a metric.

  9. Define the metric that utilizes the R script using the Metric Specification section, which contains the following options:
    • Nulls Allowed: Controls whether records containing null values are to be passed in as inputs to your analytic.

      By default this option is selected and null values are included in the analysis.

    • Check Input Count: Controls whether MicroStrategy ensures that the number of inputs to the metric matches exactly with the number of inputs specified in the function's signature.

      By default, the option is selected. If it is selected and the number of inputs is different, a warning message is returned when using the R script in MicroStrategy. When cleared and the number of inputs is different, the script execution will attempt to proceed.

    • Enable Sort By: Controls the sorting of records before the data is passed to R

      By default, the option is selected. If this option is selected, the first input must be a vector, since the default behavior sorts records in ascending order by the first input. To specify a particular sorting criterion, you can type the sort by value in the field below the check box.

      When cleared, the order of records passed into R is determined by MicroStrategy automatically.

    • Specify Working Directory: Allows you to specify a working directory for your R scripts used in MicroStrategy, without affecting your R configuration:

      By default, this option is cleared and the path provided for each R script is used.

      To specify a working directory for MicroStrategy to search for R scripts, select the check box and specify a working directory in the field below the check box. MicroStrategy does not alter R's working directory, which is otherwise determined by R.

    • Output Variable: Allows the user to control which variable is returned to MicroStrategy. The first output of an R script is selected by default. This output variable is not included in the metric expression.
  10. Click Preview.
  11. After you have configured the variables and specified the metric options, click Save.

    After saving the signature to your R script, the deployR utility provides the metric expression for your analytic. The Metric Expression pane at the bottom right of the dialog box shows the metric expression that defines how MicroStrategy interacts with your function.

  12. Click Copy to Clipboard, and then paste this metric expression into any MicroStrategy metric editor, including the metric editors available for MicroStrategy Developer, MicroStrategy Web, MicroStrategy Desktop, and MicroStrategy Visual Insight.
  13. Map each of the inputs of the expression, which are included between parentheses, to MicroStrategy metrics that provide the data for statistical analysis. An example of this modification is here.