Skip to content

calling r from java

9 messages · Eduard Drenth, Jeff Newmiller, Bert Gunter +1 more

#
Dear all,

As a java developer I prefer to develop rest services using jax-rs.

Now I developed a service that executes Rscript (Using ProcessBuilder),
sends text to stdin of the process and reads from stdout of the
process.

Works fine, but this is inefficient, because every call reloads all
that is needed.

I have looked into this:

https://github.com/microsoft/java-client-library
https://rforge.net/Rserve/
several other sources on stackoverflow etc.

A lot of these sources seem old or not maintained.

Now my question: Is there a preferred and maintained way to efficiently
call R from Java? Preferrably available in maven central?

Regards, Eduard
#
Well ... google is your friend.
"calling R from Java"
brought up what looked to me like useful resources, including this:
https://www.cnblogs.com/mavlarn/archive/2012/12/24/2831688.html

Have you done this already?

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Nov 27, 2020 at 4:01 PM Eduard Drenth <edrenth at fryske-akademy.nl>
wrote:

  
  
#
Not being a Java programmer I was going to sit this one out, but when Bert points at an 8-year old blog that OP was already saying was too old I figure even I can Google better than that.

https://github.com/oracle/fastr

which has activity within the last 3 days, though I really don't know anything about it beyond that.

FWIW I can't recall ever seeing mention of calling R from Java on this list before, so don't get your hopes up. Of course, that subject would in general be off topic so that isn't saying much.
On November 27, 2020 4:55:39 PM PST, Bert Gunter <bgunter.4567 at gmail.com> wrote:

  
    
#
Heh heh. Criticism accepted. However...

1. Web searching first is still a good idea.
2. Old in not **necessarily** useless -- I fervently hope(calculus has been
around since, umm...).

This also **might** be useful to the OP:
https://cran.r-project.org/web/views/WebTechnologies.html

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Nov 27, 2020 at 5:14 PM Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
wrote:

  
  
#
Hi Eduard,
This doesn't answer your question, but may be relevant.
I have a java-based application that works on a similar principle.
(The code is horrendously bad and most of it should be thrown away).

I'm planning to write a terminal emulator, in the near future.
(Currently, second place on my top-level todo list).

The primary objective is to build object-oriented and message passing
APIs on top of the core terminal emulation system, with at least some
cross platform functionality.
Noting that, in my opinion, the cross-platform aspect is more
important for R, than in many other IPC topics.

Hence, I'm interested in hearing "wishlist" items for such APIs.
#
Thanks all, I'll go for https://www.rforge.net/JRI/ and the libraries
in maven https://search.maven.org/search?q=jri

The maven library is build from  here 
https://www.rforge.net/rJava/files/ back in 2017.

After this no new libs are published to maven.

It would be nice (understatement) if publishing new rJava components to
maven becomes a regular part of R deveopment processes.

This would promote R use from Java which I think is good.

And of course I can help.

Bye, Eduard

-----Original Message-----
From: Abby Spurdle <spurdle.a at gmail.com>
To: Eduard Drenth <edrenth at fryske-akademy.nl>
Cc: r-help at r-project.org <r-help at r-project.org>
Subject: Re: [R] calling r from java
Date: Sat, 28 Nov 2020 15:55:36 +1300

Hi Eduard,
This doesn't answer your question, but may be relevant.I have a java-
based application that works on a similar principle.(The code is
horrendously bad and most of it should be thrown away).
I'm planning to write a terminal emulator, in the near
future.(Currently, second place on my top-level todo list).
The primary objective is to build object-oriented and message
passingAPIs on top of the core terminal emulation system, with at least
somecross platform functionality.Noting that, in my opinion, the cross-
platform aspect is moreimportant for R, than in many other IPC topics.
Hence, I'm interested in hearing "wishlist" items for such APIs.
#
Found this https://github.com/s-u/rJava as the place for rJava
development and issues

-----Original Message-----
From: Eduard Drenth <edrenth at fryske-akademy.nl>
To: spurdle.a at gmail.com <spurdle.a at gmail.com>
Cc: r-help at r-project.org <r-help at r-project.org>
Subject: Re: [R] calling r from java
Date: Sat, 28 Nov 2020 11:57:49 +0000

Thanks all, I'll go for https://www.rforge.net/JRI/ and the librariesin
maven https://search.maven.org/search?q=jri

The maven library is build from  here 
https://www.rforge.net/rJava/files/ back in 2017.
After this no new libs are published to maven.
It would be nice (understatement) if publishing new rJava components
tomaven becomes a regular part of R deveopment processes.
This would promote R use from Java which I think is good.
And of course I can help.
Bye, Eduard
-----Original Message-----From: Abby Spurdle <spurdle.a at gmail.com>To:
Eduard Drenth <edrenth at fryske-akademy.nl>Cc: r-help at r-project.org <
r-help at r-project.org>Subject: Re: [R] calling r from javaDate: Sat, 28
Nov 2020 15:55:36 +1300
Hi Eduard,
This doesn't answer your question, but may be relevant.I have a java-
based application that works on a similar principle.(The code
ishorrendously bad and most of it should be thrown away).I'm planning
to write a terminal emulator, in the nearfuture.(Currently, second
place on my top-level todo list).The primary objective is to build
object-oriented and messagepassingAPIs on top of the core terminal
emulation system, with at leastsomecross platform functionality.Noting
that, in my opinion, the cross-platform aspect is moreimportant for R,
than in many other IPC topics.Hence, I'm interested in hearing
"wishlist" items for such
APIs.______________________________________________R-help at r-project.org 
mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
1 day later
#
First attempts to use jri on ubuntu 20.04 stranded.

Steps I followed:

1) download rJava from https://www.rforge.net/rJava/files/
2) create a symlink /usr/lib/libjvm.so to /usr/lib/jvm/java-8-openjdk-
amd64/jre/lib/amd64/server/libjvm.so
3) configure and make jri
4) create a symlink /usr/lib/libjri.so
5) put the built JRI.jar in local maven repo
6) include a dependency to the jar
7) create and run a hello world test for Rengine

The test fails because com.misc.Unsafe.prefetchRead isn't found. As I
understand depending on com.misc.Unsafe.* is a risk.

I will not follow this route any further for now, though I still think
having jri available would be great. Steps to get there are I think:

1) remove com.misc.Unsafe usage from the solution
2) make libjri available in repositories (apt, yum, other)
3) make JRI.jar available in maven central

Bye, Eduard

-----Original Message-----
From: Eduard Drenth <edrenth at fryske-akademy.nl>
To: spurdle.a at gmail.com <spurdle.a at gmail.com>
Cc: r-help at r-project.org <r-help at r-project.org>
Subject: Re: [R] calling r from java
Date: Sat, 28 Nov 2020 11:57:49 +0000

Thanks all, I'll go for https://www.rforge.net/JRI/ and the librariesin
maven https://search.maven.org/search?q=jri

The maven library is build from  here 
https://www.rforge.net/rJava/files/ back in 2017.
After this no new libs are published to maven.
It would be nice (understatement) if publishing new rJava components
tomaven becomes a regular part of R deveopment processes.
This would promote R use from Java which I think is good.
And of course I can help.
Bye, Eduard
-----Original Message-----From: Abby Spurdle <spurdle.a at gmail.com>To:
Eduard Drenth <edrenth at fryske-akademy.nl>Cc: r-help at r-project.org <
r-help at r-project.org>Subject: Re: [R] calling r from javaDate: Sat, 28
Nov 2020 15:55:36 +1300
Hi Eduard,
This doesn't answer your question, but may be relevant.I have a java-
based application that works on a similar principle.(The code
ishorrendously bad and most of it should be thrown away).I'm planning
to write a terminal emulator, in the nearfuture.(Currently, second
place on my top-level todo list).The primary objective is to build
object-oriented and messagepassingAPIs on top of the core terminal
emulation system, with at leastsomecross platform functionality.Noting
that, in my opinion, the cross-platform aspect is moreimportant for R,
than in many other IPC topics.Hence, I'm interested in hearing
"wishlist" items for such
APIs.______________________________________________R-help at r-project.org 
mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
#
sun.misc that is

-----Original Message-----
From: Eduard Drenth <edrenth at fryske-akademy.nl>
To: r-help at r-project.org <r-help at r-project.org>
Subject: Re: [R] calling r from java
Date: Mon, 30 Nov 2020 07:18:46 +0000

First attempts to use jri on ubuntu 20.04 stranded.
Steps I followed:
1) download rJava from https://www.rforge.net/rJava/files/
2) create a symlink /usr/lib/libjvm.so to /usr/lib/jvm/java-8-openjdk-
amd64/jre/lib/amd64/server/libjvm.so3) configure and make jri4) create
a symlink /usr/lib/libjri.so5) put the built JRI.jar in local maven
repo6) include a dependency to the jar7) create and run a hello world
test for Rengine
The test fails because com.misc.Unsafe.prefetchRead isn't found. As
Iunderstand depending on com.misc.Unsafe.* is a risk.
I will not follow this route any further for now, though I still
thinkhaving jri available would be great. Steps to get there are I
think:
1) remove com.misc.Unsafe usage from the solution2) make libjri
available in repositories (apt, yum, other)3) make JRI.jar available in
maven central
Bye, Eduard
-----Original Message-----From: Eduard Drenth <
edrenth at fryske-akademy.nl>To: spurdle.a at gmail.com <spurdle.a at gmail.com>
Cc: r-help at r-project.org <r-help at r-project.org>Subject: Re: [R] calling
r from javaDate: Sat, 28 Nov 2020 11:57:49 +0000
Thanks all, I'll go for https://www.rforge.net/JRI/ and the
librariesinmaven https://search.maven.org/search?q=jri

The maven library is build from  here 
https://www.rforge.net/rJava/files/ back in 2017.After this no new libs
are published to maven.It would be nice (understatement) if publishing
new rJava componentstomaven becomes a regular part of R deveopment
processes.This would promote R use from Java which I think is good.And
of course I can help.Bye, Eduard-----Original Message-----From: Abby
Spurdle <spurdle.a at gmail.com>To:Eduard Drenth <edrenth at fryske-
akademy.nl>Cc: r-help at r-project.org <r-help at r-project.org>Subject: Re:
[R] calling r from javaDate: Sat, 28Nov 2020 15:55:36 +1300Hi Eduard,
This doesn't answer your question, but may be relevant.I have a java-
based application that works on a similar principle.(The
codeishorrendously bad and most of it should be thrown away).I'm
planningto write a terminal emulator, in the nearfuture.(Currently,
secondplace on my top-level todo list).The primary objective is to
buildobject-oriented and messagepassingAPIs on top of the core
terminalemulation system, with at leastsomecross platform
functionality.Notingthat, in my opinion, the cross-platform aspect is
moreimportant for R,than in many other IPC topics.Hence, I'm interested
in hearing"wishlist" items for
suchAPIs.______________________________________________R-help at r-
project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible
code.______________________________________________R-help at r-project.org 
mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.