[R-sig-Geo] RE: Using SJava?
Benjamin.STABLER at odot.state.or.us
Benjamin.STABLER at odot.state.or.us
Mon Apr 5 23:21:42 CEST 2004
Frank and Roger,
Sorry about the path reference - I just added the example on the fly in the
email and forgot about the R escape character. Attached is the simply class
that I used to test the link. It just takes a string as an input and
returns my email signature with the string substituted for the name.
The R code to run it:
library(SJava)
.JavaInit(config=javaConfig(classPath="F:/_ben/java"))
.Java("sig","print","Ben Stabler")
In terms of the jar file, it seems to work for me. Note that I moved the
jar file to a different directory so it did not find the class file by
itself as well.
> library(SJava)
using JAVA_HOME = C:\j2sdk1.4.2\jre
> .JavaInit(config=javaConfig(classPath="F:/_ben/sig.jar"))
> .Java("sig","print","Ben Stabler")
[1] "Ben Stabler" "Oregon Department of
Transportation"
[3] "Mill Creek Office Building" "555 13th Street NE Suite 2"
[5] "Salem, OR 97301-4178"
>
The print method of the sig class is static so I'm not having any difficulty
using static methods and I did not need to create a constructor first. You
shouldn't need a constructor/object for a static method (that is the point
of static methods). Unfortunately my IS department blocked the zip file you
sent. Could you send me the code as text or maybe just copy into email?
Thanks.
Ben
>-----Original Message-----
>From: Frank Hardisty [mailto:HardistF at gwm.sc.edu]
>Sent: Monday, April 05, 2004 1:07 PM
>To: Roger.Bivand at nhh.no
>Cc: STABLER Benjamin
>Subject: Re: [R-sig-Geo] RE: Using SJava?
>
>
>Roger and Benjamin,
>
>Benjamin, your advice is good and the test class does work. Roger, one
>difficulty is that we were calling a static method of the class, which
>does NOT work for some reason. However, the class can be instantiated
>and used from within R. Here's my session with my mistakes edited out:
>
>[Previously saved workspace restored]
>
>> library(SJava)
>using JAVA_HOME = C:\programs\j2sdk_nb\j2sdk1.4.2
>> .JavaInit(config=javaConfig(classPath="C:/temp/javatest/test.jar"))
>> testClass <- .JavaConstructor("TestJava")
>> .Java(testClass,"getMessage")
>[1] "Hi Roger!"
>>
>
>Benjamin, do you also find that static methods don't work in SJava?
>It's hard to understand, because calls to static methods in the Java
>runtime libraries work just fine, for example,
>
>> .Java("Math","random")
>[1] 0.07714792
>
>regards,
>-Frank
>
>>>> Roger Bivand <Roger.Bivand at nhh.no> 04/05/04 03:36PM >>>
>On Mon, 5 Apr 2004 Benjamin.STABLER at odot.state.or.us wrote:
>
>> Hopefully, I'm not too late on this one....when you initialize the
>JVM you
>> need to set the class path as follows:
>>
>>
>.JavaInit(config=javaConfig(classPath="StringDirectoryPathReference"))
>>
>> or
>>
>> .JavaInit(config=javaConfig(classPath=c("String1", "String2")))
>>
>> for example:
>>
>> .JavaInit(config=javaConfig(classPath="C:\javastuff"))
>>
>> where javastuff contains my class files. You need to specify the jar
>file
>> name if you are trying to include class files within jars. I have
>used it
>> with some classes that I wrote.
>
>Yes, and Sys.putenv("CLASSPATH"="String1") can be used too, but what do
>
>you put in .Java() to get into your own jars? Are there escaping issues
>in
>the path to the jars? (backslash twice? forwardslash?) Could we put up
>
>some jars and some instructions for use on a website? Frank Hardisty
>sent
>me an example off-list that works from the command line but which I
>can't
>find from within R/SJava (Windows XP, the SJava examples that I've
>tried
>work for me).
>
>The idea would be to see if GeoTools2 can be reached from within R,
>because it could provide (another) way to import/export multiple GIS
>formats.
>
>Roger
>
>>
>> I too am excited about linking Java and R, as there is so much useful
>code
>> in the Java community.
>>
>> Benjamin Stabler
>> Transportation Planning Analysis Unit
>> Oregon Department of Transportation
>> 555 13th Street NE, Suite 2
>> Salem, OR 97301 Ph: 503-986-4104
>>
>>
>> >Message: 5
>> >Date: Fri, 2 Apr 2004 20:56:50 +0200 (CEST)
>> >From: Roger Bivand <Roger.Bivand at nhh.no>
>> >Subject: [R-sig-Geo] Using SJava?
>> >To: r-sig-geo at stat.math.ethz.ch
>> >Cc: Frank Hardisty <HardistF at gwm.sc.edu>
>> >Message-ID:
><Pine.LNX.4.44.0404022042580.28093-100000 at reclus.nhh.no>
>> >Content-Type: TEXT/PLAIN; charset=US-ASCII
>> >
>> >Is anyone on this list using SJava or any R/Java connection?
>> >Not only is
>> >the JTS Topology Suite that Tim just mentioned interesting,
>> >but so is the
>> >upcoming GeoTools2 at http://www.geotools.org/. Both are
>> >likely to be used
>> >quite a lot, and thus probably well-maintained.
>> >
>> >At the recent Association of American Geographers meeting,
>> >Frank Hardisty
>> >asked me about this, and while I was able to install SJava (from
>> >http://www.stats.ox.ac.uk/pub/RWin) on a Win XP laptop, we
>> >were not able
>> >to see how to get Java within R to see GeoTools in its
>> >classpath. Both of
>> >these Java resources are potentially useful, and R opinions
>> >two or three
>> >years ago, that Java is slow, may need revision given increased
>machine
>> >capacity. I feel we could benefit from mobilizing Java insight
>> >(but I feel
>> >personally Java-challenged!).
>> >
>> >I believe that Duncan Temple-Lang was playing with/working on object
>
>> >discovery - this could be very relevant in terms of matching
>> >R-internal
>> >object representations with those in existing software that we
>> >could - if
>> >SJava worked - link to. I also think that we could ask him for
>> >advice if
>> >we discussed it first here. What do others think?
>> >
>> >--
>> >Roger Bivand
>> >Economic Geography Section, Department of Economics, Norwegian
>> >School of
>> >Economics and Business Administration, Breiviksveien 40, N-5045
>Bergen,
>> >Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
>> >e-mail: Roger.Bivand at nhh.no
>> >
>> >
>> >
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>--
>Roger Bivand
>Economic Geography Section, Department of Economics, Norwegian School
>of
>Economics and Business Administration, Breiviksveien 40, N-5045
>Bergen,
>Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
>e-mail: Roger.Bivand at nhh.no
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sig.class
Type: application/octet-stream
Size: 476 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20040405/3931ed6a/attachment.class>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sig.java
Type: application/octet-stream
Size: 342 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20040405/3931ed6a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sig.jar
Type: application/octet-stream
Size: 809 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20040405/3931ed6a/attachment-0001.obj>
More information about the R-sig-Geo
mailing list