I'm running into a very curious problem. I've an R code which doesn't contain any print statement (except my explicit calls to log the time taken) and yet the entire json gets dumped on to the "R console". This is causing a serious performance issue with our module and I need your help to track down the problem.
Here is just a part of the R file (due to company policies, I cannot post the entire source code and I apologize for not giving much info)
#run time/online time series models
LAST_TIME_ID <- DATA[nrow(DATA),id];
LAST_TIME_ID <- strptime(LAST_TIME_ID,format="%d-%m-%Y %H:%M");
#timestamp tag computation using frequency
FREQUENCY_VEC <- rep(TIMESTAMP_FREQUENCY*60,PREDICTION_NUMBER);
FREQUENCY_VEC <- cumsum(FREQUENCY_VEC);
TIMESTAMP_TAGS <- LAST_TIME_ID + FREQUENCY_VEC;
TIMESTAMP_TAGS <- format(strptime(TIMESTAMP_TAGS,format="%Y-%m-%d %H:%M"),format="%d-%m-%Y %H:%M");
#prepare the prediction points data per tag into table format
PREDICTION_DATA <- NULL;
startTime <- Sys.time();
for (tag_index in 1:length(MODEL[,tag_id])) {
TEMP <- data.table(id=as.character(TIMESTAMP_TAGS),tag_id = MODEL[tag_index,tag_id], prediction = as.vector(MODEL[,Forecast][[tag_index]]));
PREDICTION_DATA <- data.table(rbind(PREDICTION_DATA,TEMP));
rm(TEMP);
};
endTime <- Sys.time();
print(paste("seconds consumed (prediction points data per tag into TEMP): ",(endTime-startTime)/1000));
#OUTPUT <- dcast(PREDICTION_DATA,id~tag_id); #into output
OUTPUT <- PREDICTION_DATA;
#compute final output in json format
js_object <- toJSON(OUTPUT,asIs = TRUE);
js_object;
I can assure you the rest of code looks the same (i.e. no prints). I'm running my R code through Java (1.8) using RServe (REngine.jar) on Windows 8.
Any ideas/clues would be greatly appreciated.
The last line of your choice snippet where you just execute: js_object;
prints the variable to the console.
Remove such type of statements where nothing assigned to a variable.