Nuiton-j2r-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
April 2009
- 2 participants
- 17 discussions
[LutinJ2R-commits] r70 - in lutinj2r/trunk/src: main/java/org/codelutin/j2r main/java/org/codelutin/j2r/types test/java/org/codelutin/j2r
by jcouteau@users.labs.libre-entreprise.org 30 Apr '09
by jcouteau@users.labs.libre-entreprise.org 30 Apr '09
30 Apr '09
Author: jcouteau
Date: 2009-04-30 12:10:02 +0000 (Thu, 30 Apr 2009)
New Revision: 70
Added:
lutinj2r/trunk/src/main/java/org/codelutin/j2r/types/
lutinj2r/trunk/src/main/java/org/codelutin/j2r/types/RDataFrame.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/DataframeTest.java
Log:
Adding data.frame data type + tests.
Added: lutinj2r/trunk/src/main/java/org/codelutin/j2r/types/RDataFrame.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/types/RDataFrame.java (rev 0)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/types/RDataFrame.java 2009-04-30 12:10:02 UTC (rev 70)
@@ -0,0 +1,254 @@
+package org.codelutin.j2r.types;
+
+import java.io.Serializable;
+import java.util.Vector;
+
+import org.codelutin.j2r.REngine;
+import org.codelutin.j2r.RException;
+
+public class RDataFrame {
+
+ private Vector<String> names;
+ private Vector<String> rowNames;
+ private Vector<Vector<? extends Serializable>> data;
+ private String variable;
+
+ public RDataFrame() {
+ super();
+ this.names = new Vector<String>();
+ this.rowNames = new Vector<String>();
+ this.data = new Vector<Vector<? extends Serializable>>();
+ this.variable = "";
+ }
+
+ public RDataFrame(Vector<String> names, Vector<String> rowNames,
+ Vector<Vector<? extends Serializable>> data, REngine engine,
+ String variable) throws RException {
+ super();
+ this.names = names;
+ this.rowNames = rowNames;
+ this.data = (Vector<Vector<? extends Serializable>>) data;
+ this.variable = variable;
+ assignTo(variable, engine);
+ }
+
+ /**
+ * Method to get the names of the vectors of the R data.frame (there is no
+ * synchronizing with R, use the synchro() method to synchronize data with R
+ * before using this method if you think data may have changed.
+ *
+ * @return a vector of strings containing the names of each vector of the R
+ * data.frame
+ */
+ public Vector<String> getNames() {
+ return names;
+ }
+
+ /**
+ * Method to assign names of the vectors of the R data.frame (the names will
+ * then be synchronized with R)
+ *
+ * @param names
+ * a vector containing the names of the vector of the R
+ * data.frame
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void setNames(Vector<String> names, REngine engine)
+ throws RException {
+ this.names = names;
+ assignNames(engine);
+ }
+
+ /**
+ * Method to get the names of the rows of the R data.frame (there is no
+ * synchronizing with R, use the synchro() method to synchronize data with R
+ * before using this method if you think data may have changed.
+ *
+ * @return a vector of strings containing the names of each row of the R
+ * data.frame
+ */
+ public Vector<String> getRowNames() {
+ return rowNames;
+ }
+
+ /**
+ * Method to assign names of the rows of the R data.frame (the names will
+ * then be synchronized with R)
+ *
+ * @param rowNames
+ * a vector containing the names of the rows of the R data.frame
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void setRowNames(Vector<String> rowNames, REngine engine)
+ throws RException {
+ this.rowNames = rowNames;
+ assignRowNames(engine);
+ }
+
+ /**
+ * Method to get the vectors of the R data.frame (there is no synchronizing
+ * with R, use the synchro() method to synchronize data with R before using
+ * this method if you think data may have changed.
+ *
+ * @return a Vector containing the vectors of the R data.frame
+ */
+ public Vector<Vector<? extends Serializable>> getData() {
+ return data;
+ }
+
+ /**
+ * Method to assign the data of the R data.frame (the data will then be
+ * synchronized with R)
+ *
+ * @param data
+ * a Vector of Vectors, containing each vector of the R
+ * data.frame
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void setData(Vector<Vector<? extends Serializable>> data,
+ REngine engine) throws RException {
+ this.data = data;
+ assignData(engine);
+ }
+
+ /**
+ * Method to assign this data.frame to a variable in R.
+ *
+ * @param variable
+ * name of the variable
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void assignTo(String variable, REngine engine) throws RException {
+
+ this.variable = variable;
+ assignData(engine);
+ assignRowNames(engine);
+ assignNames(engine);
+
+ }
+
+ /**
+ * Method to get a data.frame from a variable in R.
+ *
+ * @param variable
+ * name of the data.frame in R
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void getFrom(String variable, REngine engine) throws RException {
+ this.variable = variable;
+ rowNames.clear();
+ names.clear();
+ data.clear();
+ String[] rowNamesArray = (String[]) engine.eval("row.names("
+ + this.variable + ")");
+ for (int i = 0; i < rowNamesArray.length; i++) {
+ rowNames.add(rowNamesArray[i]);
+ }
+ String[] namesArray = (String[]) engine.eval("names(" + this.variable
+ + ")");
+ for (int i = 0; i < namesArray.length; i++) {
+ names.add(namesArray[i]);
+ }
+
+ Integer dataframelength = (Integer) engine.eval("length("
+ + this.variable + ")");
+
+ for (int i = 0; i < dataframelength; i++) {
+ Integer vectorlength = (Integer) engine.eval("length("
+ + this.variable + "[," + (i + 1) + "])");
+ Vector<Serializable> thisColumn = new Vector<Serializable>();
+ for (int j = 0; j < vectorlength; j++) {
+ thisColumn.add((Serializable) engine.eval(this.variable + "["
+ + (i + 1) + "," + (j + 1) + "]"));
+ }
+ data.add(thisColumn);
+ }
+
+ }
+
+ /**
+ * Synchronization with R method. This method updates the content of the
+ * data.frame from R. All local changes are lost.
+ *
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ public void check(REngine engine) throws RException {
+ getFrom(variable, engine);
+ }
+
+ /**
+ * Send names changes to R
+ *
+ * @param engine
+ * @throws RException
+ */
+ private void assignNames(REngine engine) throws RException {
+ String vectorNames = "names(" + this.variable + ")<-c(";
+ for (int i = 0; i < names.size(); i++) {
+ vectorNames = vectorNames + "\"" + names.get(i) + "\"" + ",";
+ }
+ vectorNames = vectorNames.substring(0, vectorNames.length() - 1) + ")";
+ engine.voidEval(vectorNames);
+ }
+
+ /**
+ * Send row names changes to R
+ *
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ private void assignRowNames(REngine engine) throws RException {
+ String vectorRowNames = "row.names(" + this.variable + ")<-c(";
+ for (int i = 0; i < rowNames.size(); i++) {
+ vectorRowNames = vectorRowNames + "\"" + rowNames.get(i) + "\""
+ + ",";
+ }
+ vectorRowNames = vectorRowNames.substring(0,
+ vectorRowNames.length() - 1)
+ + ")";
+ engine.voidEval(vectorRowNames);
+ }
+
+ /**
+ * Send data changes to R
+ *
+ * @param engine
+ * a REngine where the R session is located.
+ * @throws RException
+ */
+ private void assignData(REngine engine) throws RException {
+ String dataframe = variable + "<-data.frame(";
+ for (int i = 0; i < data.size(); i++) {
+ dataframe = dataframe + "data" + i + ",";
+ String datai = "data" + i + "<-c(";
+ for (int j = 0; j < data.get(i).size(); j++) {
+ datai = datai + data.get(i).get(j) + ",";
+ }
+ datai = datai.substring(0, datai.length() - 1) + ")";
+ engine.voidEval(datai);
+
+ }
+ dataframe = dataframe.substring(0, dataframe.length() - 1) + ")";
+ engine.voidEval(dataframe);
+ }
+
+ //TODO method set attributes, get attributes
+
+ //TODO method add attribute, remove attribute
+
+ //TODO check data consistency.
+
+}
Added: lutinj2r/trunk/src/test/java/org/codelutin/j2r/DataframeTest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/DataframeTest.java (rev 0)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/DataframeTest.java 2009-04-30 12:10:02 UTC (rev 70)
@@ -0,0 +1,158 @@
+/* *##% Lutin Java-2-R library
+ * Copyright (C) 2006 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.j2r;
+
+import java.io.Serializable;
+import java.util.Vector;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.j2r.types.RDataFrame;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DataframeTest {
+
+ private static Log log = LogFactory.getLog(DataframeTest.class);
+
+ private REngine engine;
+
+ @Before
+ public void setUp() throws Exception {
+ LutinTimer init = new LutinTimer();
+ init.startTiming();
+ if (engine == null) {
+ engine = new RProxy();
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ engine.terminate();
+ }
+
+ @Test
+ public void testDataFrameCreation() throws Exception {
+ //This test is also a test for all the setters...
+ //they work the same way and use the same internal methods.
+ Vector<String> names = new Vector<String>();
+ names.add("column1");
+ names.add("column2");
+
+ Vector<String> rowNames = new Vector<String>();
+ rowNames.add("row 1");
+ rowNames.add("row 2");
+ rowNames.add("row 3");
+
+ Vector<Double> column1 = new Vector<Double>();
+ column1.add(3.0);
+ column1.add(4.5);
+ column1.add(0.01);
+
+ Vector<Double> column2 = new Vector<Double>();
+ column2.add(1.0);
+ column2.add(5555555555555555555555.0);
+ column2.add(3.0);
+
+ Vector<Vector<? extends Serializable>> data = new Vector<Vector<? extends Serializable>>();
+ data.add(column1);
+ data.add(column2);
+
+ RDataFrame testDataFrame = new RDataFrame(names, rowNames, data,
+ engine, "test");
+ //Test data
+ Assert.assertEquals(new Double(3.0), (Double) engine.eval("test[1,1]"));
+ Assert.assertEquals(new Double(4.5), (Double) engine.eval("test[2,1]"));
+ Assert
+ .assertEquals(new Double(0.01), (Double) engine
+ .eval("test[3,1]"));
+ Assert.assertEquals(new Double(1.0), (Double) engine.eval("test[1,2]"));
+ Assert.assertEquals(new Double(5555555555555555555555.0),
+ (Double) engine.eval("test[2,2]"));
+ Assert.assertEquals(new Double(3.0), (Double) engine.eval("test[3,2]"));
+ //Test names
+ Assert.assertEquals("column1", (String) engine.eval("names(test)[1]"));
+ Assert.assertEquals("column2", (String) engine.eval("names(test)[2]"));
+ //Test row names
+ Assert
+ .assertEquals("row 1", (String) engine
+ .eval("row.names(test)[1]"));
+ Assert
+ .assertEquals("row 2", (String) engine
+ .eval("row.names(test)[2]"));
+ Assert
+ .assertEquals("row 3", (String) engine
+ .eval("row.names(test)[3]"));
+ }
+
+ @Test
+ public void testGetDataFrame() throws Exception {
+ //This test is also a test for all the setters...
+ //they work the same way and use the same internal methods.
+ Vector<String> names = new Vector<String>();
+ names.add("column1");
+ names.add("column2");
+
+ Vector<String> rowNames = new Vector<String>();
+ rowNames.add("row 1");
+ rowNames.add("row 2");
+ rowNames.add("row 3");
+
+ Vector<Double> column1 = new Vector<Double>();
+ column1.add(3.0);
+ column1.add(4.5);
+ column1.add(0.01);
+
+ Vector<Double> column2 = new Vector<Double>();
+ column2.add(1.0);
+ column2.add(5555555555555555555555.0);
+ column2.add(3.0);
+
+ Vector<Vector<? extends Serializable>> data = new Vector<Vector<? extends Serializable>>();
+ data.add(column1);
+ data.add(column2);
+
+ RDataFrame testDataFrame = new RDataFrame(names, rowNames, data,
+ engine, "test");
+ RDataFrame dataframe2 = new RDataFrame();
+ dataframe2.getFrom("test", engine);
+ //Test data
+ Assert.assertEquals(new Double(3.0), (Double) engine.eval("test[1,1]"));
+ Assert.assertEquals(new Double(4.5), (Double) engine.eval("test[2,1]"));
+ Assert
+ .assertEquals(new Double(0.01), (Double) engine
+ .eval("test[3,1]"));
+ Assert.assertEquals(new Double(1.0), (Double) engine.eval("test[1,2]"));
+ Assert.assertEquals(new Double(5555555555555555555555.0),
+ (Double) engine.eval("test[2,2]"));
+ Assert.assertEquals(new Double(3.0), (Double) engine.eval("test[3,2]"));
+ //Test names
+ Assert.assertEquals("column1", dataframe2.getNames().get(0));
+ Assert.assertEquals("column2", dataframe2.getNames().get(1));
+ //Test row names
+ Assert
+ .assertEquals("row 1", dataframe2.getRowNames().get(0));
+ Assert
+ .assertEquals("row 2", dataframe2.getRowNames().get(1));
+ Assert
+ .assertEquals("row 3", dataframe2.getRowNames().get(2));
+ }
+
+}
1
0
[LutinJ2R-commits] r69 - in lutinj2r/trunk/src: main/java/org/codelutin/j2r main/java/org/codelutin/j2r/jni main/java/org/codelutin/j2r/net test/java/org/codelutin/j2r
by jcouteau@users.labs.libre-entreprise.org 29 Apr '09
by jcouteau@users.labs.libre-entreprise.org 29 Apr '09
29 Apr '09
Author: jcouteau
Date: 2009-04-29 14:43:55 +0000 (Wed, 29 Apr 2009)
New Revision: 69
Modified:
lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
Log:
Adding copy, move, list all objects and clear session capability
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -30,6 +30,7 @@
package org.codelutin.j2r;
import java.io.File;
+import java.util.List;
/**
* Cette interface est le point commun entre les differentes technologies
@@ -37,114 +38,171 @@
*/
public interface REngine {
- /**
+ /**
* Effectue l'initialisation du moteur. Les parametres sont passes par les
* options de JVM, -D...
- * @return true/false pour indiquer si l'initialisation a pu se faire sans
- * encombre
- */
- public boolean init();
+ *
+ * @return true/false pour indiquer si l'initialisation a pu se faire sans
+ * encombre
+ */
+ public boolean init();
- /**
- * Delegue a R le traitement passe en parametre.
- * @param expr l'expression a evaluer
- * @return La valeur renvoyee par la commande
- * @throws RException
- */
- public Object eval(String expr) throws RException;
+ /**
+ * Delegue a R le traitement passe en parametre.
+ *
+ * @param expr
+ * l'expression a evaluer
+ * @return La valeur renvoyee par la commande
+ * @throws RException
+ */
+ public Object eval(String expr) throws RException;
/**
* Effectue un eval mais sans retour de resultat. Quand c'est possible cela
* permet donc de na pas consommer du temps de transfert et conversion de R
* a Java.
- * @param expr l'expression a evaluer
- * @throws RException
+ *
+ * @param expr
+ * l'expression a evaluer
+ * @throws RException
*/
public void voidEval(String expr) throws RException;
- /**
+ /**
* Met fin a l'utilisation de l'engine
- * @throws RException
- */
- public void terminate() throws RException;
-
- /**
+ *
+ * @throws RException
+ */
+ public void terminate() throws RException;
+
+ /**
* Load .RData file located in directory
*
- * @param directory directory where the .RData file is located
+ * @param directory
+ * directory where the .RData file is located
* @throws RException
*/
- public void loadRData(File directory) throws RException;
-
+ public void loadRData(File directory) throws RException;
+
/**
* Save the session in a .RData file in directory
*
- * @param directory where the .RData file will be saved
+ * @param directory
+ * where the .RData file will be saved
* @throws RException
*/
public void saveRData(File directory) throws RException;
-
+
/**
* Set the R working directory
- * @param directory to set
+ *
+ * @param directory
+ * to set
* @throws RException
*/
public void setwd(File directory) throws RException;
-
+
/**
* Get the actual R session working directory
*
* @return a File that is the actual R session working directory
* @throws RException
*/
-
+
public File getwd() throws RException;
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
* The file created will be in the working directory
*
- * @param rObject name of the R object to save
- * @param outputFileName name of the file to save
+ * @param rObject
+ * name of the R object to save
+ * @param outputFileName
+ * name of the file to save
* @throws RException
*/
public void dput(String rObject, String outputFileName) throws RException;
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
- * The file used have to be in the working directory
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object. The file used have to be in the
+ * working directory
*
- * @param rObject name of the R object created
- * @param inputFileName name of the file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFileName
+ * name of the file to load
* @throws RException
*/
public void dget(String rObject, String inputFileName) throws RException;
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
*
- * @param rObject R object to save
- * @param outputFileName the file to save
+ * @param rObject
+ * R object to save
+ * @param outputFileName
+ * the file to save
* @throws RException
*/
public void dput(String rObject, File outputFile) throws RException;
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object.
*
- * @param rObject name of the R object created
- * @param inputFile file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFile
+ * file to load
* @throws RException
*/
public void dget(String rObject, File inputFile) throws RException;
-
+
/**
* Remove a R object from the actual session
- * @param rObject to be removed from the session
+ *
+ * @param rObject
+ * to be removed from the session
* @throws RException
*/
- public void remove (String rObject) throws RException;
+ public void remove(String rObject) throws RException;
+ /**
+ * Make a copy of an object and remove the old one.
+ *
+ * @param inputObject
+ * the object to be copied and deleted
+ * @param outputObject
+ * the object to be created
+ * @throws RException
+ */
+ public void mv(String inputObject, String outputObject) throws RException;
+
+ /**
+ * Copy an object.
+ *
+ * @param inputObject
+ * the object to be copied
+ * @param outputObject
+ * the object to be created
+ * @throws RException
+ */
+ public void cp(String inputObject, String outputObject) throws RException;
+
+ /**
+ * List all R object present in the actual session
+ *
+ * @return a list containing the name of all the R objects in the R session.
+ * @throws RException
+ */
+ public String[] ls() throws RException;
+
+ /**
+ * Remove all the objects present in the actual R session.
+ *
+ * @throws RException
+ */
+ public void clearSession() throws RException;
+
} //RJniEngine
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -41,21 +41,21 @@
* l'implatation choisie. La detection est basee sur l'option de demarrage de la
* JVM :
* <ul>
- * <li><code>-DR.type=net</code></li>
- * <li><code>-DR.type=jni</code></li>
- * <li><code>-DR.type=...</code></li>
+ * <li><code>-DR.type=net</code></li>
+ * <li><code>-DR.type=jni</code></li>
+ * <li><code>-DR.type=...</code></li>
* </ul>
* Il est possible de parametrer la solution network, pour cela, voir la
* documentation de {@link org.codelutin.j2r.net.RNetEngine}
*/
public class RProxy implements REngine {
- private Log log = LogFactory.getLog(RProxy.class);
+ private Log log = LogFactory.getLog(RProxy.class);
- private REngine engine;
+ private REngine engine;
public RProxy() {
- init();
+ init();
}
private boolean init(String RType) {
@@ -64,255 +64,312 @@
RType = "net";
}
if (RType.startsWith("net")) {
- initSucceded = initOnNet();
- if (!initSucceded) {
- if (log.isErrorEnabled()) {
- log.error("Initialization of R with Network failed, trying JNI");
- }
- initSucceded = initOnJNI();
- }
+ initSucceded = initOnNet();
+ if (!initSucceded) {
+ if (log.isErrorEnabled()) {
+ log
+ .error("Initialization of R with Network failed, trying JNI");
+ }
+ initSucceded = initOnJNI();
+ }
} else if ("jni".equalsIgnoreCase(RType)) {
- initSucceded = initOnJNI();
- if (!initSucceded) {
- if (log.isErrorEnabled()) {
- log.error("Initialization of R over JNI failed, trying with Network");
- }
- initSucceded = initOnNet();
- }
+ initSucceded = initOnJNI();
+ if (!initSucceded) {
+ if (log.isErrorEnabled()) {
+ log
+ .error("Initialization of R over JNI failed, trying with Network");
+ }
+ initSucceded = initOnNet();
+ }
} else if (log.isErrorEnabled()) {
- log.error("Invalid type specified : " + RType);
+ log.error("Invalid type specified : " + RType);
}
return initSucceded;
}
private boolean initOnJNI() {
- if (log.isInfoEnabled()) {
- log.info("Trying to initialize the R Proxy over JNI");
- }
- RJniEngine newEngine = new RJniEngine();
- if (newEngine.init()) {
- engine = newEngine;
- return true;
- }
- return false;
+ if (log.isInfoEnabled()) {
+ log.info("Trying to initialize the R Proxy over JNI");
+ }
+ RJniEngine newEngine = new RJniEngine();
+ if (newEngine.init()) {
+ engine = newEngine;
+ return true;
+ }
+ return false;
}
private boolean initOnNet() {
- if (log.isInfoEnabled()) {
- log.info("Trying to initialize the R Proxy with Network");
- }
- RNetEngine newEngine = new RNetEngine();
- if (newEngine.init()) {
- engine = newEngine;
- return true;
- }
- return false;
+ if (log.isInfoEnabled()) {
+ log.info("Trying to initialize the R Proxy with Network");
+ }
+ RNetEngine newEngine = new RNetEngine();
+ if (newEngine.init()) {
+ engine = newEngine;
+ return true;
+ }
+ return false;
}
- /* (non-Javadoc)
- * @see org.codelutin.R.REngine#eval(java.lang.String)
- */
- public Object eval(String expr) throws RException {
- if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
- return null;
- }
- return engine.eval(expr);
- }
+ /* (non-Javadoc)
+ * @see org.codelutin.R.REngine#eval(java.lang.String)
+ */
+ public Object eval(String expr) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ return null;
+ }
+ return engine.eval(expr);
+ }
- /* (non-Javadoc)
- * @see org.codelutin.j2r.REngine#init()
- */
- public boolean init() {
+ /* (non-Javadoc)
+ * @see org.codelutin.j2r.REngine#init()
+ */
+ public boolean init() {
String RType = System.getProperty("R.type");
if (RType == null || "".equals(RType)) {
- log.warn("No R type specified.\nusage:\n\tjava -DR.type=net ...\n" +
- "or\n\tjava -DR.type=jni ...\n\nConsidering network type");
- RType = "net";
+ log
+ .warn("No R type specified.\nusage:\n\tjava -DR.type=net ...\n"
+ + "or\n\tjava -DR.type=jni ...\n\nConsidering network type");
+ RType = "net";
}
if (!init(RType)) {
- if (log.isFatalEnabled()) {
- log.fatal("The initializing of R failed.");
- }
- return false;
+ if (log.isFatalEnabled()) {
+ log.fatal("The initializing of R failed.");
+ }
+ return false;
}
- return true;
- }
+ return true;
+ }
- /* (non-Javadoc)
- * @see org.codelutin.j2r.REngine#terminate()
- */
- public void terminate() throws RException {
- if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
- } else {
- engine.terminate();
- }
- }
+ /* (non-Javadoc)
+ * @see org.codelutin.j2r.REngine#terminate()
+ */
+ public void terminate() throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ } else {
+ engine.terminate();
+ }
+ }
/* (non-Javadoc)
* @see org.codelutin.j2r.REngine#voidEval(java.lang.String)
*/
public void voidEval(String expr) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
engine.voidEval(expr);
}
-
+
/**
* Load .RData file located in directory
*
- * @param directory directory where the .RData file is located
+ * @param directory
+ * directory where the .RData file is located
* @throws RException
*/
public void loadRData(File directory) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
engine.setwd(directory);
engine.voidEval("load(\".RData\")");
}
-
+
/**
* Save the session in a .RData file in directory
*
- * @param directory where the .RData file will be saved
+ * @param directory
+ * where the .RData file will be saved
* @throws RException
*/
- public void saveRData(File directory) throws RException{
+ public void saveRData(File directory) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
engine.setwd(directory);
engine.voidEval("save.image()");
}
-
+
/**
* Set the R working directory
- * @param directory to set
+ *
+ * @param directory
+ * to set
* @throws RException
*/
public void setwd(File directory) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
- engine.voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
+ engine.voidEval("setwd(\"" + directory.getAbsolutePath() + "\")");
}
-
+
/**
* Get the actual R session working directory
*
- * @return a File that is the actual R session working directory, null if the engine is not initialized
+ * @return a File that is the actual R session working directory, null if
+ * the engine is not initialized
* @throws RException
*/
-
+
public File getwd() throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return null;
}
- String directory = (String)engine.eval("getwd()");
+ String directory = (String) engine.eval("getwd()");
return new File(directory);
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
* The file created will be in the working directory
*
- * @param rObject name of the R object to save
- * @param outputFileName name of the file to save
+ * @param rObject
+ * name of the R object to save
+ * @param outputFileName
+ * name of the file to save
* @throws RException
*/
public void dput(String rObject, String outputFileName) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
String rInstruction = "dput(%s,file=\"%s\")";
engine.voidEval(String.format(rInstruction, rObject, outputFileName));
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
- * The file used have to be in the working directory
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object. The file used have to be in the
+ * working directory
*
- * @param rObject name of the R object created
- * @param inputFileName name of the file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFileName
+ * name of the file to load
* @throws RException
*/
public void dget(String rObject, String inputFileName) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
String rInstruction = "%s <- dget(\"%s\")";
engine.voidEval(String.format(rInstruction, rObject, inputFileName));
-
+
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
*
- * @param rObject R object to save
- * @param outputFileName the file to save
+ * @param rObject
+ * R object to save
+ * @param outputFileName
+ * the file to save
* @throws RException
*/
public void dput(String rObject, File outputFile) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
File workingdir = getwd();
engine.setwd(outputFile.getParentFile());
String rInstruction = "dput(%s,file=\"%s\")";
- engine.voidEval(String.format(rInstruction, rObject, outputFile.getName()));
+ engine.voidEval(String.format(rInstruction, rObject, outputFile
+ .getName()));
setwd(workingdir);
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object.
*
- * @param rObject name of the R object created
- * @param inputFile file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFile
+ * file to load
* @throws RException
*/
public void dget(String rObject, File inputFile) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
File workingdir = getwd();
engine.setwd(inputFile.getParentFile());
String rInstruction = "%s <- dget(\"%s\")";
- engine.voidEval(String.format(rInstruction, rObject, inputFile.getName()));
- setwd(workingdir);
+ engine.voidEval(String.format(rInstruction, rObject, inputFile
+ .getName()));
+ setwd(workingdir);
}
-
+
public void remove(String rObject) throws RException {
if (engine == null) {
- log.fatal("The R Proxy is not initialized. An error probably " +
- "occured during the initialization.");
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
return;
}
engine.remove(rObject);
}
+ public void mv(String inputObject, String outputObject) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ return;
+ }
+ engine.mv(inputObject, outputObject);
+
+ }
+
+ public void cp(String inputObject, String outputObject) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ return;
+ }
+ engine.cp(inputObject, outputObject);
+
+ }
+
+ public String[] ls() throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ return null;
+ }
+ return engine.ls();
+ }
+
+ public void clearSession() throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably "
+ + "occured during the initialization.");
+ return;
+ }
+ engine.clearSession();
+
+ }
+
} //RProxy
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -78,7 +78,7 @@
public Object eval(String expr) throws RException {
REXP result = null;
try {
- log.info(expr);
+ log.debug(expr);
result = engine.eval(expr);
} catch (Exception eee) {
throw new RException("Unable to evaluate the R expression "
@@ -102,7 +102,7 @@
result = rexp.asString();
break;
case REXP.XT_INT:
- result = (Integer)rexp.asInt();
+ result = (Integer) rexp.asInt();
break;
case REXP.XT_ARRAY_INT:
result = rexp.asIntArray();
@@ -120,7 +120,6 @@
break;
case REXP.XT_BOOL:
result = rexp.asBool().isTRUE();
- log.info(result);
break;
case REXP.XT_DOUBLE:
result = rexp.asDoubleArray();
@@ -151,6 +150,9 @@
case REXP.XT_VECTOR:
result = rexp.asVector();
break;
+ case 34:
+ result = rexp.asStringArray();
+ break;
default:
log.error("Unknown return type [" + type + "] " + "on : "
+ rexp.toString());
@@ -179,7 +181,6 @@
// voidEval is not really supproted by JRI, we just discard the result
// conversion
try {
- log.info(expr);
engine.eval(expr);
} catch (Exception eee) {
throw new RException("An error occured while voidEval on JNI", eee);
@@ -304,4 +305,28 @@
voidEval("remove(" + rObject + ")");
}
+ public void mv(String inputObject, String outputObject) throws RException {
+ cp(inputObject, outputObject);
+ remove(inputObject);
+
+ }
+
+ public void cp(String inputObject, String outputObject) throws RException {
+ voidEval(outputObject + "<-" + inputObject);
+
+ }
+
+ public String[] ls() throws RException {
+ String[] Robjects = (String[]) eval("ls()");
+ return Robjects;
+ }
+
+ public void clearSession() throws RException {
+ String[] Robjects = ls();
+ for (int i = 0; i < Robjects.length; i++) {
+ remove(Robjects[i]);
+ }
+
+ }
+
} // RJniEngine
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -30,6 +30,7 @@
package org.codelutin.j2r.net;
import java.io.File;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,7 +41,6 @@
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
-
/**
* Cette classe represente le moteur reseau pour acceder a R. Par defaut, il
* essaye de se connecter a l'adresse 127.0.0.1 sur le port 6311. Cependant, il
@@ -53,252 +53,262 @@
*/
public class RNetEngine implements REngine {
- public static final int DEFAULT_PORT = 6311;
- public static final String DEFAULT_HOST = "127.0.0.1";
+ public static final int DEFAULT_PORT = 6311;
+ public static final String DEFAULT_HOST = "127.0.0.1";
- private Log log = LogFactory.getLog(RNetEngine.class);
+ private Log log = LogFactory.getLog(RNetEngine.class);
- private RConnection conn;
+ private RConnection conn;
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#init()
- */
- public boolean init() {
- String typeProp = System.getProperty("R.type", "net");
- int urlPos = typeProp.indexOf("net://");
- String host = null;
- String portAsString = null;
- if (urlPos != -1) {
- String url = typeProp.substring(urlPos + 6);
- int commaPos = url.indexOf(":");
- if (commaPos != -1) {
- host = url.substring(0, commaPos);
- portAsString = url.substring(commaPos + 1);
- } else {
- host = url;
- }
- }
- if (host == null || "".equals(host)) {
- host = DEFAULT_HOST;
- }
- int port = DEFAULT_PORT;
- if (portAsString != null) {
- try {
- port = Integer.parseInt(portAsString);
- } catch (NumberFormatException nfe) {
- if (log.isWarnEnabled()) {
- log.warn("Bad port format " + portAsString
- + ", using default" + " port : " + port);
- }
- }
- }
- return init(host, port);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#init()
+ */
+ public boolean init() {
+ String typeProp = System.getProperty("R.type", "net");
+ int urlPos = typeProp.indexOf("net://");
+ String host = null;
+ String portAsString = null;
+ if (urlPos != -1) {
+ String url = typeProp.substring(urlPos + 6);
+ int commaPos = url.indexOf(":");
+ if (commaPos != -1) {
+ host = url.substring(0, commaPos);
+ portAsString = url.substring(commaPos + 1);
+ } else {
+ host = url;
+ }
+ }
+ if (host == null || "".equals(host)) {
+ host = DEFAULT_HOST;
+ }
+ int port = DEFAULT_PORT;
+ if (portAsString != null) {
+ try {
+ port = Integer.parseInt(portAsString);
+ } catch (NumberFormatException nfe) {
+ if (log.isWarnEnabled()) {
+ log.warn("Bad port format " + portAsString
+ + ", using default" + " port : " + port);
+ }
+ }
+ }
+ return init(host, port);
+ }
- public boolean init(String host, int port) {
- if (log.isInfoEnabled()) {
- log.info("Trying to connect to the Rserve on '" + host + ":" + port
- + "'");
- }
- try {
- conn = new RConnection(host, port);
- } catch (RserveException e) {
- log.error("Unable to establish a connection to the R server. "
- + "Maybe you forgot to start it. "
- + "Try using the command \"R CMD Rserve\".");
- e.printStackTrace();
- return false;
- }
- return conn.isConnected();
- }
+ public boolean init(String host, int port) {
+ if (log.isInfoEnabled()) {
+ log.info("Trying to connect to the Rserve on '" + host + ":" + port
+ + "'");
+ }
+ try {
+ conn = new RConnection(host, port);
+ } catch (RserveException e) {
+ log.error("Unable to establish a connection to the R server. "
+ + "Maybe you forgot to start it. "
+ + "Try using the command \"R CMD Rserve\".");
+ e.printStackTrace();
+ return false;
+ }
+ return conn.isConnected();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.R.REngine#eval(java.lang.String)
- */
- public Object eval(String expr) throws RException {
- REXP result = null;
- try {
- log.info(expr);
- result = conn.eval(expr);
- } catch (RserveException e) {
- throw new RException("An error occured during the eval method", e);
- }
- return convertResult(result);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.R.REngine#eval(java.lang.String)
+ */
+ public Object eval(String expr) throws RException {
+ REXP result = null;
+ try {
+ log.debug(expr);
+ result = conn.eval(expr);
+ } catch (RserveException e) {
+ throw new RException("An error occured during the eval method", e);
+ }
+ return convertResult(result);
+ }
- private Object convertResult(REXP rexp) {
- if (rexp == null) {
- log.debug("Null returned");
- return null;
- }
- if (log.isDebugEnabled()) {
- log.debug("Converting : " + rexp.toString());
- }
+ private Object convertResult(REXP rexp) {
+ if (rexp == null) {
+ log.debug("Null returned");
+ return null;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Converting : " + rexp.toString());
+ }
- Object result = null;
+ Object result = null;
- try {
+ try {
- if (rexp.isInteger()) {
- result = rexp.asIntegers();
- int[] intarray = (int[]) result;
- if (intarray.length == 1) {
- result = intarray[0];
- }
- }
+ if (rexp.isInteger()) {
+ result = rexp.asIntegers();
+ int[] intarray = (int[]) result;
+ if (intarray.length == 1) {
+ result = intarray[0];
+ }
+ }
- else if (rexp.isFactor()) {
- result = rexp.asFactor();
- }
+ else if (rexp.isFactor()) {
+ result = rexp.asFactor();
+ }
- else if (rexp.isNumeric()) {
- result = rexp.asDoubles();
- double[] doublearray = (double[]) result;
- if (doublearray.length == 1) {
- result = doublearray[0];
- }
- }
-
- else if (rexp.isString()) {
- result = rexp.asStrings();
- String[] stringArray = (String[]) result;
- if (stringArray.length == 1) {
- result = stringArray[0];
- }
-
- }
-
- else if (rexp.isLogical()) {
- result = rexp.asStrings();
- String[] strings = ((String [])result);
- Boolean[] stringArray = new Boolean[strings.length];
- for (int i=0;i<((String [])result).length;i++){
- stringArray[i]=Boolean.parseBoolean(strings[i]);
- }
- if (stringArray.length == 1) {
- result = (Boolean)stringArray[0];
- }
- else {result = (Boolean[])stringArray;}
- }
-
- else if (rexp.isNull()) {
- return null;
- }
+ else if (rexp.isNumeric()) {
+ result = rexp.asDoubles();
+ double[] doublearray = (double[]) result;
+ if (doublearray.length == 1) {
+ result = doublearray[0];
+ }
+ }
- else {
- log.error("Unknown return type on : " + rexp.toString());
- }
- } catch (REXPMismatchException e) {
- e.printStackTrace();
- }
- return result;
- }
+ else if (rexp.isString()) {
+ result = rexp.asStrings();
+ String[] stringArray = (String[]) result;
+ if (stringArray.length == 1) {
+ result = stringArray[0];
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#terminate()
- */
- public void terminate() throws RException {
- if (conn != null && conn.isConnected()) {
- conn.close();
- }
- }
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#voidEval(java.lang.String)
- */
- public void voidEval(String expr) throws RException {
- try {
- log.info(expr);
- conn.voidEval(expr);
- } catch (RserveException rse) {
- throw new RException("An error occured while voidEval on net", rse);
- }
- }
-
- /**
+ else if (rexp.isLogical()) {
+ result = rexp.asStrings();
+ String[] strings = ((String[]) result);
+ Boolean[] stringArray = new Boolean[strings.length];
+ for (int i = 0; i < ((String[]) result).length; i++) {
+ stringArray[i] = Boolean.parseBoolean(strings[i]);
+ }
+ if (stringArray.length == 1) {
+ result = (Boolean) stringArray[0];
+ } else {
+ result = (Boolean[]) stringArray;
+ }
+ }
+
+ else if (rexp.isNull()) {
+ return null;
+ }
+
+ else {
+ log.error("Unknown return type on : " + rexp.toString());
+ }
+ } catch (REXPMismatchException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#terminate()
+ */
+ public void terminate() throws RException {
+ if (conn != null && conn.isConnected()) {
+ conn.close();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#voidEval(java.lang.String)
+ */
+ public void voidEval(String expr) throws RException {
+ try {
+ conn.voidEval(expr);
+ } catch (RserveException rse) {
+ throw new RException("An error occured while voidEval on net", rse);
+ }
+ }
+
+ /**
* Load .RData file located in directory
*
- * @param directory directory where the .RData file is located
+ * @param directory
+ * directory where the .RData file is located
* @throws RException
*/
public void loadRData(File directory) throws RException {
setwd(directory);
voidEval("load(\".RData\")");
}
-
+
/**
* Save the session in a .RData file in directory
*
- * @param directory where the .RData file will be saved
+ * @param directory
+ * where the .RData file will be saved
* @throws RException
*/
- public void saveRData(File directory) throws RException{
+ public void saveRData(File directory) throws RException {
setwd(directory);
voidEval("save.image()");
}
-
+
/**
* Set the R working directory
- * @param directory to set
+ *
+ * @param directory
+ * to set
* @throws RException
*/
public void setwd(File directory) throws RException {
- voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
+ voidEval("setwd(\"" + directory.getAbsolutePath() + "\")");
}
-
+
/**
* Get the actual R session working directory
*
* @return a File that is the actual R session working directory
* @throws RException
*/
-
+
public File getwd() throws RException {
- String directory = (String)eval("getwd()");
+ String directory = (String) eval("getwd()");
return new File(directory);
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
* The file created will be in the working directory
*
- * @param rObject name of the R object to save
- * @param outputFileName name of the file to save
+ * @param rObject
+ * name of the R object to save
+ * @param outputFileName
+ * name of the file to save
* @throws RException
*/
public void dput(String rObject, String outputFileName) throws RException {
String rInstruction = "dput(%s,file=\"%s\")";
voidEval(String.format(rInstruction, rObject, outputFileName));
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
- * The file used have to be in the working directory
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object. The file used have to be in the
+ * working directory
*
- * @param rObject name of the R object created
- * @param inputFileName name of the file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFileName
+ * name of the file to load
* @throws RException
*/
public void dget(String rObject, String inputFileName) throws RException {
String rInstruction = "%s <- dget(\"%s\")";
voidEval(String.format(rInstruction, rObject, inputFileName));
-
+
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
*
- * @param rObject R object to save
- * @param outputFileName the file to save
+ * @param rObject
+ * R object to save
+ * @param outputFileName
+ * the file to save
* @throws RException
*/
public void dput(String rObject, File outputFile) throws RException {
@@ -308,13 +318,15 @@
voidEval(String.format(rInstruction, rObject, outputFile.getName()));
setwd(workingdir);
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object.
*
- * @param rObject name of the R object created
- * @param inputFile file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFile
+ * file to load
* @throws RException
*/
public void dget(String rObject, File inputFile) throws RException {
@@ -322,11 +334,35 @@
setwd(inputFile.getParentFile());
String rInstruction = "%s <- dget(\"%s\")";
voidEval(String.format(rInstruction, rObject, inputFile.getName()));
- setwd(workingdir);
+ setwd(workingdir);
}
-
- public void remove (String rObject) throws RException {
- voidEval("remove("+rObject+")");
+
+ public void remove(String rObject) throws RException {
+ voidEval("remove(" + rObject + ")");
}
+ public void mv(String inputObject, String outputObject) throws RException {
+ cp(inputObject, outputObject);
+ remove(inputObject);
+
+ }
+
+ public void cp(String inputObject, String outputObject) throws RException {
+ voidEval(outputObject + "<-" + inputObject);
+
+ }
+
+ public String[] ls() throws RException {
+ String[] Robjects = (String[]) eval("ls()");
+ return Robjects;
+ }
+
+ public void clearSession() throws RException {
+ String[] Robjects = ls();
+ for (int i = 0; i < Robjects.length; i++) {
+ remove(Robjects[i]);
+ }
+
+ }
+
} // RNetEngine
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -255,5 +255,31 @@
engine.remove("a");
Assert.assertNull(engine.eval("a"));
}
+
+ @Test
+ public void testMvCp() throws Exception {
+ //Test only mv as mv uses cp.
+ engine.voidEval("a<-5.0");
+ engine.remove("b");
+ engine.mv("a", "b");
+ Assert.assertEquals(new Double(5.0), engine.eval("b"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"a\")"));
+ }
+
+ @Test
+ public void testLsClearSession() throws Exception {
+ //Test only ClearSession as it uses ls
+ engine.voidEval("a<-5.0");
+ engine.voidEval("b<-5.0");
+ engine.voidEval("d<-5.0");
+ engine.voidEval("e<-5.0");
+ engine.voidEval("f<-5.0");
+ engine.clearSession();
+ Assert.assertFalse((Boolean) engine.eval("exists(\"a\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"b\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"d\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"e\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"f\")"));
+ }
} // JNITest
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-28 18:42:55 UTC (rev 68)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-29 14:43:55 UTC (rev 69)
@@ -49,129 +49,130 @@
public class NetTest {
- private static Log log = LogFactory.getLog(NetTest.class);
+ private static Log log = LogFactory.getLog(NetTest.class);
- private REngine engine;
- private String savedRType;
+ private REngine engine;
+ private String savedRType;
- @Before
- public void setUp() throws Exception {
- LutinTimer init = new LutinTimer();
- init.startTiming();
- savedRType = System.getProperty("R.type", "");
- System.setProperty("R.type", "net://:6311");
- if (engine == null) {
- engine = new RProxy();
- }
- if (log.isInfoEnabled()) {
- log.info("net init: " + init.endTiming() + "ms");
- }
- }
+ @Before
+ public void setUp() throws Exception {
+ LutinTimer init = new LutinTimer();
+ init.startTiming();
+ savedRType = System.getProperty("R.type", "");
+ System.setProperty("R.type", "net://:6311");
+ if (engine == null) {
+ engine = new RProxy();
+ }
+ if (log.isInfoEnabled()) {
+ log.info("net init: " + init.endTiming() + "ms");
+ }
+ }
- @After
- public void tearDown() throws Exception {
- engine.terminate();
- System.setProperty("R.type", savedRType);
- }
+ @After
+ public void tearDown() throws Exception {
+ engine.terminate();
+ System.setProperty("R.type", savedRType);
+ }
- @Test
- public void testDouble() throws Exception {
- Assert.assertEquals(5.0, engine.eval("5.0"));
- engine.voidEval("t<-sin(0)");
- double d = (Double) engine.eval("t");
- Assert.assertEquals(0.0, d, 0);
- }
+ @Test
+ public void testDouble() throws Exception {
+ Assert.assertEquals(5.0, engine.eval("5.0"));
+ engine.voidEval("t<-sin(0)");
+ double d = (Double) engine.eval("t");
+ Assert.assertEquals(0.0, d, 0);
+ }
- @Test
- public void testIntArray() throws Exception {
- Object result = engine.eval("5:10");
- Assert.assertNotNull(result);
- Assert.assertEquals(int[].class, result.getClass());
- int[] intArray = (int[]) result;
- Assert.assertEquals(6, intArray.length);
- for (int i = 5; i < 11; i++) {
- Assert.assertEquals(i, intArray[i - 5]);
- }
- }
+ @Test
+ public void testIntArray() throws Exception {
+ Object result = engine.eval("5:10");
+ Assert.assertNotNull(result);
+ Assert.assertEquals(int[].class, result.getClass());
+ int[] intArray = (int[]) result;
+ Assert.assertEquals(6, intArray.length);
+ for (int i = 5; i < 11; i++) {
+ Assert.assertEquals(i, intArray[i - 5]);
+ }
+ }
- @Test
- public void testSimpleOp() throws Exception {
- LutinTimer t = new LutinTimer();
- for (int loop = 0; loop < S_NB_LOOPS; loop++) {
- engine.voidEval("t<-0");
- t.startTiming();
- engine.voidEval(S_OP);
- t.endTiming();
- double d = (Double) engine.eval("t");
- Assert.assertEquals((double) S_T_MAX, d, 0);
- }
- double[] results = t.computeResults();
- System.err.println("[SO]min: " + results[0]);
- System.err.println("[SO]avg: " + results[1]);
- System.err.println("[SO]max: " + results[2]);
- System.err.println("[SO]etype: " + results[3]);
- }
+ @Test
+ public void testSimpleOp() throws Exception {
+ LutinTimer t = new LutinTimer();
+ for (int loop = 0; loop < S_NB_LOOPS; loop++) {
+ engine.voidEval("t<-0");
+ t.startTiming();
+ engine.voidEval(S_OP);
+ t.endTiming();
+ double d = (Double) engine.eval("t");
+ Assert.assertEquals((double) S_T_MAX, d, 0);
+ }
+ double[] results = t.computeResults();
+ System.err.println("[SO]min: " + results[0]);
+ System.err.println("[SO]avg: " + results[1]);
+ System.err.println("[SO]max: " + results[2]);
+ System.err.println("[SO]etype: " + results[3]);
+ }
- @Test
- public void testVector() throws Exception {
- LutinTimer t = new LutinTimer();
- for (int loop = 0; loop < V_NB_LOOPS; loop++) {
- t.startTiming();
- engine.voidEval(V_OP_A);
- engine.voidEval(V_OP_B);
- double[] r = (double[]) engine.eval(V_OP_AB);
- t.endTiming();
- Assert.assertEquals(V_MAX, r.length);
- }
- double[] results = t.computeResults();
- System.err.println("[V]min: " + results[0]);
- System.err.println("[V]avg: " + results[1]);
- System.err.println("[V]max: " + results[2]);
- System.err.println("[V]etype: " + results[3]);
- }
+ @Test
+ public void testVector() throws Exception {
+ LutinTimer t = new LutinTimer();
+ for (int loop = 0; loop < V_NB_LOOPS; loop++) {
+ t.startTiming();
+ engine.voidEval(V_OP_A);
+ engine.voidEval(V_OP_B);
+ double[] r = (double[]) engine.eval(V_OP_AB);
+ t.endTiming();
+ Assert.assertEquals(V_MAX, r.length);
+ }
+ double[] results = t.computeResults();
+ System.err.println("[V]min: " + results[0]);
+ System.err.println("[V]avg: " + results[1]);
+ System.err.println("[V]max: " + results[2]);
+ System.err.println("[V]etype: " + results[3]);
+ }
- @Test
- public void testString() throws Exception {
- engine.voidEval("a<-\"testing string\"");
- String testString = (String) engine.eval("a");
- Assert.assertEquals("testing string", testString);
- }
+ @Test
+ public void testString() throws Exception {
+ engine.voidEval("a<-\"testing string\"");
+ String testString = (String) engine.eval("a");
+ Assert.assertEquals("testing string", testString);
+ }
- @Test
- public void testInt() throws Exception {
- engine.voidEval("a<-as.integer(5)");
- Integer testInteger = (Integer) engine.eval("a");
- Integer toCompare = 5;
- Assert.assertEquals(toCompare, testInteger);
- }
+ @Test
+ public void testInt() throws Exception {
+ engine.voidEval("a<-as.integer(5)");
+ Integer testInteger = (Integer) engine.eval("a");
+ Integer toCompare = 5;
+ Assert.assertEquals(toCompare, testInteger);
+ }
- @Test
- public void testBool() throws Exception {
- engine.voidEval("a<-TRUE");
- engine.voidEval("b<-FALSE");
- Boolean testA = (Boolean) engine.eval("a");
- Boolean testB = (Boolean) engine.eval("b");
- Assert.assertTrue(testA);
- Assert.assertFalse(testB);
- }
+ @Test
+ public void testBool() throws Exception {
+ engine.voidEval("a<-TRUE");
+ engine.voidEval("b<-FALSE");
+ Boolean testA = (Boolean) engine.eval("a");
+ Boolean testB = (Boolean) engine.eval("b");
+ Assert.assertTrue(testA);
+ Assert.assertFalse(testB);
+ }
- @Test
- public void testArrayBool() throws Exception {
- engine.voidEval("a<-c(TRUE,FALSE,TRUE)");
- Boolean[] testBoolArray = (Boolean[]) engine.eval("a");
- Assert.assertTrue(testBoolArray[0]);
- Assert.assertFalse(testBoolArray[1]);
- Assert.assertTrue(testBoolArray[2]);
- }
-
- @Test
+ @Test
+ public void testArrayBool() throws Exception {
+ engine.voidEval("a<-c(TRUE,FALSE,TRUE)");
+ Boolean[] testBoolArray = (Boolean[]) engine.eval("a");
+ Assert.assertTrue(testBoolArray[0]);
+ Assert.assertFalse(testBoolArray[1]);
+ Assert.assertTrue(testBoolArray[2]);
+ }
+
+ @Test
public void testWorkingDirectory() throws Exception {
File workingDirectory = new File("/tmp");
engine.setwd(workingDirectory);
File testWorkingDirectory = engine.getwd();
- Assert.assertEquals(workingDirectory.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ Assert.assertEquals(workingDirectory.getAbsolutePath(),
+ testWorkingDirectory.getAbsolutePath());
}
-
+
@Test
public void testRData() throws Exception {
File workingdir = new File("/tmp");
@@ -179,46 +180,73 @@
engine.saveRData(workingdir);
engine.remove("a");
engine.loadRData(workingdir);
- Double testDouble = (Double)engine.eval("a");
- Double compareTo = new Double (5.0);
+ Double testDouble = (Double) engine.eval("a");
+ Double compareTo = new Double(5.0);
Assert.assertEquals(compareTo, testDouble);
}
-
+
@Test
public void testDputDget() throws Exception {
File workingdir = new File("/tmp");
File testingFile = new File("/tmp/testfile");
-
+
// test method using the workingdir
engine.voidEval("a<-5.0");
engine.setwd(workingdir);
engine.dput("a", "testDputDgetfile");
engine.remove("a");
engine.dget("a", "testDputDgetfile");
- Double testDouble = (Double)engine.eval("a");
- Double compareTo = new Double (5.0);
+ Double testDouble = (Double) engine.eval("a");
+ Double compareTo = new Double(5.0);
Assert.assertEquals(compareTo, testDouble);
-
- workingdir= new File("/");
+
+ workingdir = new File("/");
//test method using absolute path
engine.setwd(workingdir);
engine.voidEval("a<-6.0");
- engine.dput("a",testingFile);
+ engine.dput("a", testingFile);
engine.remove("a");
engine.dget("a", testingFile);
- Double testDouble2 = (Double)engine.eval("a");
- Double compareTo2 = new Double (6.0);
+ Double testDouble2 = (Double) engine.eval("a");
+ Double compareTo2 = new Double(6.0);
Assert.assertEquals(compareTo2, testDouble2);
File testWorkingDirectory = engine.getwd();
- Assert.assertEquals(workingdir.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ Assert.assertEquals(workingdir.getAbsolutePath(), testWorkingDirectory
+ .getAbsolutePath());
}
-
+
@Test
public void testRemove() throws Exception {
engine.voidEval("a<-6.0");
- Assert.assertEquals(new Double(6.0),engine.eval("a"));
+ Assert.assertEquals(new Double(6.0), engine.eval("a"));
engine.remove("a");
- Assert.assertFalse((Boolean)engine.eval("exists(\"a\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"a\")"));
}
+
+ @Test
+ public void testMvCp() throws Exception {
+ //Test only mv as mv uses cp.
+ engine.voidEval("a<-5.0");
+ engine.remove("b");
+ engine.mv("a", "b");
+ Assert.assertEquals(new Double(5.0), engine.eval("b"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"a\")"));
+ }
+
+ @Test
+ public void testLsClearSession() throws Exception {
+ //Test only ClearSession as it uses ls
+ engine.voidEval("a<-5.0");
+ engine.voidEval("b<-5.0");
+ engine.voidEval("d<-5.0");
+ engine.voidEval("e<-5.0");
+ engine.voidEval("f<-5.0");
+ engine.clearSession();
+ Assert.assertFalse((Boolean) engine.eval("exists(\"a\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"b\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"d\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"e\")"));
+ Assert.assertFalse((Boolean) engine.eval("exists(\"f\")"));
+ }
} // NetTest
1
0
[LutinJ2R-commits] r68 - lutinj2r/trunk/src/test/java/org/codelutin/j2r
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
28 Apr '09
Author: jcouteau
Date: 2009-04-28 18:42:55 +0000 (Tue, 28 Apr 2009)
New Revision: 68
Modified:
lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
Log:
Fixed integer test on Net engine
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-28 16:25:41 UTC (rev 67)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-28 18:42:55 UTC (rev 68)
@@ -137,13 +137,13 @@
Assert.assertEquals("testing string", testString);
}
- /*@Test
+ @Test
public void testInt() throws Exception {
- engine.voidEval("a<-5");
+ engine.voidEval("a<-as.integer(5)");
Integer testInteger = (Integer) engine.eval("a");
Integer toCompare = 5;
Assert.assertEquals(toCompare, testInteger);
- }*/
+ }
@Test
public void testBool() throws Exception {
1
0
[LutinJ2R-commits] r67 - in lutinj2r/trunk/src: main/java/org/codelutin/j2r/jni test/java/org/codelutin/j2r
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
28 Apr '09
Author: jcouteau
Date: 2009-04-28 16:25:41 +0000 (Tue, 28 Apr 2009)
New Revision: 67
Modified:
lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
Log:
Adding Boolean management to JRIEngine
Fixed Integer tests
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-28 15:42:01 UTC (rev 66)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-28 16:25:41 UTC (rev 67)
@@ -26,7 +26,6 @@
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
-
/**
* RJniEngine.java
*
@@ -39,212 +38,240 @@
*/
public class RJniEngine implements REngine {
- private Log log = LogFactory.getLog(RJniEngine.class);
+ private Log log = LogFactory.getLog(RJniEngine.class);
- /**
- * Le Rengine est fait pour tourner en static
- */
- private static Rengine engine;
+ /**
+ * Le Rengine est fait pour tourner en static
+ */
+ private static Rengine engine;
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#init()
- */
- public boolean init() {
- if (engine == null) {
- try {
- String[] args = { "--no-save" };
- engine = new Rengine(args, false, null);
- if (!engine.waitForR()) {
- if (log.isErrorEnabled()) {
- log.error("Cannot load the R engine");
- }
- return false;
- }
- } catch (Throwable twable) {
- log.error("An error occured during R/JNI initialization.",
- twable);
- return false;
- }
- }
- return true;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#init()
+ */
+ public boolean init() {
+ if (engine == null) {
+ try {
+ String[] args = { "--no-save" };
+ engine = new Rengine(args, false, null);
+ if (!engine.waitForR()) {
+ if (log.isErrorEnabled()) {
+ log.error("Cannot load the R engine");
+ }
+ return false;
+ }
+ } catch (Throwable twable) {
+ log.error("An error occured during R/JNI initialization.",
+ twable);
+ return false;
+ }
+ }
+ return true;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.R.REngine#eval(java.lang.String)
- */
- public Object eval(String expr) throws RException {
- REXP result = null;
- try {
- log.info(expr);
- result = engine.eval(expr);
- } catch (Exception eee) {
- throw new RException("Unable to evaluate the R expression "
- + "over JNI", eee);
- }
- return convertResult(result);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.R.REngine#eval(java.lang.String)
+ */
+ public Object eval(String expr) throws RException {
+ REXP result = null;
+ try {
+ log.info(expr);
+ result = engine.eval(expr);
+ } catch (Exception eee) {
+ throw new RException("Unable to evaluate the R expression "
+ + "over JNI", eee);
+ }
+ return convertResult(result);
+ }
- private Object convertResult(REXP rexp) {
- if (rexp == null) {
- log.debug("Null returned");
- return null;
- }
- if (log.isDebugEnabled()) {
- log.debug("Converting : " + rexp.toString());
- }
- int type = rexp.getType();
- Object result = null;
- switch (type) {
- case REXP.XT_STR:
- result = rexp.asString();
- break;
- /*case REXP.XT_INT:
+ private Object convertResult(REXP rexp) {
+ if (rexp == null) {
+ log.debug("Null returned");
+ return null;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Converting : " + rexp.toString());
+ }
+ int type = rexp.getType();
+ Object result = null;
+ switch (type) {
+ case REXP.XT_STR:
+ result = rexp.asString();
+ break;
+ case REXP.XT_INT:
result = (Integer)rexp.asInt();
- break;*/
- case REXP.XT_ARRAY_INT:
+ break;
+ case REXP.XT_ARRAY_INT:
result = rexp.asIntArray();
int[] intarray = (int[]) result;
if (intarray.length == 1) {
- result = (Integer)intarray[0];
+ result = (Integer) intarray[0];
}
break;
- case REXP.XT_ARRAY_DOUBLE:
- result = rexp.asDoubleArray();
- double[] doublearray = (double[]) result;
- if (doublearray.length == 1) {
- result = doublearray[0];
- }
- break;
- case REXP.XT_BOOL:
- result = rexp.asBool().isTRUE();
- break;
- case REXP.XT_DOUBLE:
- result = rexp.asDoubleArray();
- double[] doublearray2 = (double[]) result;
- result = doublearray2[0];
- /*case REXP.XT_NULL:
- result = null;*/
- /*case REXP.XT_ARRAY_BOOL:
- result = rexp.asIntArray();
- boolean[] booleanarray = (boolean[]) result;
- result = booleanarray;*/
- case REXP.XT_VECTOR:
- result = rexp.asVector();
- default:
- log.error("Unknown return type [" + type + "] " + "on : "
- + rexp.toString());
- }
- return result;
- }
+ case REXP.XT_ARRAY_DOUBLE:
+ result = rexp.asDoubleArray();
+ double[] doublearray = (double[]) result;
+ if (doublearray.length == 1) {
+ result = doublearray[0];
+ }
+ break;
+ case REXP.XT_BOOL:
+ result = rexp.asBool().isTRUE();
+ log.info(result);
+ break;
+ case REXP.XT_DOUBLE:
+ result = rexp.asDoubleArray();
+ double[] doublearray2 = (double[]) result;
+ result = doublearray2[0];
+ break;
+ case REXP.XT_NULL:
+ result = null;
+ break;
+ case 37:
+ result = rexp.asIntArray();
+ int[] integers = ((int[]) result);
+ Boolean[] booleanArray = new Boolean[integers.length];
+ for (int i = 0; i < integers.length; i++) {
+ if (integers[i] == 1) {
+ booleanArray[i] = Boolean.TRUE;
+ } else {
+ booleanArray[i] = Boolean.FALSE;
+ }
+ }
+ if (booleanArray.length == 1) {
+ result = booleanArray[0];
+ } else {
+ result = booleanArray;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#terminate()
- */
- public void terminate() {
- if (engine.isAlive()) {
- engine.end();
- }
- }
+ break;
+ case REXP.XT_VECTOR:
+ result = rexp.asVector();
+ break;
+ default:
+ log.error("Unknown return type [" + type + "] " + "on : "
+ + rexp.toString());
+ break;
+ }
+ return result;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.j2r.REngine#voidEval(java.lang.String)
- */
- public void voidEval(String expr) throws RException {
- // voidEval is not really supproted by JRI, we just discard the result
- // conversion
- try {
- log.info(expr);
- engine.eval(expr);
- } catch (Exception eee) {
- throw new RException("An error occured while voidEval on JNI", eee);
- }
- }
-
-
- /**
- * Load .RData file located in directory
- *
- * @param directory directory where the .RData file is located
- * @throws RException
- */
- public void loadRData(File directory) throws RException {
- setwd(directory);
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#terminate()
+ */
+ public void terminate() {
+ if (engine.isAlive()) {
+ engine.end();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.j2r.REngine#voidEval(java.lang.String)
+ */
+ public void voidEval(String expr) throws RException {
+ // voidEval is not really supproted by JRI, we just discard the result
+ // conversion
+ try {
+ log.info(expr);
+ engine.eval(expr);
+ } catch (Exception eee) {
+ throw new RException("An error occured while voidEval on JNI", eee);
+ }
+ }
+
+ /**
+ * Load .RData file located in directory
+ *
+ * @param directory
+ * directory where the .RData file is located
+ * @throws RException
+ */
+ public void loadRData(File directory) throws RException {
+ setwd(directory);
voidEval("load(\".RData\")");
- }
-
- /**
- * Save the session in a .RData file in directory
- *
- * @param directory where the .RData file will be saved
- * @throws RException
- */
- public void saveRData(File directory) throws RException{
- setwd(directory);
+ }
+
+ /**
+ * Save the session in a .RData file in directory
+ *
+ * @param directory
+ * where the .RData file will be saved
+ * @throws RException
+ */
+ public void saveRData(File directory) throws RException {
+ setwd(directory);
voidEval("save.image()");
- }
-
- /**
- * Set the R working directory
- * @param directory to set
- * @throws RException
- */
- public void setwd(File directory) throws RException {
- voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
- }
-
- /**
- * Get the actual R session working directory
- *
- * @return a File that is the actual R session working directory
- * @throws RException
- */
-
+ }
+
+ /**
+ * Set the R working directory
+ *
+ * @param directory
+ * to set
+ * @throws RException
+ */
+ public void setwd(File directory) throws RException {
+ voidEval("setwd(\"" + directory.getAbsolutePath() + "\")");
+ }
+
+ /**
+ * Get the actual R session working directory
+ *
+ * @return a File that is the actual R session working directory
+ * @throws RException
+ */
+
public File getwd() throws RException {
- String directory = (String)eval("getwd()");
+ String directory = (String) eval("getwd()");
return new File(directory);
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
* The file created will be in the working directory
*
- * @param rObject name of the R object to save
- * @param outputFileName name of the file to save
+ * @param rObject
+ * name of the R object to save
+ * @param outputFileName
+ * name of the file to save
* @throws RException
*/
public void dput(String rObject, String outputFileName) throws RException {
String rInstruction = "dput(%s,file=\"%s\")";
voidEval(String.format(rInstruction, rObject, outputFileName));
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
- * The file used have to be in the working directory
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object. The file used have to be in the
+ * working directory
*
- * @param rObject name of the R object created
- * @param inputFileName name of the file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFileName
+ * name of the file to load
* @throws RException
*/
public void dget(String rObject, String inputFileName) throws RException {
String rInstruction = "%s <- dget(\"%s\")";
voidEval(String.format(rInstruction, rObject, inputFileName));
-
+
}
-
+
/**
* Use the dput R instruction to store the content of a R object to a file.
*
- * @param rObject R object to save
- * @param outputFileName the file to save
+ * @param rObject
+ * R object to save
+ * @param outputFileName
+ * the file to save
* @throws RException
*/
public void dput(String rObject, File outputFile) throws RException {
@@ -254,13 +281,15 @@
voidEval(String.format(rInstruction, rObject, outputFile.getName()));
setwd(workingdir);
}
-
-
+
/**
- * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * Use the dget rInstruction to store the content of a file (created with
+ * the dput instruction) into a R object.
*
- * @param rObject name of the R object created
- * @param inputFile file to load
+ * @param rObject
+ * name of the R object created
+ * @param inputFile
+ * file to load
* @throws RException
*/
public void dget(String rObject, File inputFile) throws RException {
@@ -268,11 +297,11 @@
setwd(inputFile.getParentFile());
String rInstruction = "%s <- dget(\"%s\")";
voidEval(String.format(rInstruction, rObject, inputFile.getName()));
- setwd(workingdir);
+ setwd(workingdir);
}
-
- public void remove (String rObject) throws RException {
- voidEval("remove("+rObject+")");
+
+ public void remove(String rObject) throws RException {
+ voidEval("remove(" + rObject + ")");
}
} // RJniEngine
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-28 15:42:01 UTC (rev 66)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-28 16:25:41 UTC (rev 67)
@@ -84,17 +84,6 @@
}
@Test
- public void testIntArray() throws Exception {
- Object result = engine.eval("5:10");
- Assert.assertEquals(int[].class, result.getClass());
- int[] intArray = (int[]) result;
- Assert.assertEquals(6, intArray.length);
- for (int i = 5; i < 11; i++) {
- Assert.assertEquals(i, intArray[i - 5]);
- }
- }
-
- @Test
public void testDoubleArray() throws Exception {
Object result = engine.eval("5.5:10.5");
Assert.assertEquals(double[].class, result.getClass());
@@ -150,15 +139,27 @@
Assert.assertEquals("testing string", testString);
}
- /*@Test
+ @Test
public void testInt() throws Exception {
- engine.voidEval("a<-5");
+ engine.voidEval("a<-as.integer(5)");
Integer testInteger = (Integer) engine.eval("a");
Integer toCompare = 5;
Assert.assertEquals(toCompare, testInteger);
- }*/
+ }
+
+ @Test
+ public void testIntArray() throws Exception {
+ engine.voidEval("a<-as.integer(5)");
+ engine.voidEval("b<-as.integer(6)");
+ engine.voidEval("z<-c(a,b)");
+ int[] testIntArray = (int[]) engine.eval("z");
+ int toCompare1 = 5;
+ Assert.assertEquals(toCompare1, testIntArray[0]);
+ int toCompare2 = 6;
+ Assert.assertEquals(toCompare2, testIntArray[1]);
+ }
- /* @Test
+ @Test
public void testBool() throws Exception {
engine.voidEval("a<-TRUE");
engine.voidEval("b<-FALSE");
@@ -166,16 +167,16 @@
Boolean testB = (Boolean) engine.eval("b");
Assert.assertTrue(testA);
Assert.assertFalse(testB);
- }*/
+ }
- /* @Test
+ @Test
public void testArrayBool() throws Exception {
engine.voidEval("a<-c(TRUE,FALSE,TRUE)");
Boolean[] testBoolArray = (Boolean[]) engine.eval("a");
Assert.assertTrue(testBoolArray[0]);
Assert.assertFalse(testBoolArray[1]);
Assert.assertTrue(testBoolArray[2]);
- }*/
+ }
/*@Test
public void testDataFrame() throws Exception {
1
0
[LutinJ2R-commits] r66 - in lutinj2r/trunk/src: main/java/org/codelutin/j2r main/java/org/codelutin/j2r/jni main/java/org/codelutin/j2r/net test/java/org/codelutin/j2r
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
by jcouteau@users.labs.libre-entreprise.org 28 Apr '09
28 Apr '09
Author: jcouteau
Date: 2009-04-28 15:42:01 +0000 (Tue, 28 Apr 2009)
New Revision: 66
Modified:
lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
Log:
Adding support for booleans in NetEngine
Adding support for R native methods to:
- set/get R working directory
- store/get R objects in files
- remove objects from R session
- save/load a R session
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/REngine.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -29,6 +29,8 @@
package org.codelutin.j2r;
+import java.io.File;
+
/**
* Cette interface est le point commun entre les differentes technologies
* utilisees pour l'acces a R
@@ -65,5 +67,84 @@
* @throws RException
*/
public void terminate() throws RException;
+
+ /**
+ * Load .RData file located in directory
+ *
+ * @param directory directory where the .RData file is located
+ * @throws RException
+ */
+ public void loadRData(File directory) throws RException;
+
+ /**
+ * Save the session in a .RData file in directory
+ *
+ * @param directory where the .RData file will be saved
+ * @throws RException
+ */
+ public void saveRData(File directory) throws RException;
+
+ /**
+ * Set the R working directory
+ * @param directory to set
+ * @throws RException
+ */
+ public void setwd(File directory) throws RException;
+
+ /**
+ * Get the actual R session working directory
+ *
+ * @return a File that is the actual R session working directory
+ * @throws RException
+ */
+
+ public File getwd() throws RException;
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ * The file created will be in the working directory
+ *
+ * @param rObject name of the R object to save
+ * @param outputFileName name of the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, String outputFileName) throws RException;
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * The file used have to be in the working directory
+ *
+ * @param rObject name of the R object created
+ * @param inputFileName name of the file to load
+ * @throws RException
+ */
+ public void dget(String rObject, String inputFileName) throws RException;
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ *
+ * @param rObject R object to save
+ * @param outputFileName the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, File outputFile) throws RException;
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ *
+ * @param rObject name of the R object created
+ * @param inputFile file to load
+ * @throws RException
+ */
+ public void dget(String rObject, File inputFile) throws RException;
+
+ /**
+ * Remove a R object from the actual session
+ * @param rObject to be removed from the session
+ * @throws RException
+ */
+ public void remove (String rObject) throws RException;
} //RJniEngine
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/RProxy.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -29,6 +29,8 @@
package org.codelutin.j2r;
+import java.io.File;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.j2r.jni.RJniEngine;
@@ -131,7 +133,7 @@
}
if (!init(RType)) {
if (log.isFatalEnabled()) {
- log.fatal("The initializaing of R failed.");
+ log.fatal("The initializing of R failed.");
}
return false;
}
@@ -161,5 +163,156 @@
}
engine.voidEval(expr);
}
+
+ /**
+ * Load .RData file located in directory
+ *
+ * @param directory directory where the .RData file is located
+ * @throws RException
+ */
+ public void loadRData(File directory) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ engine.setwd(directory);
+ engine.voidEval("load(\".RData\")");
+ }
+
+ /**
+ * Save the session in a .RData file in directory
+ *
+ * @param directory where the .RData file will be saved
+ * @throws RException
+ */
+ public void saveRData(File directory) throws RException{
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ engine.setwd(directory);
+ engine.voidEval("save.image()");
+ }
+
+ /**
+ * Set the R working directory
+ * @param directory to set
+ * @throws RException
+ */
+ public void setwd(File directory) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ engine.voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
+ }
+
+ /**
+ * Get the actual R session working directory
+ *
+ * @return a File that is the actual R session working directory, null if the engine is not initialized
+ * @throws RException
+ */
+
+ public File getwd() throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return null;
+ }
+ String directory = (String)engine.eval("getwd()");
+ return new File(directory);
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ * The file created will be in the working directory
+ *
+ * @param rObject name of the R object to save
+ * @param outputFileName name of the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, String outputFileName) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ String rInstruction = "dput(%s,file=\"%s\")";
+ engine.voidEval(String.format(rInstruction, rObject, outputFileName));
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * The file used have to be in the working directory
+ *
+ * @param rObject name of the R object created
+ * @param inputFileName name of the file to load
+ * @throws RException
+ */
+ public void dget(String rObject, String inputFileName) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ String rInstruction = "%s <- dget(\"%s\")";
+ engine.voidEval(String.format(rInstruction, rObject, inputFileName));
+
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ *
+ * @param rObject R object to save
+ * @param outputFileName the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, File outputFile) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ File workingdir = getwd();
+ engine.setwd(outputFile.getParentFile());
+ String rInstruction = "dput(%s,file=\"%s\")";
+ engine.voidEval(String.format(rInstruction, rObject, outputFile.getName()));
+ setwd(workingdir);
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ *
+ * @param rObject name of the R object created
+ * @param inputFile file to load
+ * @throws RException
+ */
+ public void dget(String rObject, File inputFile) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ File workingdir = getwd();
+ engine.setwd(inputFile.getParentFile());
+ String rInstruction = "%s <- dget(\"%s\")";
+ engine.voidEval(String.format(rInstruction, rObject, inputFile.getName()));
+ setwd(workingdir);
+ }
+
+ public void remove(String rObject) throws RException {
+ if (engine == null) {
+ log.fatal("The R Proxy is not initialized. An error probably " +
+ "occured during the initialization.");
+ return;
+ }
+ engine.remove(rObject);
+ }
} //RProxy
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -17,6 +17,8 @@
package org.codelutin.j2r.jni;
+import java.io.File;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.j2r.REngine;
@@ -77,6 +79,7 @@
public Object eval(String expr) throws RException {
REXP result = null;
try {
+ log.info(expr);
result = engine.eval(expr);
} catch (Exception eee) {
throw new RException("Unable to evaluate the R expression "
@@ -158,11 +161,118 @@
// voidEval is not really supproted by JRI, we just discard the result
// conversion
try {
+ log.info(expr);
engine.eval(expr);
} catch (Exception eee) {
throw new RException("An error occured while voidEval on JNI", eee);
}
}
+
+ /**
+ * Load .RData file located in directory
+ *
+ * @param directory directory where the .RData file is located
+ * @throws RException
+ */
+ public void loadRData(File directory) throws RException {
+ setwd(directory);
+ voidEval("load(\".RData\")");
+ }
+
+ /**
+ * Save the session in a .RData file in directory
+ *
+ * @param directory where the .RData file will be saved
+ * @throws RException
+ */
+ public void saveRData(File directory) throws RException{
+ setwd(directory);
+ voidEval("save.image()");
+ }
+
+ /**
+ * Set the R working directory
+ * @param directory to set
+ * @throws RException
+ */
+ public void setwd(File directory) throws RException {
+ voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
+ }
+
+ /**
+ * Get the actual R session working directory
+ *
+ * @return a File that is the actual R session working directory
+ * @throws RException
+ */
+
+ public File getwd() throws RException {
+ String directory = (String)eval("getwd()");
+ return new File(directory);
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ * The file created will be in the working directory
+ *
+ * @param rObject name of the R object to save
+ * @param outputFileName name of the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, String outputFileName) throws RException {
+ String rInstruction = "dput(%s,file=\"%s\")";
+ voidEval(String.format(rInstruction, rObject, outputFileName));
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * The file used have to be in the working directory
+ *
+ * @param rObject name of the R object created
+ * @param inputFileName name of the file to load
+ * @throws RException
+ */
+ public void dget(String rObject, String inputFileName) throws RException {
+ String rInstruction = "%s <- dget(\"%s\")";
+ voidEval(String.format(rInstruction, rObject, inputFileName));
+
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ *
+ * @param rObject R object to save
+ * @param outputFileName the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, File outputFile) throws RException {
+ File workingdir = getwd();
+ setwd(outputFile.getParentFile());
+ String rInstruction = "dput(%s,file=\"%s\")";
+ voidEval(String.format(rInstruction, rObject, outputFile.getName()));
+ setwd(workingdir);
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ *
+ * @param rObject name of the R object created
+ * @param inputFile file to load
+ * @throws RException
+ */
+ public void dget(String rObject, File inputFile) throws RException {
+ File workingdir = getwd();
+ setwd(inputFile.getParentFile());
+ String rInstruction = "%s <- dget(\"%s\")";
+ voidEval(String.format(rInstruction, rObject, inputFile.getName()));
+ setwd(workingdir);
+ }
+
+ public void remove (String rObject) throws RException {
+ voidEval("remove("+rObject+")");
+ }
} // RJniEngine
Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java
===================================================================
--- lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -29,6 +29,8 @@
package org.codelutin.j2r.net;
+import java.io.File;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.j2r.REngine;
@@ -120,6 +122,7 @@
public Object eval(String expr) throws RException {
REXP result = null;
try {
+ log.info(expr);
result = conn.eval(expr);
} catch (RserveException e) {
throw new RException("An error occured during the eval method", e);
@@ -171,12 +174,20 @@
else if (rexp.isLogical()) {
result = rexp.asStrings();
- Boolean[] stringArray = (Boolean[])result;
+ String[] strings = ((String [])result);
+ Boolean[] stringArray = new Boolean[strings.length];
+ for (int i=0;i<((String [])result).length;i++){
+ stringArray[i]=Boolean.parseBoolean(strings[i]);
+ }
if (stringArray.length == 1) {
result = (Boolean)stringArray[0];
}
- else {result = (Boolean[])result;}
+ else {result = (Boolean[])stringArray;}
}
+
+ else if (rexp.isNull()) {
+ return null;
+ }
else {
log.error("Unknown return type on : " + rexp.toString());
@@ -205,10 +216,117 @@
*/
public void voidEval(String expr) throws RException {
try {
+ log.info(expr);
conn.voidEval(expr);
} catch (RserveException rse) {
throw new RException("An error occured while voidEval on net", rse);
}
}
+
+ /**
+ * Load .RData file located in directory
+ *
+ * @param directory directory where the .RData file is located
+ * @throws RException
+ */
+ public void loadRData(File directory) throws RException {
+ setwd(directory);
+ voidEval("load(\".RData\")");
+ }
+
+ /**
+ * Save the session in a .RData file in directory
+ *
+ * @param directory where the .RData file will be saved
+ * @throws RException
+ */
+ public void saveRData(File directory) throws RException{
+ setwd(directory);
+ voidEval("save.image()");
+ }
+
+ /**
+ * Set the R working directory
+ * @param directory to set
+ * @throws RException
+ */
+ public void setwd(File directory) throws RException {
+ voidEval("setwd(\""+directory.getAbsolutePath() + "\")");
+ }
+
+ /**
+ * Get the actual R session working directory
+ *
+ * @return a File that is the actual R session working directory
+ * @throws RException
+ */
+
+ public File getwd() throws RException {
+ String directory = (String)eval("getwd()");
+ return new File(directory);
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ * The file created will be in the working directory
+ *
+ * @param rObject name of the R object to save
+ * @param outputFileName name of the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, String outputFileName) throws RException {
+ String rInstruction = "dput(%s,file=\"%s\")";
+ voidEval(String.format(rInstruction, rObject, outputFileName));
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ * The file used have to be in the working directory
+ *
+ * @param rObject name of the R object created
+ * @param inputFileName name of the file to load
+ * @throws RException
+ */
+ public void dget(String rObject, String inputFileName) throws RException {
+ String rInstruction = "%s <- dget(\"%s\")";
+ voidEval(String.format(rInstruction, rObject, inputFileName));
+
+ }
+
+ /**
+ * Use the dput R instruction to store the content of a R object to a file.
+ *
+ * @param rObject R object to save
+ * @param outputFileName the file to save
+ * @throws RException
+ */
+ public void dput(String rObject, File outputFile) throws RException {
+ File workingdir = getwd();
+ setwd(outputFile.getParentFile());
+ String rInstruction = "dput(%s,file=\"%s\")";
+ voidEval(String.format(rInstruction, rObject, outputFile.getName()));
+ setwd(workingdir);
+ }
+
+
+ /**
+ * Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
+ *
+ * @param rObject name of the R object created
+ * @param inputFile file to load
+ * @throws RException
+ */
+ public void dget(String rObject, File inputFile) throws RException {
+ File workingdir = getwd();
+ setwd(inputFile.getParentFile());
+ String rInstruction = "%s <- dget(\"%s\")";
+ voidEval(String.format(rInstruction, rObject, inputFile.getName()));
+ setwd(workingdir);
+ }
+
+ public void remove (String rObject) throws RException {
+ voidEval("remove("+rObject+")");
+ }
} // RNetEngine
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/JNITest.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -39,9 +39,7 @@
import static org.codelutin.j2r.TestConstants.V_OP_B;
import static org.codelutin.j2r.TestConstants.V_OP_R;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
+import java.io.File;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,8 +47,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.rosuda.JRI.REXP;
-import org.rosuda.JRI.RVector;
public class JNITest {
@@ -181,7 +177,7 @@
Assert.assertTrue(testBoolArray[2]);
}*/
- @Test
+ /*@Test
public void testDataFrame() throws Exception {
engine.voidEval("X1<-data.frame(matrix(runif(5*100),nrow=100))");
Assert.assertTrue(engine.eval("X1") instanceof Vector);
@@ -190,5 +186,73 @@
.asDoubleArray().length, 100);
}
+ @Test
+ public void testSobol() throws Exception {
+ engine.voidEval("library(sensitivity)");
+ engine.voidEval("setwd(\"/home/couteau/isis-export/as__2009-04-07-17-36\")");
+ engine.voidEval("a<-fast99(model=NULL,factors=c(2), n=17,M=1, q = \"qunif\", q.arg=list(min=0,max=1))");
+ engine.voidEval("dput(a,file=\".fast99\")");
+ Assert.assertTrue(engine.eval("a$X") instanceof Vector);
+ Assert.assertEquals(((Integer) engine.eval("length(a$X[,1])")).intValue(), 34);
+
+ }*/
+
+ @Test
+ public void testWorkingDirectory() throws Exception {
+ File workingDirectory = new File("/tmp");
+ engine.setwd(workingDirectory);
+ File testWorkingDirectory = engine.getwd();
+ Assert.assertEquals(workingDirectory.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ }
+
+ @Test
+ public void testRData() throws Exception {
+ File workingdir = new File("/tmp");
+ engine.voidEval("a<-5.0");
+ engine.saveRData(workingdir);
+ engine.remove("a");
+ engine.loadRData(workingdir);
+ Double testDouble = (Double)engine.eval("a");
+ Double compareTo = new Double (5.0);
+ Assert.assertEquals(compareTo, testDouble);
+ }
+
+ @Test
+ public void testDputDget() throws Exception {
+ File workingdir = new File("/tmp");
+ File testingFile = new File("/tmp/testfile");
+
+ // test method using the workingdir
+ engine.voidEval("a<-5.0");
+ engine.setwd(workingdir);
+ engine.dput("a", "testDputDgetfile");
+ engine.remove("a");
+ engine.dget("a", "testDputDgetfile");
+ Double testDouble = (Double)engine.eval("a");
+ Double compareTo = new Double (5.0);
+ Assert.assertEquals(compareTo, testDouble);
+
+ //test method using absolute path
+ workingdir = new File("/");
+ engine.setwd(workingdir);
+ engine.voidEval("a<-6.0");
+ engine.dput("a",testingFile);
+ engine.remove("a");
+ engine.dget("a", testingFile);
+ Double testDouble2 = (Double)engine.eval("a");
+ Double compareTo2 = new Double (6.0);
+ Assert.assertEquals(compareTo2, testDouble2);
+ File testWorkingDirectory = engine.getwd();
+ Assert.assertEquals(workingdir.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ engine.voidEval("a<-6.0");
+ Assert.assertEquals(new Double(6.0),engine.eval("a"));
+ engine.remove("a");
+ Assert.assertNull(engine.eval("a"));
+ }
+
} // JNITest
Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java
===================================================================
--- lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-09 12:29:24 UTC (rev 65)
+++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/NetTest.java 2009-04-28 15:42:01 UTC (rev 66)
@@ -38,6 +38,8 @@
import static org.codelutin.j2r.TestConstants.V_OP_AB;
import static org.codelutin.j2r.TestConstants.V_OP_B;
+import java.io.File;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
@@ -141,7 +143,7 @@
Integer testInteger = (Integer) engine.eval("a");
Integer toCompare = 5;
Assert.assertEquals(toCompare, testInteger);
- }
+ }*/
@Test
public void testBool() throws Exception {
@@ -160,6 +162,63 @@
Assert.assertTrue(testBoolArray[0]);
Assert.assertFalse(testBoolArray[1]);
Assert.assertTrue(testBoolArray[2]);
- }*/
+ }
+
+ @Test
+ public void testWorkingDirectory() throws Exception {
+ File workingDirectory = new File("/tmp");
+ engine.setwd(workingDirectory);
+ File testWorkingDirectory = engine.getwd();
+ Assert.assertEquals(workingDirectory.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ }
+
+ @Test
+ public void testRData() throws Exception {
+ File workingdir = new File("/tmp");
+ engine.voidEval("a<-5.0");
+ engine.saveRData(workingdir);
+ engine.remove("a");
+ engine.loadRData(workingdir);
+ Double testDouble = (Double)engine.eval("a");
+ Double compareTo = new Double (5.0);
+ Assert.assertEquals(compareTo, testDouble);
+ }
+
+ @Test
+ public void testDputDget() throws Exception {
+ File workingdir = new File("/tmp");
+ File testingFile = new File("/tmp/testfile");
+
+ // test method using the workingdir
+ engine.voidEval("a<-5.0");
+ engine.setwd(workingdir);
+ engine.dput("a", "testDputDgetfile");
+ engine.remove("a");
+ engine.dget("a", "testDputDgetfile");
+ Double testDouble = (Double)engine.eval("a");
+ Double compareTo = new Double (5.0);
+ Assert.assertEquals(compareTo, testDouble);
+
+ workingdir= new File("/");
+ //test method using absolute path
+ engine.setwd(workingdir);
+ engine.voidEval("a<-6.0");
+ engine.dput("a",testingFile);
+ engine.remove("a");
+ engine.dget("a", testingFile);
+ Double testDouble2 = (Double)engine.eval("a");
+ Double compareTo2 = new Double (6.0);
+ Assert.assertEquals(compareTo2, testDouble2);
+ File testWorkingDirectory = engine.getwd();
+ Assert.assertEquals(workingdir.getAbsolutePath(), testWorkingDirectory.getAbsolutePath());
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ engine.voidEval("a<-6.0");
+ Assert.assertEquals(new Double(6.0),engine.eval("a"));
+ engine.remove("a");
+ Assert.assertFalse((Boolean)engine.eval("exists(\"a\")"));
+ }
} // NetTest
1
0
09 Apr '09
Author: chatellier
Date: 2009-04-09 12:29:24 +0000 (Thu, 09 Apr 2009)
New Revision: 65
Modified:
lutinj2r/trunk/pom.xml
Log:
Fix scm values
Modified: lutinj2r/trunk/pom.xml
===================================================================
--- lutinj2r/trunk/pom.xml 2009-04-09 10:40:22 UTC (rev 64)
+++ lutinj2r/trunk/pom.xml 2009-04-09 12:29:24 UTC (rev 65)
@@ -120,9 +120,9 @@
</build>
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/trunk/…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
<!--Code Lutin Repository-->
1
0
09 Apr '09
Author: chatellier
Date: 2009-04-09 10:40:22 +0000 (Thu, 09 Apr 2009)
New Revision: 64
Modified:
lutinj2r/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: lutinj2r/trunk/pom.xml
===================================================================
--- lutinj2r/trunk/pom.xml 2009-04-09 10:40:19 UTC (rev 63)
+++ lutinj2r/trunk/pom.xml 2009-04-09 10:40:22 UTC (rev 64)
@@ -13,7 +13,7 @@
</parent>
<artifactId>lutinj2r</artifactId>
- <version>0.3</version>
+ <version>0.4-SNAPSHOT</version>
<dependencies>
<!-- dependency>
@@ -120,9 +120,9 @@
</build>
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/tags/l…</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/trunk/…</url>
</scm>
<!--Code Lutin Repository-->
1
0
[LutinJ2R-commits] r63 - in lutinj2r/tags: . lutinj2r-0.3
by chatellier@users.labs.libre-entreprise.org 09 Apr '09
by chatellier@users.labs.libre-entreprise.org 09 Apr '09
09 Apr '09
Author: chatellier
Date: 2009-04-09 10:40:19 +0000 (Thu, 09 Apr 2009)
New Revision: 63
Added:
lutinj2r/tags/lutinj2r-0.3/
lutinj2r/tags/lutinj2r-0.3/pom.xml
Removed:
lutinj2r/tags/lutinj2r-0.3/pom.xml
Log:
[maven-release-plugin] copy for tag lutinj2r-0.3
Copied: lutinj2r/tags/lutinj2r-0.3 (from rev 56, lutinj2r/trunk)
Deleted: lutinj2r/tags/lutinj2r-0.3/pom.xml
===================================================================
--- lutinj2r/trunk/pom.xml 2009-04-09 10:31:50 UTC (rev 56)
+++ lutinj2r/tags/lutinj2r-0.3/pom.xml 2009-04-09 10:40:19 UTC (rev 63)
@@ -1,190 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
- <parent>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinproject</artifactId>
- <version>3.4</version>
- </parent>
-
- <artifactId>lutinj2r</artifactId>
- <version>0.3</version>
-
- <dependencies>
- <!-- dependency>
- <groupId>externallib</groupId>
- <artifactId>JRclient</artifactId>
- <version>RF503</version>
- <scope>compile</scope>
- </dependency-->
- <dependency>
- <groupId>externallib</groupId>
- <artifactId>JRI</artifactId>
- <version>0.7-0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>externallib</groupId>
- <artifactId>REngine</artifactId>
- <version>0.6-0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>externallib</groupId>
- <artifactId>Rserve</artifactId>
- <version>0.6-0</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>Lutin Java-2-R library</name>
- <description>Librairie permettant d'utiliser R en Java, que ce soit par le
- Network ou en JNI.
- </description>
- <inceptionYear>2006</inceptionYear>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <properties>
- <!-- id du projet du labs -->
- <labs.id>109</labs.id>
-
- <labs.name>lutinj2r</labs.name>
-
- <!-- FIXME -->
- <maven.test.skip>true</maven.test.skip>
-
- <!-- Jar main class -->
- <!--maven.jar.main.class>org.codelutin.j2r.RProxy</maven.jar.main.class-->
- </properties>
-
- <build>
- <defaultGoal>install</defaultGoal>
-
- <plugins>
-
- <!-- Always process jrst files, but only called on pre-site phase -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jrst-plugin</artifactId>
- <version>0.8.4</version>
- <configuration>
- <defaultLocale>fr</defaultLocale>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>jrst</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/deps.xml</descriptor>
- <descriptor>src/main/assembly/full.xml</descriptor>
- </descriptors>
- <attach>false</attach>
- </configuration>
- <executions>
- <execution>
- <id>create-assembly</id>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
-
- </build>
-
- <scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinbuilder/lutinj2r/tags/lutinj2r-0.3</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinbuilder/lutinj2r/tags/lutinj2r-0.3</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/tags/l…</url>
- </scm>
-
- <!--Code Lutin Repository-->
- <repositories>
- <repository>
- <id>codelutin-repository</id>
- <name>CodeLutinRepository</name>
- <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
- <snapshots>
- <enabled>true</enabled>
- <checksumPolicy>warn</checksumPolicy>
- </snapshots>
- <releases>
- <enabled>true</enabled>
- <checksumPolicy>warn</checksumPolicy>
- </releases>
- </repository>
- </repositories>
-
- <profiles>
- <profile>
- <id>release-profile</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
-
- <!-- launch in a release the assembly automaticly -->
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>create-assembly</id>
- <phase>package</phase>
- </execution>
- </executions>
- </plugin>
-
- <!-- always add license and third-party files to classpath -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-license-switcher-plugin</artifactId>
- <version>0.6</version>
- <executions>
- <execution>
- <id>attach-licenses</id>
- <goals>
- <goal>license</goal>
- <goal>third-party</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
-
- </build>
- </profile>
- </profiles>
-
-</project>
\ No newline at end of file
Copied: lutinj2r/tags/lutinj2r-0.3/pom.xml (from rev 62, lutinj2r/trunk/pom.xml)
===================================================================
--- lutinj2r/tags/lutinj2r-0.3/pom.xml (rev 0)
+++ lutinj2r/tags/lutinj2r-0.3/pom.xml 2009-04-09 10:40:19 UTC (rev 63)
@@ -0,0 +1,190 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinproject</artifactId>
+ <version>3.4</version>
+ </parent>
+
+ <artifactId>lutinj2r</artifactId>
+ <version>0.3</version>
+
+ <dependencies>
+ <!-- dependency>
+ <groupId>externallib</groupId>
+ <artifactId>JRclient</artifactId>
+ <version>RF503</version>
+ <scope>compile</scope>
+ </dependency-->
+ <dependency>
+ <groupId>externallib</groupId>
+ <artifactId>JRI</artifactId>
+ <version>0.7-0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>externallib</groupId>
+ <artifactId>REngine</artifactId>
+ <version>0.6-0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>externallib</groupId>
+ <artifactId>Rserve</artifactId>
+ <version>0.6-0</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>Lutin Java-2-R library</name>
+ <description>Librairie permettant d'utiliser R en Java, que ce soit par le
+ Network ou en JNI.
+ </description>
+ <inceptionYear>2006</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <properties>
+ <!-- id du projet du labs -->
+ <labs.id>109</labs.id>
+
+ <labs.project>lutinj2r</labs.project>
+
+ <!-- FIXME -->
+ <maven.test.skip>true</maven.test.skip>
+
+ <!-- Jar main class -->
+ <!--maven.jar.main.class>org.codelutin.j2r.RProxy</maven.jar.main.class-->
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+
+ <!-- Always process jrst files, but only called on pre-site phase -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-jrst-plugin</artifactId>
+ <version>0.8.4</version>
+ <configuration>
+ <defaultLocale>fr</defaultLocale>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jrst</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/deps.xml</descriptor>
+ <descriptor>src/main/assembly/full.xml</descriptor>
+ </descriptors>
+ <attach>false</attach>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-assembly</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ </build>
+
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/tags/l…</url>
+ </scm>
+
+ <!--Code Lutin Repository-->
+ <repositories>
+ <repository>
+ <id>codelutin-repository</id>
+ <name>CodeLutinRepository</name>
+ <url>http://lutinbuilder.labs.libre-entreprise.org/maven2</url>
+ <snapshots>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ <checksumPolicy>warn</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+
+ <profiles>
+ <profile>
+ <id>release-profile</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+
+ <!-- launch in a release the assembly automaticly -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-assembly</id>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- always add license and third-party files to classpath -->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-license-switcher-plugin</artifactId>
+ <version>0.6</version>
+ <executions>
+ <execution>
+ <id>attach-licenses</id>
+ <goals>
+ <goal>license</goal>
+ <goal>third-party</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+ </profile>
+ </profiles>
+
+</project>
\ No newline at end of file
1
0
09 Apr '09
Author: chatellier
Date: 2009-04-09 10:40:15 +0000 (Thu, 09 Apr 2009)
New Revision: 62
Modified:
lutinj2r/trunk/pom.xml
Log:
[maven-release-plugin] prepare release lutinj2r-0.3
Modified: lutinj2r/trunk/pom.xml
===================================================================
--- lutinj2r/trunk/pom.xml 2009-04-09 10:39:50 UTC (rev 61)
+++ lutinj2r/trunk/pom.xml 2009-04-09 10:40:15 UTC (rev 62)
@@ -13,7 +13,7 @@
</parent>
<artifactId>lutinj2r</artifactId>
- <version>0.3-SNAPSHOT</version>
+ <version>0.3</version>
<dependencies>
<!-- dependency>
@@ -120,9 +120,9 @@
</build>
<scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</connection>
+ <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinj2r/lutinj2r/tags/lutinj2r-0.3</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/tags/l…</url>
</scm>
<!--Code Lutin Repository-->
1
0
09 Apr '09
Author: chatellier
Date: 2009-04-09 10:39:50 +0000 (Thu, 09 Apr 2009)
New Revision: 61
Modified:
lutinj2r/trunk/pom.xml
Log:
Release failed
Modified: lutinj2r/trunk/pom.xml
===================================================================
--- lutinj2r/trunk/pom.xml 2009-04-09 10:39:15 UTC (rev 60)
+++ lutinj2r/trunk/pom.xml 2009-04-09 10:39:50 UTC (rev 61)
@@ -62,7 +62,7 @@
<!-- id du projet du labs -->
<labs.id>109</labs.id>
- <labs.name>lutinj2r</labs.name>
+ <labs.project>lutinj2r</labs.project>
<!-- FIXME -->
<maven.test.skip>true</maven.test.skip>
@@ -120,9 +120,9 @@
</build>
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinbuilder/lutinj2r/tags/lutinj2r-0.3</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinbuilder/lutinj2r/tags/lutinj2r-0.3</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinj2r/tags/l…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
<!--Code Lutin Repository-->
1
0