From: Thomas K. <tho...@we...> - 2006-06-07 14:13:32
|
> -----Urspr=FCngliche Nachricht----- > Von: raj...@pr... [mailto:raj...@pr...] > Gesendet: Mittwoch, 7. Juni 2006 15:15 > An: Thomas Kuhn > Cc: 'Thomas Kuhn'; cdk...@li... > Betreff: rJava and CDK >=20 > On Wed, 2006-06-07 at 13:48 +0200, Thomas Kuhn wrote: >=20 > > In the in the rModel.java class you use a .call method the execute R > methods > > like: > > revaluator.call("saveModel", new Object[] { (Object)modelname, > > (Object)filename }); > > But I can't find a similar method within the rJava project. >=20 > The saveModel method is actually a function I have written. In fact = the > R-CDK interface has a number of functions I wrote that allow me to > transfer complex R objects back to the Java side. In addition these > functions, allow me to perform error checking or various = pre-processing > transforms on the data sent to an R method. >=20 > If you look under src/org/openscience/cdk/qsar/model/data you'll find = a > number of R scripts. Some of them represent wrappers for specific > modeling routines (lm, cnn, pls etc) and init_1.R provides some = utility > methods (such as saveModel, loadModel) etc. I saw these scripts.=20 >=20 > A lot of the R code is necessary because of the nature of the R-Java > bridge, so it might not be applicable to the rJava package. >=20 > See the CDK News article for a more detailed description of what goes = on > under the hood. >=20 > [ From what I have understood if you wanted to use R from within a CDK > app, you need to use JRI (whereas rJava is for accessing Java from an = R > session) ] =20 That's right. I have forgotten to mention this.=20 > Also if I understand correctly, the JRI API provides methods to call > methods in an R session via the REngine class and classes for various > types of R primitive objects (string, integer, numeric, factor, list). >=20 > This would mean that for example if you are building a OLS model with > lm() there is no easy way to get back an 'lm' object as a Java object. > As far as I can see, you have to call lm() via REngine, and whenever = you > need something from the 'lm' object (such as say fitted(), > coefficients() etc) you must make a call to the R session. This is > certainly doable, but you need to have some mechanism of keeping track > of objects in the R session. >=20 > > > > I understand I can only assign values to a symbol in R. Which I = thought > > would not be the big problem, I could assign the symbol first and = than > > execute the R method with this R symbol and the .eval method of the > rJava > > rengine. >=20 > Correct. >=20 > > But the problem is that I can only assign double[], int[], REXP, > > and strings. Do I misunderstand this? >=20 > For the case of 'building' models this is not necessarily a problem. = In > general all model building routines require matrix, data.frame, = vector, > or string arguments. >=20 > Now, since you can only assign vectors, this means that on the R side > you're going to have reshape the input vector to an appropriately > dimensioned matrix (or data.frame if required). >=20 > This implies you need to have wrapper methods on the R side. So = instead > of calling lm() you'd call a routine that you wrote called = lm.wrapper() > which would take a X vector rather than a X matrix, and would then > reshape the X vector to a matrix and call lm(). >=20 > Now, your wrapper function would then have to assign the returned 'lm' > object to the global environment (otherwise it would be lost after the > wrapper method returns and you could not then query the result of = lm()) > and essentially return the name of the 'lm' object to the Java caller. >=20 > All this assumes that rJava does not allow one to make a R matrix = object > on the Java side. As far as I understand this is his assumption correct.=20 > Of course an alternative approach without writing wrapper functions is > to essentially perform the preprocessing using a sequence of eval(...) > calls - which might be a better option a it would keep the code in one > place, does not require fiddling with environments on the R side. But > it's a pain to type :) =20 It would really be a pain of type but I think it would be easier to = maintain or? =20 > However as I noted above, there appears to be no way to get back = complex > R objects, so you must perform eval(...) calls each time you want to > query some aspect of an R object (which is certainly a performance = hit) So what do you think should we do? Should we try to get a SJava version running and try to get a reliable installation routine or tutorial for = this or should we switch to rJava which is easy to install but is still in an early development status? |