Re: [R] Using Java methods in R

From: Shekhar <>
Date: Sat, 23 Apr 2011 10:35:13 -0700 (PDT)

Hi Hill,
I just finished interfacing the C++ with R, i.e. c++ functions from R and vice versa. Next thing in pipe line is Java and python. I just wanted to share some of the things which i think might be useful for you. Reason being whether its a C++, java or any other compiled language the interface has to be generic in R. That means mode of interfacing might be different(using different packages Rcpp for c++, rJava for Java) but the underlying mechanism remains the same.

For C++ you will be creating a dll ( windows) and .so( *nix) and for jave you will be using class.
Now for using c++/java functions with in R or vice versa, you first should check whether the functions are properly loaded in the R symbol table or not?

If you are unable to call the java functions in R, then probably you are unable to load the class into the R environment.

A few steps which i have followed in C++ ( i think must be more or less same conceptually) could be useful for you:

  1. I have a c++ file, i compile it using the command R CMD SHLIB filename.cpp. On successful completion it creates the library. if you are getting compilation error then you need to check whether the header files are in proper path or not.
  2. Then for using this function is first use to load the library using the function dyn.load("library path")
  3. If the loading is successful i check whether the required function is properly loaded into the R symbol table or not by using the function is.loaded("function name")
  4. if it returns true, then i call the function by using .C or .Call function provided by R. For more information you can see .

Hope it helps you in someway.

Som Shekhar mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 23 Apr 2011 - 20:41:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 23 Apr 2011 - 21:20:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive