├── javadoc
├── package-list
├── resources
│ └── inherit.gif
├── stylesheet.css
├── index.html
├── allclasses-noframe.html
├── allclasses-frame.html
├── sngforge
│ └── java2r
│ │ ├── package-frame.html
│ │ ├── class-use
│ │ ├── RBase.html
│ │ ├── RHelp.html
│ │ ├── RParser.html
│ │ ├── RScript.html
│ │ └── RGraphics.html
│ │ ├── package-tree.html
│ │ └── package-use.html
├── nr
│ └── co
│ │ └── sngforge
│ │ └── java2r
│ │ ├── package-frame.html
│ │ └── class-use
│ │ ├── RBase.html
│ │ ├── RHelp.html
│ │ ├── RParser.html
│ │ ├── RScript.html
│ │ └── RGraphics.html
├── deprecated-list.html
├── index-files
│ ├── index-14.html
│ ├── index-1.html
│ ├── index-17.html
│ ├── index-4.html
│ ├── index-10.html
│ ├── index-11.html
│ ├── index-2.html
│ ├── index-15.html
│ └── index-16.html
├── serialized-form.html
└── overview-tree.html
├── source
├── nbproject
│ ├── private
│ │ ├── config.properties
│ │ ├── private.xml
│ │ └── private.properties
│ ├── genfiles.properties
│ ├── project.xml
│ └── project.properties
├── build
│ └── classes
│ │ ├── .netbeans_automatic_build
│ │ └── sngforge
│ │ └── java2r
│ │ ├── RBase.class
│ │ ├── RHelp.class
│ │ ├── RParser.class
│ │ ├── RScript.class
│ │ ├── RFactory.class
│ │ ├── RGraphics.class
│ │ ├── test
│ │ └── Mean.class
│ │ ├── RException.class
│ │ ├── RFactoryException.class
│ │ └── RBase$LineRedirecter.class
├── src
│ └── sngforge
│ │ └── java2r
│ │ ├── test
│ │ └── Mean.java
│ │ ├── RException.java
│ │ ├── RFactoryException.java
│ │ ├── RFactory.java
│ │ ├── RHelp.java
│ │ ├── RBase.java
│ │ ├── RScript.java
│ │ ├── RGraphics.java
│ │ └── RParser.java
└── build.xml
├── Java2R.jar
├── java2R_v1.0.zip
├── CHANGES.txt
├── examples
├── RMiscDemo.class
├── RTerminal.class
├── ExecRCommand.class
├── RGraphicsDemo.class
├── RGraphicsDemo.java
├── ExecRCommand.java
├── RMiscDemo.java
└── RTerminal.java
├── README
└── README.txt
/javadoc/package-list:
--------------------------------------------------------------------------------
1 | sngforge.java2r
2 |
--------------------------------------------------------------------------------
/source/nbproject/private/config.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/source/build/classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Java2R.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/Java2R.jar
--------------------------------------------------------------------------------
/java2R_v1.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/java2R_v1.0.zip
--------------------------------------------------------------------------------
/CHANGES.txt:
--------------------------------------------------------------------------------
1 | Java2R Changelog
2 |
3 | Version 1.00
4 | ~~~~~~~~~~~~
5 | Happy Birthday Java2R!
--------------------------------------------------------------------------------
/examples/RMiscDemo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/examples/RMiscDemo.class
--------------------------------------------------------------------------------
/examples/RTerminal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/examples/RTerminal.class
--------------------------------------------------------------------------------
/examples/ExecRCommand.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/examples/ExecRCommand.class
--------------------------------------------------------------------------------
/examples/RGraphicsDemo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/examples/RGraphicsDemo.class
--------------------------------------------------------------------------------
/javadoc/resources/inherit.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/javadoc/resources/inherit.gif
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RBase.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RBase.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RHelp.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RHelp.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RParser.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RParser.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RScript.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RScript.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RFactory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RFactory.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RGraphics.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RGraphics.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/test/Mean.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/test/Mean.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RException.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RFactoryException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RFactoryException.class
--------------------------------------------------------------------------------
/source/build/classes/sngforge/java2r/RBase$LineRedirecter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngsankha/java2r/master/source/build/classes/sngforge/java2r/RBase$LineRedirecter.class
--------------------------------------------------------------------------------
/source/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | compile.on.save=true
2 | do.depend=false
3 | do.jar=true
4 | javac.debug=true
5 | javadoc.preview=true
6 | jaxws.endorsed.dir=C:\\Program Files\\NetBeans 6.7.1\\java2\\modules\\ext\\jaxws21\\api:C:\\Program Files\\NetBeans 6.7.1\\ide11\\modules\\ext\\jaxb\\api
7 | user.properties.file=C:\\Documents and Settings\\s.n.guria\\.netbeans\\6.7\\build.properties
8 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This library Java2R is a port to R and can be used in
2 | your Java programs to connect R and Java. As you can well imagine
3 | then you can have rich interactive applications at the same time
4 | use the power of R. You can use this to perform statistical
5 | computations from R and used to prepare high quality graphs.
6 |
7 | 2. License
8 | ~~~~~~~~~~
9 | This is a open-source free library licensed under GNU General Public
10 | License. The full license text can be found in the LICENSE.txt file.
--------------------------------------------------------------------------------
/source/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=cdb477c7
2 | build.xml.script.CRC32=e1e519a5
3 | build.xml.stylesheet.CRC32=958a1d3e@1.26.2.45
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=cdb477c7
7 | nbproject/build-impl.xml.script.CRC32=8d88a0dd
8 | nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45
9 |
--------------------------------------------------------------------------------
/source/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 | Java2R
7 | 1.6.5
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/RGraphicsDemo.java:
--------------------------------------------------------------------------------
1 | import nr.co.sngforge.java2r.*;
2 |
3 | /*
4 | This example shows a Graph in a Swing Window
5 | */
6 |
7 | class RGraphicsDemo
8 | {
9 | public static void main(String args[])throws Exception
10 | {
11 | //initializing RFactory class
12 | //the next line is for Windows. If on other systems comment out this line
13 | RFactory rf=new RFactory("c:/Program Files/R/R-2.7.1/bin/R.exe");//replace this with the location of R executable
14 | //the next line is for Linux. If on ther systems comment out this line
15 | //RFactory rf=new RFactory("R");
16 | RGraphics rg=new RGraphics(rf,RGraphics.JAVA2R,"");
17 | rg.execute("plot(sin, -pi, 2*pi)");
18 | rf.close();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/ExecRCommand.java:
--------------------------------------------------------------------------------
1 | import nr.co.sngforge.java2r.*;
2 |
3 | /*
4 | This example shows how to execute a R command from Java.
5 | This executes the command using RParser class.
6 | */
7 |
8 | class ExecRCommand
9 | {
10 | public static void main(String args[])throws Exception
11 | {
12 | //initializing RFactory class
13 | //the next line is for Windows. If on other systems comment out this line
14 | RFactory rf=new RFactory("c:/Program Files/R/R-2.7.1/bin/R.exe");//replace this with the location of R executable
15 | //the next line is for Linux. If on ther systems comment out this line
16 | //RFactory rf=new RFactory("R");
17 | RParser rp=new RParser(rf);
18 | //Perforimg a simple addition
19 | rp.eval("4+4",System.out,false);
20 | //Show summary about the trees dataset
21 | rp.eval("summary(trees)",System.out,false);
22 | rf.close();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/RMiscDemo.java:
--------------------------------------------------------------------------------
1 | import nr.co.sngforge.java2r.*;
2 | import java.io.*;
3 |
4 | /*
5 | This example shows miscellaneous capabilities
6 | */
7 |
8 | class RMiscDemo
9 | {
10 | public static void main(String args[])throws Exception
11 | {
12 | //initializing RFactory class
13 | //the next line is for Windows. If on other systems comment out this line
14 | RFactory rf=new RFactory("c:/Program Files/R/R-2.7.1/bin/R.exe");//replace this with the location of R executable
15 | //the next line is for Linux. If on ther systems comment out this line
16 | //RFactory rf=new RFactory("R");
17 | System.out.println("Please enter the path to a R script file");
18 | BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
19 | String path=br.readLine();
20 | RScript rs=new RScript(rf);
21 | rs.eval(path);
22 | System.out.println("Now I will show you a R help window.");
23 | RHelp rh=new RHelp(rf);
24 | rh.getHelp("graphics");
25 | rf.close();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/test/Mean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package sngforge.java2r.test;
7 |
8 | import sngforge.java2r.*;
9 | import java.io.*;
10 |
11 | public class Mean {
12 | public static void main(String args[])throws Exception{
13 | RFactory rf=new RFactory("C:\\Program Files\\R\\R-2.9.2\\bin\\R.exe");
14 |
15 | /*RBase rb=new RBase(rf,fout,System.err,RBase.VERY_QUIET);
16 | rb.execute("x=c(8,4,5,9,5)");
17 | rb.execute("mean(x)");*/
18 | RScript rs=new RScript(rf);
19 | String result=rs.eval("C:\\Documents and Settings\\s.n.guria\\Desktop\\mmn.R");
20 | System.out.println(result);
21 | /*RGraphics rg=new RGraphics(rf,RGraphics.PDF,"C:\\Documents and Settings\\s.n.guria\\Desktop\\graph.pdf");
22 | rg.execute("plot(sin,-pi,pi)");
23 | rg.close(null);*/
24 | rf.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/examples/RTerminal.java:
--------------------------------------------------------------------------------
1 | import nr.co.sngforge.java2r.*;
2 | import java.io.*;
3 |
4 | /*
5 | This example creates a R Terminal based on Java.
6 | */
7 |
8 | class RTerminal
9 | {
10 | public static void main(String args[])throws Exception
11 | {
12 | //initializing RFactory class
13 | //the next line is for Windows. If on other systems comment out this line
14 | RFactory rf=new RFactory("c:/Program Files/R/R-2.7.1/bin/R.exe");//replace this with the location of R executable
15 | //the next line is for Linux. If on ther systems comment out this line
16 | //RFactory rf=new RFactory("R");
17 | //for(int i=0;i<=10000;i++);
18 | System.out.println("Enter q() to exit");
19 | //to take input
20 | BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
21 | String cmd="";
22 | //initializing RBase class
23 | RBase rb=new RBase(rf,System.out,System.err,RBase.VERY_QUIET);
24 | while(cmd.equals("q()")==false)
25 | {
26 | cmd=br.readLine();
27 | rb.execute(cmd);
28 | }
29 | rf.close();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | /**
22 | * Exception due to miscellaneous error.
23 | * @author Sankha Narayan Guria
24 | * @version 1.0
25 | */
26 | public class RException extends Exception {
27 | /**
28 | * Constructs an instance of RException with the specified detail message.
29 | * @param msg The detail message.
30 | */
31 | public RException(String msg) {
32 | super(msg);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RFactoryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | /**
22 | * Exception due to error in initialization of RFactory
23 | * @author Sankha Narayan Guria
24 | * @version 1.0
25 | */
26 | public class RFactoryException extends Exception {
27 | /**
28 | * Constructs an instance of RFactoryException with the specified detail message.
29 | * @param msg The detail message.
30 | */
31 | public RFactoryException(String msg) {
32 | super(msg);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/javadoc/stylesheet.css:
--------------------------------------------------------------------------------
1 | /* Javadoc style sheet */
2 |
3 | /* Define colors, fonts and other style attributes here to override the defaults */
4 |
5 | /* Page background color */
6 | body { background-color: #FFFFFF; color:#000000 }
7 |
8 | /* Headings */
9 | h1 { font-size: 145% }
10 |
11 | /* Table colors */
12 | .TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */
13 | .TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */
14 | .TableRowColor { background: #FFFFFF; color:#000000 } /* White */
15 |
16 | /* Font used in left-hand frame lists */
17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
20 |
21 | /* Navigation bar fonts and colors */
22 | .NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */
23 | .NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */
24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;}
25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;}
26 |
27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
29 |
30 |
--------------------------------------------------------------------------------
/javadoc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/source/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | application.desc=Java2R: A library to connect Java and R
2 | application.title=Java2R
3 | application.vendor=Sankha Narayan Guria
4 | auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
5 | auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
6 | auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=default
7 | build.classes.dir=${build.dir}/classes
8 | build.classes.excludes=**/*.java,**/*.form
9 | # This directory is removed when the project is cleaned:
10 | build.dir=build
11 | build.generated.dir=${build.dir}/generated
12 | build.generated.sources.dir=${build.dir}/generated-sources
13 | # Only compile against the classpath explicitly listed here:
14 | build.sysclasspath=ignore
15 | build.test.classes.dir=${build.dir}/test/classes
16 | build.test.results.dir=${build.dir}/test/results
17 | # Uncomment to specify the preferred debugger connection transport:
18 | #debug.transport=dt_socket
19 | debug.classpath=\
20 | ${run.classpath}
21 | debug.test.classpath=\
22 | ${run.test.classpath}
23 | # This directory is removed when the project is cleaned:
24 | dist.dir=dist
25 | dist.jar=${dist.dir}/Java2R.jar
26 | dist.javadoc.dir=${dist.dir}/javadoc
27 | excludes=
28 | includes=**
29 | jar.compress=true
30 | javac.classpath=
31 | # Space-separated list of extra javac options
32 | javac.compilerargs=
33 | javac.deprecation=false
34 | javac.source=1.5
35 | javac.target=1.5
36 | javac.test.classpath=\
37 | ${javac.classpath}:\
38 | ${build.classes.dir}:\
39 | ${libs.junit.classpath}:\
40 | ${libs.junit_4.classpath}
41 | javadoc.additionalparam=
42 | javadoc.author=false
43 | javadoc.encoding=${source.encoding}
44 | javadoc.noindex=false
45 | javadoc.nonavbar=false
46 | javadoc.notree=false
47 | javadoc.private=false
48 | javadoc.splitindex=true
49 | javadoc.use=true
50 | javadoc.version=false
51 | javadoc.windowtitle=
52 | jnlp.codebase.type=local
53 | jnlp.codebase.url=file:/E:/sankha/sngforge/Java2R/dist/
54 | jnlp.descriptor=application
55 | jnlp.enabled=false
56 | jnlp.offline-allowed=false
57 | jnlp.signed=false
58 | main.class=sngforge.java2r.test.Mean
59 | meta.inf.dir=${src.dir}/META-INF
60 | platform.active=default_platform
61 | run.classpath=\
62 | ${javac.classpath}:\
63 | ${build.classes.dir}
64 | # Space-separated list of JVM arguments used when running the project
65 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
66 | # or test-sys-prop.name=value to set system properties for unit tests):
67 | run.jvmargs=
68 | run.test.classpath=\
69 | ${javac.test.classpath}:\
70 | ${build.test.classes.dir}
71 | source.encoding=UTF-8
72 | src.dir=src
73 | test.src.dir=test
74 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import java.io.*;
22 |
23 | /**
24 | * This class should be initialized at the start of the program.
25 | * It creates a temporary session directory in the user's home directory's .java2r folder. It is deleted when the close() method is called.
26 | * @author Sankha Narayan Guria
27 | * @version 1.0
28 | */
29 | public class RFactory {
30 |
31 | private String rexec;
32 | private String sesnDir;
33 |
34 | /**
35 | * Creates an instance of the RFactory class.
36 | * @param rexec The path to the R executable
37 | * @exception nr.co.sngforge.java2r.RFactoryException Thrown if there is error while creating a RFactory object or temporary session directory.
38 | */
39 | public RFactory(String rexec) throws RFactoryException{
40 | this.rexec=rexec;
41 | setWorkDir();
42 | }
43 |
44 | private void setWorkDir() throws RFactoryException{
45 | boolean result=true;
46 | String wd=System.getProperty("user.home").replace("\\","/")+"/.java2r";
47 | File wdf=new File(wd);
48 | if(wdf.exists()==false)
49 | result=wdf.mkdir();
50 | String sesn=wd+"/s";
51 | int n=0;
52 | while(new File(sesn+n).exists()==true)
53 | n++;
54 | File sesnf=new File(sesn+n);
55 | result=sesnf.mkdir();
56 | if(result==false)
57 | throw new RFactoryException("Error in creating temporary session diectory");
58 | sesnDir=sesn+n;
59 | }
60 |
61 | /**
62 | * Returns the path of the R executable.
63 | */
64 | public String getRexec(){
65 | return rexec;
66 | }
67 |
68 | /**
69 | * Returns the path of the temporay session directory
70 | */
71 | public String getSesnDir(){
72 | return sesnDir;
73 | }
74 |
75 | /**
76 | * Closes the RFactory instance.
77 | * This method should be called at the end of your program. This deletes the temporary session directory and sets the location of the session directory and the R exeutable to null.
78 | * @exception nr.co.sngforge.java2r.RFactoryException Thrown if there is error while deleting the temporary session directory.
79 | */
80 | public void close() throws RFactoryException{
81 | boolean result=true;
82 | File sesnf=new File(sesnDir);
83 | File inside[]=sesnf.listFiles();
84 | for(int i=0;i
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project Java2R.
12 |
13 |
74 |
75 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RHelp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import java.io.*;
22 |
23 | /**
24 | * This class can be used for displaying the help from R.
25 | * @author Sankha Narayan Guria
26 | * @version 1.0
27 | */
28 |
29 | public class RHelp {
30 |
31 | private RBase rb;
32 |
33 | /**
34 | * This creates an instance of this class.
35 | * System.out is used as the standard output stream (stdout) nad System.err is used as the error stream(stderr).
36 | * @param rf An instance of RFactory that has already been initialized.
37 | * @throws java.io.IOException Thrown if there is an error in redirecting the IO Streams.
38 | */
39 | public RHelp(RFactory rf) throws IOException
40 | {
41 | rb=new RBase(rf, System.out, System.err, RBase.VERY_QUIET);
42 | }
43 |
44 | /**
45 | * Constructor to instantiate an object of this class.
46 | * @param rf The RFactory object that has already been initialized.
47 | * @param out The OutputStream to print the normal standard output(stdout) messages of R. Can be System.out or System.err also.
48 | * @param err The OutputStream to print the error output(stderr) messages of R. Can be System.out or System.err also.
49 | * @param q The quietness level in which R will be run. The follwing values may be used
RBase.LESS_QUIET
RBase.NOT_QUIET
RBase.VERY_QUIET
50 | * @throws java.io.IOException Thrown if there is an error in redirecting the IO Streams.
51 | */
52 | public RHelp(RFactory rf, OutputStream out, OutputStream err, int q) throws IOException
53 | {
54 | rb=new RBase(rf, out, err, q);
55 | }
56 |
57 | /**
58 | * This tells R to show help on a topic. This is similiar to the command help(topic).
59 | * @param topic The topic on which help is to shown.
60 | */
61 | public void getHelp(String topic)
62 | {
63 | rb.execute("help("+topic+")");
64 | }
65 |
66 | /**
67 | * This tells R to show some demos. This is similiar to the command demo().
68 | */
69 | public void demo(){
70 | rb.execute("demo()");
71 | }
72 |
73 | /**
74 | * This starts the help in an HTML browser interface. This is similiar to the command help.start().
75 | */
76 | public void helpStart(){
77 | rb.execute("help.start()");
78 | }
79 |
80 | /**
81 | * This tells R to search its help for a query. This is similiar to the command help.search(query).
82 | * @param query The search string
83 | */
84 | public void helpSearch(String query){
85 | rb.execute("help.search("+query+")");
86 | }
87 |
88 | /**
89 | * This shows Apropos. This is similiar to the command apropos(query).
90 | * @param query The string to be used as the parameter.
91 | */
92 | public void apropos(String query){
93 | rb.execute("apropos("+query+")");
94 | }
95 |
96 | /**
97 | * This method ensures that R has exited successfully before the RHelp object is destroyed.
98 | */
99 | protected void finalize(){
100 | rb.execute("q()");
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | Java2R Version 1.0 - Readme
2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 |
4 | Contents
5 | ~~~~~~~~
6 | 1. Introduction
7 | 2. License
8 | 3. System Requirements
9 | 4. Latest Version
10 | 5. Installation
11 | 6. Documentation
12 | 7. Examples
13 | 8. Files
14 | 9. Distributing your Application
15 | 10. Building the Source Code
16 | 11. Contact Me & Support
17 |
18 | 1. Introduction
19 | ~~~~~~~~~~~~~~~
20 | R is software for statistical computing. It has its own scripting
21 | language. Its power and flexibility has led to the growth of its
22 | popularity. This library Java2R is a port to R and can be used in
23 | your Java programs to connect R and Java. As you can well imagine
24 | then you can have rich interactive applications at the same time
25 | use the power of R. You can use this to perform statistical
26 | computations from R and used to prepare high quality graphs.
27 |
28 | 2. License
29 | ~~~~~~~~~~
30 | This is a open-source free library licensed under GNU General Public
31 | License. The full license text can be found in the COPYING.txt file.
32 |
33 | 3. System Requirements
34 | ~~~~~~~~~~~~~~~~~~~~~~
35 | To use Java2R you should have
36 | * A recent version of the JDK (I have tested this with JDK 1.6.0)
37 | * Any operating system on which R binaries can run.
38 | (I have tested this with Microsoft Windows XP Service Pack 3)
39 | * A proper R installation (I have tested this with R 2.7.1)
40 | You can get one from http://www.r-project.org/
41 |
42 | 4. Latest Version
43 | ~~~~~~~~~~~~~~~~~
44 | The latest version can be obtained from https://github.com/sankha93/java2r
45 |
46 | 5. Installation
47 | ~~~~~~~~~~~~~~~
48 | To use Java2R in your Java programs you need to add the "Java2R.jar"
49 | file to your CLASSPATH. To know how to change your CLASSPATH
50 | environment variable please consult your system documentation.
51 | To do this in Windows execute the follwing command after going to the
52 | Command Prompt.
53 | SET CLASSPATH=%CLASSPATH%;
54 | Replace with the location of the Java2R.jar file.
55 |
56 | You can also use it with javac and java by
57 | javac -cp
58 | java -cp
59 |
60 | To use it in your IDE please coonsult your IDE documentation on how to add
61 | add Libraries to your projects.
62 |
63 | 6. Documentation
64 | ~~~~~~~~~~~~~~~~
65 | The Java2R API Javadoc can be found in the docs folder. Please open the
66 | index.html file in your browser to view it.
67 |
68 | 7. Examples
69 | ~~~~~~~~~~~
70 | Examples for Java2R can be found in the examples folder. You need to
71 | compile the source code files to run the examples.
72 |
73 | To compile them use
74 | javac -cp
75 |
76 | To run them do
77 | java -cp
78 |
79 | 8.Files
80 | ~~~~~~~
81 | The following files are included in the distribution
82 | README.TXT This file
83 | COPYING.TXT The full license text
84 | Java2R.jar This the jar file of Java2R
85 | docs This folder contains the library documentation
86 | source The source code for this library
87 |
88 | 9. Distributing your Application
89 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 | All applications that you build with the keyval library should distribute the
91 | Java2R.jar file in order to run the application properly and it should have
92 | a proper version of R installed for that system.
93 |
94 | 10. Building the Source Code
95 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 | To build the source code you should have Ant (http://ant.apache.org)
97 | installed or NetBeans IDE 6.5 installed. This was created in NetBeans
98 | so you can open the source code as project in NetBeans directly.
99 |
100 | To build it with ant make sure that the source folder is your current
101 | directory. Then execute the following command
102 | ant
103 |
104 | 11. Contact Me & Support
105 | ~~~~~~~~~~~~~~~~~~~~~~~~
106 | There may be bugs in this library. If you find any problem or have any
107 | suggestion then kindly report them to me.
108 |
109 | If possible you may rewrite some parts of the program and send them to me.
110 |
111 | Website: https://github.com/sankha93/java2r
112 | E-Mail: sankha93@gmail.com
113 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import java.io.*;
22 |
23 | /**
24 | * This class forms the basic port to the R executable. It can be used for interacting with R.
25 | * @author Sankha Narayan Guria
26 | * @version 1.0
27 | */
28 |
29 | public class RBase {
30 |
31 | private RFactory rf;
32 | private OutputStream out;
33 | private Process r;
34 | private PrintStream rIn;
35 |
36 | /**
37 | * Parameter to specify that R runs in the slave and silent mode. In this case it gives the least messages.
38 | */
39 | public static final int VERY_QUIET=0;
40 | /**
41 | * Parameter to specify that R runs in the silent mode. In this case it gives some messages.
42 | */
43 | public static final int LESS_QUIET=1;
44 | /**
45 | * Parameter to specify that R runs in normal mode. In this case it gives all messages.
46 | */
47 | public static final int NOT_QUIET=2;
48 |
49 | private static class LineRedirecter extends Thread {
50 | private InputStream in;
51 | private OutputStream out;
52 |
53 | LineRedirecter(InputStream in, OutputStream out) {
54 | this.in = in;
55 | this.out = out;
56 | }
57 |
58 | public void run()
59 | {
60 | try {
61 | BufferedReader reader = new BufferedReader(new InputStreamReader(in));
62 | PrintStream printStream = new PrintStream(out);
63 | String line;
64 |
65 | while ( (line = reader.readLine()) != null)
66 | printStream.println(line);
67 | } catch (IOException exc) {
68 | System.err.println(exc);
69 | }
70 | }
71 |
72 | }
73 |
74 | /**
75 | * Constructor to instantiate an object of this class.
76 | * @param rf The RFactory object that has already been initialized.
77 | * @param out The OutputStream to print the normal standard output(stdout) messages of R. Can be System.out or System.err also.
78 | * @param err The OutputStream to print the error output(stderr) messages of R. Can be System.out or System.err also.
79 | * @param q The quietness level in which R will be run. The follwing values may be used
RBase.LESS_QUIET
RBase.NOT_QUIET
RBase.VERY_QUIET
80 | * @throws java.io.IOException Thrown if there is an error in redirecting the IO Streams.
81 | */
82 | public RBase(RFactory rf, OutputStream out, OutputStream err, int q) throws IOException{
83 | this.rf=rf;
84 | this.out=out;
85 | String process=rf.getRexec()+" --no-save";
86 | if(q==0)
87 | process=process+" --slave";
88 | else if(q==1)
89 | process=process+" -q";
90 | r=Runtime.getRuntime().exec(process);
91 | new LineRedirecter(r.getInputStream(), out).start();
92 | new LineRedirecter(r.getErrorStream(), err).start();
93 | rIn = new PrintStream(r.getOutputStream());
94 | }
95 |
96 | /**
97 | * This command executes the command in R.
98 | * @param cmd The command exactly in the same form as R
99 | */
100 | public void execute(String cmd){
101 | rIn.println(cmd);
102 | rIn.flush();
103 | }
104 |
105 | /**
106 | * This method ensures that R has exited successfully before the RBase object is destroyed.
107 | */
108 | protected void finalize(){
109 | execute("q()");
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RScript.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import java.io.*;
22 |
23 | /**
24 | * This class parses R scipts stored in a file.
25 | * After the execution the proc.time() command is executed automatically. The command q(save = \"no\", status = 0, runLast = FALSE) needs to be the last line of your script to prevent this.
26 | * @author Sankha Narayan Guria
27 | * @version 1.0
28 | */
29 | public class RScript {
30 | private RFactory rf;
31 |
32 | /**
33 | * This creates an instance of this class.
34 | * @param rf A RFactory object that has already ben instantiated.
35 | */
36 | public RScript(RFactory rf){
37 | this.rf=rf;
38 | }
39 |
40 | /**
41 | * This executes the script.
42 | * @param file A File refering to the script file
43 | * @return The results in a String
44 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
45 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
46 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
47 | */
48 | public String eval(File file)throws IOException, InterruptedException, RException{
49 | Process r=Runtime.getRuntime().exec(rf.getRexec()+" CMD BATCH --slave \""+file.getAbsolutePath()+"\" \""+rf.getSesnDir()+"/tmp.Rout\"");
50 | int i=r.waitFor();
51 | if(i!=0)
52 | throw new RException("Unspecified Error Occured!");
53 | FileReader fr=new FileReader(rf.getSesnDir()+"/tmp.Rout");
54 | BufferedReader br=new BufferedReader(fr);
55 | String out="", line="";
56 | while((line=br.readLine())!=null)
57 | out=out+line+"\n";
58 | fr.close();
59 | return out;
60 | }
61 |
62 | /**
63 | * This executes the script.
64 | * @param file Path to the script file
65 | * @return The results in a String
66 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
67 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
68 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
69 | */
70 | public String eval(String file)throws IOException, InterruptedException, RException{
71 | return eval(new File(file));
72 | }
73 |
74 | /**
75 | * This executes the script.
76 | * @param file A File refering to the script file
77 | * @param out The OutputStream in which the results will be dumped.
78 | * @param close A boolean value specifying whether the OutputStream should be closed or not. It is useful when the OutputStream is writing to a file.
79 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
80 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
81 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
82 | */
83 | public void eval(File file, OutputStream out, boolean close)throws IOException, InterruptedException, RException{
84 | Process r=Runtime.getRuntime().exec(rf.getRexec()+" CMD BATCH --slave \""+file.getAbsolutePath()+"\" \""+rf.getSesnDir()+"/tmp.Rout\"");
85 | int i=r.waitFor();
86 | if(i!=0)
87 | throw new RException("Unspecified Error Occured!");
88 | FileReader fr=new FileReader(rf.getSesnDir()+"/tmp.Rout");
89 | BufferedReader br=new BufferedReader(fr);
90 | PrintStream printStream = new PrintStream(out);
91 | String line="";
92 | while((line=br.readLine())!=null)
93 | printStream.println(line);
94 | fr.close();
95 | if(close)
96 | out.close();
97 | }
98 |
99 | /**
100 | * This executes the script.
101 | * @param file Path to the script file
102 | * @param out The OutputStream in which the results will be dumped.
103 | * @param close A boolean value specifying whether the OutputStream should be closed or not. It is useful when the OutputStream is writing to a file.
104 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
105 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
106 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
107 | */
108 | public void eval(String file, OutputStream out, boolean close)throws IOException, InterruptedException, RException{
109 | eval(new File(file),out,close);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/javadoc/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Deprecated List
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RGraphics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import javax.swing.*;
22 | import java.io.*;
23 |
24 | /**
25 | * This class provides an interface to perform graphical operations with R.
26 | * @author Sankha Narayan Guria
27 | * @version 1.0
28 | */
29 | public class RGraphics {
30 |
31 | private RBase rb;
32 | private RFactory rf;
33 | private int device;
34 |
35 | /**
36 | * This indicates that the current R Graphics Device is Postscript(PS).
37 | */
38 | public static final int POSTSCRIPT=0;
39 | /**
40 | * This indicates that the current R Graphics Device is Portable Document Format(PDF).
41 | */
42 | public static final int PDF=1;
43 | /**
44 | * This indicates that the current R Graphics Device is embeddable picture LaTeX form (PicTeX).
45 | */
46 | public static final int PICTEX=2;
47 | /**
48 | * This indicates that the current R Graphics Device is Portable Network Graphics(PNG).
49 | */
50 | public static final int PNG=3;
51 | /**
52 | * This indicates that the current R Graphics Device is JPEG.
53 | */
54 | public static final int JPEG=4;
55 | /**
56 | * This indicates that the current R Graphics Device is Bitmap(BMP).
57 | */
58 | public static final int BMP=5;
59 | /**
60 | * This indicates that the current R Graphics Device is XFig.
61 | */
62 | public static final int XFIG=6;
63 | /**
64 | * This indicates that the current R Graphics Device is TIFF.
65 | */
66 | public static final int TIFF=7;
67 | /**
68 | * This is not a real R Device. It just shows the graphics on-screen in a window.
69 | */
70 | public static final int JAVA2R=8;
71 |
72 | /**
73 | * This creates an instance of the RGraphics class.
74 | * The System.out is used as the standard output stream (stdout) and System.err is used as the error stream(stderr).
75 | * @param rf An instance of the RFactory class that has been initialized.
76 | * @param device An integer representing the R Device to be used
RGraphics.BMP
RGraphics.JAVA2R
RGraphics.JPEG
RGraphics.PDF
RGraphics.PICTEX
RGraphics.PNG
RGraphics.POSTSCRIPT
RGraphics.TIFF
RGraphics.XFIG
77 | * @param file The filename to which the graphics operations will be saved after closing the device. Should be left as null or "" if the device used is RGraphics.JAVA2R.
78 | * @throws java.io.IOException Thrown if there is an error in redirecting the IO Streams.
79 | */
80 | public RGraphics(RFactory rf,int device,String file) throws IOException{
81 | this.rf=rf;
82 | rb=new RBase(rf,System.out,System.err,RBase.VERY_QUIET);
83 | this.device=device;
84 | if(device==0)
85 | rb.execute("postscript(\""+file.replace(File.separator,"/")+"\")");
86 | else if(device==1)
87 | rb.execute("pdf(\""+file.replace(File.separator,"/")+"\")");
88 | else if(device==2)
89 | rb.execute("pictex(\""+file.replace(File.separator,"/")+"\")");
90 | else if(device==3)
91 | rb.execute("png(\""+file.replace(File.separator,"/")+"\")");
92 | else if(device==4)
93 | rb.execute("jpeg(\""+file.replace(File.separator,"/")+"\")");
94 | else if(device==5)
95 | rb.execute("bmp(\""+file.replace(File.separator,"/")+"\")");
96 | else if(device==6)
97 | rb.execute("xfig(\""+file.replace(File.separator,"/")+"\")");
98 | else if(device==7)
99 | rb.execute("tiff(\""+file.replace(File.separator,"/")+"\")");
100 | else if(device==8){
101 | rb.execute("jpeg(\""+rf.getSesnDir()+"/tmp.jpeg".replace(File.separator,"/")+"\")");
102 | }
103 | }
104 |
105 | /**
106 | * This command executes the command in R. This should preferably be a command that performs a graphicsl operation.
107 | * @param cmd The command exactly in the same form as R
108 | */
109 | public void execute(String cmd){
110 | rb.execute(cmd);
111 | }
112 |
113 | /**
114 | * This closes the current R Device.
115 | * The graphics operations are saved in the target file. If the current device is RGraphics.JAVA2R then a window containing the graphics is displayed.
116 | * @param title The title of the window that will be displayed if the Graphics Device is RGraphics.JAVA2R. It has no effect on other Graphics Devices in which case it may be left as null or "".
117 | */
118 | public void close(String title){
119 | rb.execute("dev.off()");
120 | rb.finalize();
121 | while(new File(rf.getSesnDir()+"/tmp.jpeg").exists()==false);
122 | if(device==8){
123 | JFrame jf=new JFrame(title);
124 | jf.setSize(480,480);
125 | ImageIcon i=new ImageIcon(rf.getSesnDir()+"/tmp.jpeg");
126 | JLabel jl=new JLabel(i);
127 | jf.add(jl);
128 | jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
129 | jf.setResizable(false);
130 | jf.setVisible(true);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/javadoc/sngforge/java2r/class-use/RGraphics.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Uses of Class sngforge.java2r.RGraphics
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/source/src/sngforge/java2r/RParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Java2R: A library to connect Java and R
3 | * Copyright (C) 2009 Sankha Narayan Guria
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package sngforge.java2r;
20 |
21 | import java.io.*;
22 |
23 | /**
24 | * This class parses R commands by converting them to a script.
25 | * The command to be executed can be passed as a String and multiple lines can be entered by using the newline character. The workspace image is saved and is automatically retrieved during the next operation. The results can obtained as a String or it may be dumped into an OutputStream.
26 | * @author Sankha Narayan Guria
27 | * @version 1.0
28 | */
29 | public class RParser {
30 |
31 | private RFactory rf;
32 |
33 | /**
34 | * This creates an object of this class.
35 | * @param rf A RFactory object that has already been initialized.
36 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
37 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
38 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
39 | */
40 | public RParser(RFactory rf) throws IOException, InterruptedException, RException{
41 | this.rf=rf;
42 | createBlankImage();
43 | }
44 |
45 | /**
46 | * This evaluates the R command(s) by executing it as a script.
47 | * The last saved or the default workspace image is retrieved and after execution it is again temporarily stored. Multple commnad can be separated by the newline character.
48 | * @param cmd The command(s) to be executed.
49 | * @return The results are returned as a String.
50 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
51 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
52 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
53 | */
54 | public String eval(String cmd)throws IOException, InterruptedException, RException{
55 | FileWriter code=new FileWriter(rf.getSesnDir()+"/tmp.R");
56 | code.write("attach(\""+rf.getSesnDir().replace(File.separator, "/")+"/tmp.RData\")\n");
57 | code.write(cmd+"\n");
58 | code.write("save.image(file=\""+rf.getSesnDir().replace(File.separator,"/")+"/tmp.RData\")\n");
59 | code.write("q(save = \"no\", status = 0, runLast = FALSE)");
60 | code.close();
61 | Process r=Runtime.getRuntime().exec(rf.getRexec()+" CMD BATCH --slave \""+rf.getSesnDir()+"/tmp.R\"");
62 | int i=r.waitFor();
63 | if(i!=0)
64 | throw new RException("Unspecified Error Occured!");
65 | FileReader fr=new FileReader(rf.getSesnDir()+"/tmp.Rout");
66 | BufferedReader br=new BufferedReader(fr);
67 | String out="", line="";
68 | while((line=br.readLine())!=null)
69 | out=out+line+"\n";
70 | fr.close();
71 | return out;
72 | }
73 | private void createBlankImage()throws IOException, InterruptedException, RException{
74 | FileWriter code=new FileWriter(rf.getSesnDir()+"/tmp.R");
75 | code.write("save.image(file=\""+rf.getSesnDir().replace(File.separator, "/")+"/tmp.RData\")");
76 | code.close();
77 | Process r=Runtime.getRuntime().exec(rf.getRexec()+" CMD BATCH \""+rf.getSesnDir()+"/tmp.R\"");
78 | int i=r.waitFor();
79 | if(i!=0)
80 | throw new RException("Unspecified Error Occured!");
81 | }
82 |
83 | /**
84 | * This evaluates the R command(s) by executing it as a script.
85 | * The last saved or the default workspace image is retrieved and after execution it is again temporarily stored. Multple commnad can be separated by the newline character.
86 | * @param cmd The command(s) to be executed.
87 | * @param out The OutputStream in which the results will be dumped.
88 | * @param close A boolean value specifying whether the OutputStream should be closed or not. It is useful when the OutputStream is writing to a file.
89 | * @throws java.io.IOException Thrown if there is an error while performing IO Operations.
90 | * @throws java.lang.InterruptedException Thrown if R is interrpted during execution.
91 | * @throws nr.co.sngforge.java2r.RException Thrown if there is any other error.
92 | */
93 | public void eval(String cmd, OutputStream out, boolean close)throws IOException, InterruptedException, RException{
94 | FileWriter code=new FileWriter(rf.getSesnDir()+"/tmp.R");
95 | code.write("attach(\""+rf.getSesnDir().replace(File.separator, "/")+"/tmp.RData\")\n");
96 | code.write(cmd+"\n");
97 | code.write("save.image(file=\""+rf.getSesnDir().replace(File.separator,"/")+"/tmp.RData\")\n");
98 | code.write("q(save = \"no\",, runLast = FALSE)");
99 | code.close();
100 | Process r=Runtime.getRuntime().exec(rf.getRexec()+" CMD BATCH --slave \""+rf.getSesnDir()+"/tmp.R\"");
101 | int i=r.waitFor();
102 | if(i!=0)
103 | throw new RException("Unspecified Error Occured!");
104 | FileReader fr=new FileReader(rf.getSesnDir()+"/tmp.Rout");
105 | BufferedReader br=new BufferedReader(fr);
106 | PrintStream printStream = new PrintStream(out);
107 | String line="";
108 | while((line=br.readLine())!=null)
109 | printStream.println(line);
110 | fr.close();
111 | if(close)
112 | out.close();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/javadoc/nr/co/sngforge/java2r/class-use/RBase.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Uses of Class nr.co.sngforge.java2r.RBase
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |