rjavajri

Using JRI to simulate R console


I need to build an application with JRI that works similarly to the R console. The issue is that sometimes the console will respond displaying a line (for example, after entering x below) and sometimes it doesn't (for example, after entering x = 1)

enter image description here

I tried to analyze eng.parseAndEval(statement) (where statement is the command entered on the console) but cannot tell when to display the response on the console, and when not. Any ideas?


Solution

  • What you are seeing is the visibility flag maintained by R which tells the regular event loop when to print and when not. See withVisible in R for details. However, you really don't want to get into re-implementing the R event loop. Instead, JRI allows you to have R do all the work for you - you just implement the console callbacks RMainLoopCallbacks to handle all your console I/O and then start the event loop. You may want to have a look at JGR - it is a Java console implemented using JRI.