SQL command with PL/R function failing with "R interpreter parse error"
search cancel

SQL command with PL/R function failing with "R interpreter parse error"

book

Article ID: 294924

calendar_today

Updated On:

Products

Services Suite

Issue/Introduction

Symptoms:

A SQL query that includes an R function may fail with : "R interpreter parse error".

The master log will show: 

2016-06-02 11:30:06.226608 EDT,"212456758","master",p320737,th-1043842848,"3.39.77.9","54463",2016-06-02 10:49:07 EDT,46417013,con127349,cmd7,seg-1,,,x46417013,sx1,"ERROR","22000","R interpreter parse error  (seg139 segement1.domain:41003 pid=467112)","
 R parse error caught in ""PLR9437558 <- function(arg1,arg2) {
 library(data.table)
# library(lubridate)
library(dplyr)
temp1 <- arg2
temp1[temp1 == -9999] <- NA
temp2[temp2 == -9999] <- NA
temp1$frame_offset <- temp2
rm(temp2)
....

 

Environment


Cause

This error could be caused by one of two things:

  1. There are windows new line characters within the affected function 
  2. There are syntax errors within the function.

Resolution

1. Use "tr" to remove any windows characters that may be present in the function with a command similar to this:

tr -d '\15\32' < winfile.txt > unixfile.txt

 

2. Review the code for syntax errors, using pgadmin may help as it will highlight syntax errors in yellow in the code viewer. Some examples of syntax errors are:  
   a) A ")" missing at the end of this line: 
min_values <- apply(tempo1[,masada_vars], 2, min(x, var.test = TRUE)
  b) The "(" and "[" are never closed for this line of code:
test02_example <- apply(test1[,pe
3. Once the syntax errors are corrected, reload the function and re-run it.