Re: [R] Using Java methods in R
H do I obtain a strictly rectangular type-double array (converted to an R 2-dimensional array) from a Java class? I can obtain a 1-dimensional type-double array (vector) or a scalar, but I cannot figure out the two-dimensional from the instructions. Is .jevalArray also involved? My simple Java test class and R test code follows: import java.lang.reflect.Array; public class RJavTest { public static void main(String[]args) { RJavTest rJavTest=new RJavTest(); } public final static String conStg=testString; public final static double con0dbl=10001; public final static double[]con1Arr=new double[] { 10001,10002,10003,10004,10005,10006 }; public final static double[][]con2Arr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; public final static String retConStg() { return(conStg); } public final static double retCon0dbl() { return(con0dbl); } public final static double[] retCon1Arr() { return(con1Arr); } public final static double[][] retCon2Arr() { return(con2Arr); } } library(rJava) .jinit() .jaddClassPath(C:/ad/j) print(.jclassPath()) rJavaTst - .jnew(RJavTest) conn1Arr - .jfield(rJavaTst,sig=[D,con1Arr) print(conn1Arr) print(conn1Arr[2]) conn1ArrRet - .jcall(rJavaTst,returnSig=[D,retCon1Arr) print(conn1ArrRet) print(conn1ArrRet[2]) conn0dbl - .jfield(rJavaTst,sig=D,con0dbl) print(conn0dbl) ##The above works, but not the following conn2Arr - .jfield(rJavaTst,sig=[[D,con2Arr) print(conn2Arr[2]) print(conn2Arr[2,3]) print(conn2Arr) arj34Ret - .jcall(rJavaTst,returnSig=[[D,arReturnTEST) print(arj34Ret) The latter 2-dim stuff doesn't work -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3483862.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
-- snip -- It clogs up my email, takes a long time to delete, and is hard to be selective enough to not delete some of my other important email. -- snip -- If you don't care about contributing to the R listserve community, it's hard to imagine why that community should care about you. Some people (not me) seem to use nabble [ http://www.nabble.com/ ] to monitor the list. See R under what is cool . Another option is to set up rules in your email client to direct your mail to an appropriate folders or if you use gmail I guess we would say to label you R listserve email. You can search mail archives for a topic of interest with the R command line command RSiteSearch(). To learn more type ?RSiteSearch For fun I put rJava rectangular arrays into this search engine (having no idea what that means) and one of the things that came out was: http://finzi.psych.upenn.edu/R/library/rJava/html/jrectRef-class.html Hopefully, this or one of the other things can be useful to you. Finally for the third time, try joining/looking at: stats-rosuda-devel: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel or the archive: http://mailman.rz.uni-augsburg.de/pipermail/stats-rosuda-devel/ -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences 800 W. Jefferson St. Kirksville, MO 63501 660-626-2322 FAX 660-626-2965 __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
I guess your failure of getting two dimensional array may be related to this : http://www.rforge.net/rJava/news.html 0.9-0 (under development) o fixes issues introduced by several new features in the late 0.8 series. Most imporantly .jarray() and .jevalArray() behave as intended (and as implemented in previous versions). The same applies to .jcall() behavior with respect to arrays and its evalArray arument. The defaults for some new arguments have been changed to reflect the original behavior. o .jevalArray() has an additional argument `simplify' which allows multi-dimensional arrays to be converted to native R types. Use with care - it may convert more recursive types in the future so it should be used preferrably where you have control over the types converted. o fixed a bug in .jevalArray that was not simplifying string vectors correctly when the array type was not specified (.jclass returns dot notation whereas signatures use JNI notation so a conversion was necessary) So for multi-dimensional array, the.jevalArrayfunction has not been fully implemented in rJava release. As for the static double field con0dbl, it's pretty weild since it works well when I tested your code. One more notice, ar34Ret[2][3] should be ar34Ret[2,3] in R. At 2011-04-27 04:01:00£¬hill0093 hill0...@umn.edu wrote: Thanks Icn for pointing that out, but I don't understand it. My use of .jcall to return a type double scalar or String worked. My use of .jfield to get a one dimensional static array worked. My use of .jfield to get a static scalar constant did not work. My use of .jfield to get a two dimensional static constant array did not work. I don't understand the remainder of my rjava trial. The C:/ad/j/CalqsLin java code is: public final static double con0dbl=10001; public final static double[]con1Arr=new double[] { 10001,10002,10003,10004,10005,10006 }; public final static double[][]con2Arr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } I have the RGui with R Console on the screen; here is the trial: On the top pullDowns: Packages Install Packages USA(IA) rJava library(rJava) .jinit() [1] 0 .jaddClassPath(C:/ad/j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) calStg - 20110424235959 print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 calStg - .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4)) print(calStg) [1] 20110424235959 conn1Arr - .jfield(qsLin,sig=[D,con1Arr) print(conn1Arr) [1] 10001 10002 10003 10004 10005 10006 conn0dbl - .jfield(qsLin,sig=D,con0dbl) Error in .jfield(qsLin, sig = D, con0dbl) : RgetField: field con0dbl not found arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) print(arj34Ret[2][3],digits=15) [[1]] NULL print(arj34Ret,digits=15) [[1]] [1] Java-Array-Object[D:[D@1d58aae [[2]] [1] Java-Array-Object[D:[D@83cc67 [[3]] [1] Java-Array-Object[D:[D@e09713 ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). print(ar34Ret[2][3],digits=15) Error in print(ar34Ret[2][3], digits = 15) : object 'ar34Ret' not found print(ar34Ret,digits=20) Error in print(ar34Ret, digits = 20) : object 'ar34Ret' not found -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3476371.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Thanks Icn for the lookup. I appreciate your skill. The static double field con0dbl started working for me too. I was surprised, and checked my code carefully. I think they corrected that in rJava. I download and install rJava each time I use R. Hill -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3477817.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
I don't know who to contact in the management of this R-forum, and there are a few things I cannot figure out. As I understand it, to participate and learn on the R-forum, I must receive all the emails even concerning topics I have no interest in currently. It clogs up my email, takes a long time to delete, and is hard to be selective enough to not delete some of my other important email. It is nice to receive email on my posts and possibly even those others that I have responded to. Do I understand this correctly? Another item is that rJava has existed and has been promoted for a long time, and yet it doesn't seem to work for even some simple things like getting exactly-rectangular arrays from Java classes. Of course it could be that I just don't know how to use it, but people on the forum don't seem to know either. Maybe the people that know don't use the forum because of all the email. Or maybe there are not enough people that are writing rJava. And I am not talented enough to do so. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3478843.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Absence of evidence is not evidence of absence. Perhaps you are not getting answers for a good reason. From a previous email: 1) reading the source code of packages that use rJava, such as RWeka is the best way to understand how things work. If you are asked to do so is for a reason; explicitly refusing to doing so can be interpreted by the community as lack of effort on your side and reduce your chances of a reply. 2) there is a separate mailing list for rJava (stats-rosuda-devel) On Apr 27, 2011, at 13:32, hill0093 hill0...@umn.edu wrote: I don't know who to contact in the management of this R-forum, and there are a few things I cannot figure out. As I understand it, to participate and learn on the R-forum, I must receive all the emails even concerning topics I have no interest in currently. It clogs up my email, takes a long time to delete, and is hard to be selective enough to not delete some of my other important email. It is nice to receive email on my posts and possibly even those others that I have responded to. Do I understand this correctly? Another item is that rJava has existed and has been promoted for a long time, and yet it doesn't seem to work for even some simple things like getting exactly-rectangular arrays from Java classes. Of course it could be that I just don't know how to use it, but people on the forum don't seem to know either. Maybe the people that know don't use the forum because of all the email. Or maybe there are not enough people that are writing rJava. And I am not talented enough to do so. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3478843.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Thanks for your two suggestions. I am too much of a beginner in R and R-forum to be able to do either of them. How do I/ Sorry. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3479255.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Thanks Icn for pointing that out, but I don't understand it. My use of .jcall to return a type double scalar or String worked. My use of .jfield to get a one dimensional static array worked. My use of .jfield to get a static scalar constant did not work. My use of .jfield to get a two dimensional static constant array did not work. I don't understand the remainder of my rjava trial. The C:/ad/j/CalqsLin java code is: public final static double con0dbl=10001; public final static double[]con1Arr=new double[] { 10001,10002,10003,10004,10005,10006 }; public final static double[][]con2Arr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } I have the RGui with R Console on the screen; here is the trial: On the top pullDowns: Packages Install Packages USA(IA) rJava library(rJava) .jinit() [1] 0 .jaddClassPath(C:/ad/j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) calStg - 20110424235959 print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 calStg - .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4)) print(calStg) [1] 20110424235959 conn1Arr - .jfield(qsLin,sig=[D,con1Arr) print(conn1Arr) [1] 10001 10002 10003 10004 10005 10006 conn0dbl - .jfield(qsLin,sig=D,con0dbl) Error in .jfield(qsLin, sig = D, con0dbl) : RgetField: field con0dbl not found arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) print(arj34Ret[2][3],digits=15) [[1]] NULL print(arj34Ret,digits=15) [[1]] [1] Java-Array-Object[D:[D@1d58aae [[2]] [1] Java-Array-Object[D:[D@83cc67 [[3]] [1] Java-Array-Object[D:[D@e09713 ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). print(ar34Ret[2][3],digits=15) Error in print(ar34Ret[2][3], digits = 15) : object 'ar34Ret' not found print(ar34Ret,digits=20) Error in print(ar34Ret, digits = 20) : object 'ar34Ret' not found -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3476371.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
So the first few posts show that I found out how to get Java functions to return type double numbers to R. The arrays are still a problem. Here is another of my attempts to understand how to get java arrays into R. The Java code in class CalqsLin for an array of constants named conArr and for a function returning an array is: public static double[][]conArr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } I evidently do not know how to retrieve them in R, even with .jevalArray(): arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). connArr - .jevalArray(qsLin.conArr) Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found I need help from someone who calls Java from R. The whole session was: library(rJava) .jinit() .jaddClassPath(C:/ad/j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) calStg - 20110424235959 print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 calStg - .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4)) print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). connArr - .jevalArray(qsLin.conArr) Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3473023.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
you should take a look at the doc of .jarray by input ?.jarray in the console and see related examples by example(.jarray) in the console. This is what the doc says, and your issues might be related to it: '.jevalArray' currently supports only a subset of all possible array types. Recursive arrays are handled by returning a list of references which can then be evaluated separately. At 2011-04-25 20:27:24£¬hill0093 hill0...@umn.edu wrote: So the first few posts show that I found out how to get Java functions to return type double numbers to R. The arrays are still a problem. Here is another of my attempts to understand how to get java arrays into R. The Java code in class CalqsLin for an array of constants named conArr and for a function returning an array is: public static double[][]conArr=new double[][] { { 10001,10002,10003,10004 },{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } I evidently do not know how to retrieve them in R, even with .jevalArray(): arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). connArr - .jevalArray(qsLin.conArr) Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found I need help from someone who calls Java from R. The whole session was: library(rJava) .jinit() .jaddClassPath(C:/ad/j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) calStg - 20110424235959 print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 calStg - .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4)) print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) ar34Ret - .jevalArray(arj34Ret) Error in .jevalArray(arj34Ret) : object is not a Java object reference (jobjRef/jarrayRef). connArr - .jevalArray(qsLin.conArr) Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3473023.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
for(i in 1:3) for(j in 1:4) print(ar34Ret(i,j),digits=15) Error in print(ar34Ret(i, j), digits = 15) : could not find function ar34Ret The way you used ar34Ret(i, j) was actually wrong. It should be ar34Ret[i, j], if nothing else wrong. At 2011-04-25 08:06:51£¬hill0093 hill0...@umn.edu wrote: I added this R code to the bottom of the previous code and it doesn't work ar34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) print(ar34Ret,digits=20) [[1]] [1] Java-Array-Object[D:[D@8813f2 [[2]] [1] Java-Array-Object[D:[D@1d58aae [[3]] [1] Java-Array-Object[D:[D@83cc67 for(i in 1:3) for(j in 1:4) print(ar34Ret(i,j),digits=15) Error in print(ar34Ret(i, j), digits = 15) : could not find function ar34Ret The Java code is: public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } R doesn't know how to print the array in the next to final line, and thinks the array is a function in the final line. Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3472308.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Thanks Icn, for suggesting .jaddClassPath I finally had time to play around and discover what you meant. So I am one step farther than the report in the second post above: I have the RGui with R Console on the screen. On the top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() ## ?rJava::.jaddClassPath .jaddClassPath(C:/ad/j) ##or .jaddClassPath(C:\\ad\\j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,20110405235959,-4) Error in .jcall(qsLin, returnSig = D, linTimOfCalqsStgIsLev, 20110405235959, : method linTimOfCalqsStgIsLev with signature (Ljava/lang/String;Ljava/lang/String;)D not found What's wrong? Just to show my intentions, I had next wanted to call this java function method: linTimOfCalqsStgIsLev(20110405235959,-4) -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3471705.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
So I am one step farther than last time, so I am happy: I have the RGui with R Console on the screen. On the top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() .jaddClassPath(C:/ad/j) print(.jclassPath()) [1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java [2] C:\\ad\\j qsLin - .jnew(CalqsLin) calStg - 20110424235959 print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 calStg - .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4)) print(calStg) [1] 20110424235959 dblTim - .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4)) print(dblTim,digits=20) [1] 63470908799 -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3471943.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
I added this R code to the bottom of the previous code and it doesn't work ar34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST) print(ar34Ret,digits=20) [[1]] [1] Java-Array-Object[D:[D@8813f2 [[2]] [1] Java-Array-Object[D:[D@1d58aae [[3]] [1] Java-Array-Object[D:[D@83cc67 for(i in 1:3) for(j in 1:4) print(ar34Ret(i,j),digits=15) Error in print(ar34Ret(i, j), digits = 15) : could not find function ar34Ret The Java code is: public final static double[][] arReturnTEST() { double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); } R doesn't know how to print the array in the next to final line, and thinks the array is a function in the final line. Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3472308.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Using Java methods in R
I just now registered in R forum. I use Windows because of past history of using windows. I have been writing and using programs in java for about a decade. I work with unequal-interval-time-series data files, 1st 5 lines like: Title Line CnYrMoDaHrMnScDCMQ,ColSerTit1,ColSerTit2,ColSerTit3,ColSerTit4, 20110421235959,Ser1Datum1,Ser2Datum1,Ser3Datum1,Ser4Datum1, 201104220059428739,Ser1Datum2,Ser2Datum2,Ser3Datum2,Ser4Datum2, 201104220103369291,Ser1Datum3,Ser2Datum3,Ser3Datum3,Ser4Datum3, where e.g.Ser4Datum3 is a number, and calendartime unit can be anywhere from Da down to Q (Quadiseconds), a lot stops at Mn. Time is same unit throughout any one file. Getting to the point: I have all of the calendar-linear conversion and file reading subroutines as Java methods and would like to use them in R. I am not very knowledgeable yet about R. I need instructions about how to set up and use java in R on Windows. Can anyone help me with setup instructions then starting with a simple Java function (method) call. One problem with Java is that a function returns only one item. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469299.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
No answer to my post, so let's try a simpler question. Am I doing this correctly? I have the RGui with R Console on the screen. On rhe top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() qsLin - .jnew(C:/ad/j/CalqsLin) Error in .jnew(C:/ad/j/CalqsLin) : java.lang.NoClassDefFoundError: C:/ad/j/CalqsLin So I got this error which means I don't understand very much. I go to C:/ad/j and get C:\ad\jdir CalqsLin.class Volume in drive C has no label. Volume Serial Number is 9A35-67A2 Directory of C:\ad\j 04/23/2011 07:11 AM14,651 CalqsLin.class 1 File(s) 14,651 bytes 0 Dir(s) 104,257,716,224 bytes free Just to show my intentions, I had next wanted to call this java function method: linTimOfCalqsStgIsLev(20110405235959,-4) using: dblTim - .jcall(qsLin,D,linTimOfCalqsStgIsLev,20110405235959,-4) but that will probably also be wrong? Obviously I don't understand. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469848.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
On Sat, Apr 23, 2011 at 8:32 AM, hill0093 hill0...@umn.edu wrote: No answer to my post, so let's try a simpler question. Am I doing this correctly? I have the RGui with R Console on the screen. On rhe top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() qsLin - .jnew(C:/ad/j/CalqsLin) Error in .jnew(C:/ad/j/CalqsLin) : java.lang.NoClassDefFoundError: C:/ad/j/CalqsLin So I got this error which means I don't understand very much. I go to C:/ad/j and get C:\ad\jdir CalqsLin.class Volume in drive C has no label. Volume Serial Number is 9A35-67A2 Directory of C:\ad\j 04/23/2011 07:11 AM 14,651 CalqsLin.class 1 File(s) 14,651 bytes 0 Dir(s) 104,257,716,224 bytes free Just to show my intentions, I had next wanted to call this java function method: linTimOfCalqsStgIsLev(20110405235959,-4) using: dblTim - .jcall(qsLin,D,linTimOfCalqsStgIsLev,20110405235959,-4) but that will probably also be wrong? Obviously I don't understand. Have a look at the source of other packages that use rJava. Such packages are listed at the bottom of this page: http://cran.r-project.org/web/packages/rJava/index.html Also note that there is a separate list for R and Java: http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
That's more than I can understand. I just need help from someone who knows. Should be a simple answer from that person. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469882.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Since it cannot find a java class that is on my disk, is there a place I have to put it into first? -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3470350.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Date: Sat, 23 Apr 2011 05:32:59 -0700 From: hill0...@umn.edu To: r-help@r-project.org Subject: Re: [R] Using Java methods in R No answer to my post, so let's try a simpler question. Am I doing this correctly? I have the RGui with R Console on the screen. On rhe top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() qsLin - .jnew(C:/ad/j/CalqsLin) Error in .jnew(C:/ad/j/CalqsLin) : java.lang.NoClassDefFoundError: C:/ad/j/CalqsLin i haven't used rjava yet, I think I installed it on linux for testing but no real usage, but this message appears to come from jvm probably because you specified an aboslute path. You can try this from command line, $ ls ../geo/dayte* ../geo/dayte.class mmarchywka@phlulap01 /cygdrive/c/d/phluant/duphus $ java ../geo/dayte Exception in thread main java.lang.NoClassDefFoundError: ///geo/dayte Caused by: java.lang.ClassNotFoundException: ...geo.dayte at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: ../geo/dayte. Program will exit. you want to search for the classpath and set that up then refernce the class name not the path ( the class loader will follow the path looking for it ). Not sure how you do that in rjava under 'dohs but if you search for that term is should be apparent. And of course 'dohs and pdf aren't always friendly for automated work so get something like cygwin and reduce pdf's to text etc. So I got this error which means I don't understand very much. I go to C:/ad/j and get C:\ad\jdir CalqsLin.class Volume in drive C has no label. Volume Serial Number is 9A35-67A2 Directory of C:\ad\j 04/23/2011 07:11 AM 14,651 CalqsLin.class 1 File(s) 14,651 bytes 0 Dir(s) 104,257,716,224 bytes free Just to show my intentions, I had next wanted to call this java function method: linTimOfCalqsStgIsLev(20110405235959,-4) using: dblTim - .jcall(qsLin,D,linTimOfCalqsStgIsLev,20110405235959,-4) but that will probably also be wrong? Obviously I don't understand. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469848.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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@r-project.org mailing list 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.
Re: [R] Using Java methods in R
From: marchy...@hotmail.com To: hill0...@umn.edu; r-help@r-project.org Date: Sat, 23 Apr 2011 15:12:30 -0400 Subject: Re: [R] Using Java methods in R Date: Sat, 23 Apr 2011 05:32:59 -0700 From: hill0...@umn.edu To: r-help@r-project.org Subject: Re: [R] Using Java methods in R No answer to my post, so let's try a simpler question. Am I doing this correctly? I have the RGui with R Console on the screen. On rhe top pullDowns, Packages Install Packages USA(IA) rJava library(rJava) .jinit() qsLin - .jnew(C:/ad/j/CalqsLin) Error in .jnew(C:/ad/j/CalqsLin) : java.lang.NoClassDefFoundError: C:/ad/j/CalqsLin i haven't used rjava yet, I think I installed it on linux for testing but no real usage, but this message appears to come from jvm probably because you specified an aboslute path. You can try this from command line, $ ls ../geo/dayte* ../geo/dayte.class mmarchywka@phlulap01 /cygdrive/c/d/phluant/duphus $ java ../geo/dayte Exception in thread main java.lang.NoClassDefFoundError: ///geo/dayte Caused by: java.lang.ClassNotFoundException: ...geo.dayte at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: ../geo/dayte. Program will exit. you want to search for the classpath and set that up then refernce the class name not the path ( the class loader will follow the path looking for it ). Not sure how you do that in rjava under 'dohs but if you search for that term is should be apparent. And of course 'dohs and pdf aren't always friendly for automated work so get something like cygwin and reduce pdf's to text etc. It appears that by default the current directory is on the classpath. I must have installed this on 'dohs before and if I copy the class file into R directory it can find it, library(rJava) .jinit() .jnew(foo) Error in .jnew(foo) : java.lang.NoClassDefFoundError: foo .jnew(dayte) [1] Java-Object{dayte@1de3f2d} that's unlikely to fix all your problems, you want to set the classpath but if you know the term and can load cygwin you should be able to find the way to set that up. So I got this error which means I don't understand very much. I go to C:/ad/j and get C:\ad\jdir CalqsLin.class Volume in drive C has no label. Volume Serial Number is 9A35-67A2 Directory of C:\ad\j 04/23/2011 07:11 AM 14,651 CalqsLin.class 1 File(s) 14,651 bytes 0 Dir(s) 104,257,716,224 bytes free Just to show my intentions, I had next wanted to call this java function method: linTimOfCalqsStgIsLev(20110405235959,-4) using: dblTim - .jcall(qsLin,D,linTimOfCalqsStgIsLev,20110405235959,-4) but that will probably also be wrong? Obviously I don't understand. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469848.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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@r-project.org mailing list 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@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Well, the call to Java methods should be really simple in rJava. What you had tried is actually correct, initialize jvm, create an object, then call method. For the error you met, maybe you should check .jaddClassPath. At 2011-04-23 20:58:22£¬hill0093 hill0...@umn.edu wrote: That's more than I can understand. I just need help from someone who knows. Should be a simple answer from that person. -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3469882.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
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 http://groups.google.com/group/brumail/browse_thread/thread/a278dcbb6a8a439a . Hope it helps you in someway. Regards, Som Shekhar __ R-help@r-project.org mailing list 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.
Re: [R] Using Java methods in R
Hi Shekhar, Thank you. Right path. Sounds good. Please help me when you discover Java interface. Firstly, I don't know what the R symbol table is or how to do the checking you suggest. I am really naive about R. I want to be able to get my data in there so I can learn to use it for my purposes. Hill -- View this message in context: http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3470658.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.