Is there any way to run a Java jar file in R? I want one of the outputs of a .jar be used in R.
You can use system
to run an operating system command from R.
To run a java jar on a well-configured system, this should work:
system("java -jar /path/to/my.jar")
You can add other parameters, for example maybe the Java code takes input from a file which you write with R and pass the filename. Then output from the Java code could be written to files and then read from R. Without knowing what the Java code does we can't be more specific.
It is possible to directly interface with Java code but that requires full knowledge of the internals of the jar so you know what functions to call with what parameters. This is usually referred to as the "API" for that Java.
Otherwise, write a file, call system
, read a file, is sometimes the simplest way to run code in other languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With