RTIME( ) function

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

Syntax

RTIME(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

Datetime.

Examples

Basic examples

Returns `t0545`:

RTIME("value1+2700",`t0500`)

Advanced examples

Using an external R script

Adds 45 minutes to a time field by passing a field and a literal value to an external R function:

RTIME("a<-source('c:\\scripts\\sample.r');a[[1]]", end_time, 2700)

External R script (sample.r):

add_time <- function(start, sec) {
    return(start + sec)
}
add_time(value1, value2)

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.

System time zone

Greenwich Mean Time (GMT) is the default current time zone in the R environment used by Analytics.