RLOGICAL( ) function

Returns a logical value calculated by an R function or script. Data processing in R is external to Analytics.

Syntax

RLOGICAL(rScript|rCode <,field|value <,...n>>)

Parameters

Name Type Description
rScript | rCode

character

The full or relative path to the R script, or a snippet of R code to run.

If you enter R code directly rather than use an external file, you cannot use the enclosing quotation character in your code, even if you escape it:

  • valid 'var <- "\"test\"" '
  • invalid 'var <- "\'test\'" '
field | value <,...n>

optional

character

numeric

datetime

logical

The list of fields, expressions, or literal values to use as arguments for the R script or code snippet.

The values are passed into the function you call in the order you specify them, and you reference them using value1, value2 ... valueN in the R code.

You may include as many arguments as necessary to satisfy the function definition in the R code.

Note

Use the ALLTRIM() function to remove any leading or trailing spaces from character input: ALLTRIM(str). For more information, see ALLTRIM( ) function.

Output

Logical.

Examples

Basic examples

Returns T:

RLOGICAL("(value1>0.6) & (value2>0.7) & (value3>0.5)", 0.8, 0.9, 0.55)

Advanced examples

Using an external R script

Accepts an amount, and an upper and lower threshold value. The function returns a truth value based on a series of logical comparisons:

RLOGICAL("a<-'c:\\scripts\\sample.r');a[[1]]", expense_amt, threshold_low, threshold_hi)

External R script (sample.r):

test_truth <- function(amt, low, hi) {
    return(((amt > low) & (amt < hi)) | ((amt==low) | (amt==hi)))							
}
test_truth(value1, value2, value3)

Using R code stored in a variable

Performs a logical test of three fields using AND logic:

v_rcode = "(value1>0.6) & (value2>0.7) & (value3>0.5)"
RLOGICAL(v_rcode, PACKED, MICRO_LONG, ACCPAC)

Remarks

Returning data from R

When calling R scripts, use the source function and assign the return object to a variable. You can then access the value returned from your R function from the return object:

# 'a' holds the response object and a[[1]] access the data value
"a<-source('c:\\scripts\\r_scripts\\sample.r');a[[1]]"

R log file

Analytics logs R language messages to an aclrlang.log file in the project folder. Use this log file for debugging R errors.

Tip

The log file is available in the Results folder of Analytics Exchange analytic jobs.

Running external R scripts on AX Server

If you are writing an analysis app to run on AX Server and you want to work with external R scripts:

  1. Upload the file as a related file with the analysis app.
  2. Use the FILE analytic tag to identify the file(s).
  3. Reference the file(s) using the relative path ./filename.r.

Note

Using a related file ensures that the TomEE application server account has sufficient permissions to access the file when running R with Analytics Exchange.

ACL Scripting Guide 14.1