Révision 281
tmp/org.txm.statsengine.r.core/plugin.xml (revision 281) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.eclipse.core.runtime.preferences"> |
|
6 |
<initializer |
|
7 |
class="org.txm.statsengine.r.core.preferences.RPreferences"> |
|
8 |
</initializer> |
|
9 |
</extension> |
|
10 |
|
|
11 |
</plugin> |
|
0 | 12 |
tmp/org.txm.statsengine.r.core/.settings/org.eclipse.jdt.core.prefs (revision 281) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.statsengine.r.core/.classpath (revision 281) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.statsengine.r.core/META-INF/MANIFEST.MF (revision 281) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: R Statistics Engine Core |
|
4 |
Bundle-SymbolicName: org.txm.statsengine.r.core;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Require-Bundle: org.txm.libs.colt;bundle-version="1.0.0";visibility:=reexport, |
|
7 |
org.txm.libs.rserve;bundle-version="0.0.0";visibility:=reexport, |
|
8 |
org.txm.statsengine.core;bundle-version="1.0.0";visibility:=reexport, |
|
9 |
org.txm.core;bundle-version="0.7.0", |
|
10 |
org.eclipse.core.runtime |
|
11 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
12 |
Bundle-ActivationPolicy: lazy |
|
13 |
Export-Package: org.txm.statsengine.r.core, |
|
14 |
org.txm.statsengine.r.core.data, |
|
15 |
org.txm.statsengine.r.core.exceptions, |
|
16 |
org.txm.statsengine.r.core.messages, |
|
17 |
org.txm.statsengine.r.core.preferences, |
|
18 |
org.txm.statsengine.r.core.rcolt |
|
19 |
Bundle-Vendor: Textometrie.org |
|
0 | 20 |
tmp/org.txm.statsengine.r.core/.project (revision 281) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.statsengine.r.core</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/ConnectToRserve.java (revision 281) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.statsengine.r.core; |
|
29 |
import org.rosuda.REngine.REXP; |
|
30 |
import org.rosuda.REngine.RList; |
|
31 |
import org.rosuda.REngine.Rserve.RConnection; |
|
32 |
|
|
33 |
// TODO: Auto-generated Javadoc |
|
34 |
/** |
|
35 |
* The Class ConnectToRserve. |
|
36 |
*/ |
|
37 |
// not used? class of test? |
|
38 |
class ConnectToRserve { |
|
39 |
|
|
40 |
/** |
|
41 |
* The main method. |
|
42 |
* |
|
43 |
* @param args the arguments |
|
44 |
*/ |
|
45 |
public static void main(String args[]) { |
|
46 |
try { |
|
47 |
RConnection c = new RConnection(); |
|
48 |
String userhome = System.getProperty("user.home"); //$NON-NLS-1$ |
|
49 |
RList ret = c.eval("source('"+userhome+"/Bureau/R/Rdata')").asList(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
50 |
|
|
51 |
System.out.println("source ret : "+ret.get(1)); //$NON-NLS-1$ |
|
52 |
System.out.println(ret); |
|
53 |
|
|
54 |
REXP ret2 = c.eval("print(lexicaltable)"); //$NON-NLS-1$ |
|
55 |
System.out.println("lexicaltable :"+ret2); //$NON-NLS-1$ |
|
56 |
} |
|
57 |
catch(Exception e) { |
|
58 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
0 | 62 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/rcolt/RColt.java (revision 281) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.statsengine.r.core.rcolt; |
|
29 |
|
|
30 |
import cern.colt.function.IntIntDoubleFunction; |
|
31 |
import cern.colt.matrix.DoubleMatrix2D; |
|
32 |
|
|
33 |
// TODO: Auto-generated Javadoc |
|
34 |
/** |
|
35 |
* Method for transformation of colt matrix into various array. |
|
36 |
* |
|
37 |
* @author sloiseau |
|
38 |
* |
|
39 |
*/ |
|
40 |
public final class RColt { |
|
41 |
|
|
42 |
/** |
|
43 |
* Double matrix2 d2 int int array. |
|
44 |
* |
|
45 |
* @param matrix the matrix |
|
46 |
* @return the int[][] |
|
47 |
*/ |
|
48 |
public final static int[][] doubleMatrix2D2IntIntArray(DoubleMatrix2D matrix) { |
|
49 |
int rows = matrix.rows(); |
|
50 |
int columns = matrix.columns(); |
|
51 |
int[][] values = new int[rows][columns]; |
|
52 |
for (int row = rows; --row >= 0;) { |
|
53 |
int[] currentRow = values[row]; |
|
54 |
for (int column = columns; --column >= 0;) { |
|
55 |
currentRow[column] = (int) matrix.getQuick(row, column); |
|
56 |
} |
|
57 |
} |
|
58 |
return values; |
|
59 |
// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(), |
|
60 |
// matrix.columns()); |
|
61 |
// matrix.forEachNonZero(fun); |
|
62 |
// return ((CreateIntIntArray)fun).getIntIntArray(); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Double matrix2 d2 double double array. |
|
67 |
* |
|
68 |
* @param matrix the matrix |
|
69 |
* @return the double[][] |
|
70 |
*/ |
|
71 |
public final static double[][] doubleMatrix2D2DoubleDoubleArray( |
|
72 |
DoubleMatrix2D matrix) { |
|
73 |
matrix.trimToSize(); |
|
74 |
return matrix.toArray(); |
|
75 |
} |
|
76 |
|
|
77 |
/* |
|
78 |
* public final static int[][] intMatrix2D2IntIntArray (IntMatrix2D matrix) |
|
79 |
* { matrix.trimToSize(); return matrix.toArray(); } |
|
80 |
*/ |
|
81 |
|
|
82 |
/** |
|
83 |
* Transform a Colt {@link DoubleMatrix2D} into an array of <code>int</code> |
|
84 |
* . |
|
85 |
* |
|
86 |
* The value of the matrix are stored by column (the values of the first |
|
87 |
* column, then the values of the second column, etc.) |
|
88 |
* |
|
89 |
* @param matrix the matrix |
|
90 |
* @return an array of <code>int</code> |
|
91 |
* @todo use {@link DoubleMatrix2D#trimToSize()} and |
|
92 |
* {@link DoubleMatrix2D#toArray()} |
|
93 |
*/ |
|
94 |
public final static int[] doubleMatrix2D2IntArray(DoubleMatrix2D matrix) { |
|
95 |
final IntIntDoubleFunction fun = new CreateIntArray(matrix.rows(), |
|
96 |
matrix.columns()); |
|
97 |
matrix.forEachNonZero(fun); |
|
98 |
return ((CreateIntArray) fun).getIntArray(); |
|
99 |
} |
|
100 |
|
|
101 |
// public final static REXP DoubleMatrix2D2REXP(DoubleMatrix2D matrix, |
|
102 |
// Rengine engine, String varName) { |
|
103 |
// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(), |
|
104 |
// matrix.columns()); |
|
105 |
// matrix.forEachNonZero(fun); |
|
106 |
// int[][] m = ((CreateIntIntArray)fun).getIntIntArray(); |
|
107 |
// engine.assign(varName, m); |
|
108 |
// return ((CreateIntIntArray)fun).getIntIntArray(); |
|
109 |
// } |
|
110 |
|
|
111 |
/** |
|
112 |
* The Class CreateIntIntArray. |
|
113 |
*/ |
|
114 |
static class CreateIntIntArray implements IntIntDoubleFunction { |
|
115 |
|
|
116 |
/** The array. */ |
|
117 |
private final int[][] array; |
|
118 |
|
|
119 |
/** |
|
120 |
* Instantiates a new creates the int int array. |
|
121 |
* |
|
122 |
* @param rows the rows |
|
123 |
* @param columns the columns |
|
124 |
*/ |
|
125 |
public CreateIntIntArray(int rows, int columns) { |
|
126 |
array = new int[rows][columns]; |
|
127 |
for (int i = 0; i < array.length; i++) { |
|
128 |
for (int j = 0; j < array[i].length; j++) { |
|
129 |
array[i][j] = 0; |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/* (non-Javadoc) |
|
135 |
* @see cern.colt.function.IntIntDoubleFunction#apply(int, int, double) |
|
136 |
*/ |
|
137 |
@Override |
|
138 |
public double apply(int row, int col, double value) { |
|
139 |
array[row][col] = (int) value; |
|
140 |
return value; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Gets the int int array. |
|
145 |
* |
|
146 |
* @return the int int array |
|
147 |
*/ |
|
148 |
public int[][] getIntIntArray() { |
|
149 |
return array; |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* The Class CreateIntArray. |
|
155 |
*/ |
|
156 |
static class CreateIntArray implements IntIntDoubleFunction { |
|
157 |
|
|
158 |
/** The array. */ |
|
159 |
private final int[] array; |
|
160 |
|
|
161 |
/** The rows. */ |
|
162 |
private final int rows; |
|
163 |
|
|
164 |
/** |
|
165 |
* Instantiates a new creates the int array. |
|
166 |
* |
|
167 |
* @param rows the rows |
|
168 |
* @param columns the columns |
|
169 |
*/ |
|
170 |
public CreateIntArray(int rows, int columns) { |
|
171 |
array = new int[rows * columns]; |
|
172 |
for (int i = 0; i < array.length; i++) { |
|
173 |
array[i] = 0; |
|
174 |
} |
|
175 |
this.rows = rows; |
|
176 |
} |
|
177 |
|
|
178 |
/* (non-Javadoc) |
|
179 |
* @see cern.colt.function.IntIntDoubleFunction#apply(int, int, double) |
|
180 |
*/ |
|
181 |
@Override |
|
182 |
public double apply(int row, int col, double value) { |
|
183 |
array[(col * rows) + row] = (int) value; |
|
184 |
return value; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* Gets the int array. |
|
189 |
* |
|
190 |
* @return the int array |
|
191 |
*/ |
|
192 |
public int[] getIntArray() { |
|
193 |
return array; |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
} |
|
0 | 198 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/rcolt/package.html (revision 281) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Converting colt data structure into data structure suited for the R language (mainly vectorized version of matrix).</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RserveWatcher.java (revision 281) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.statsengine.r.core; |
|
29 |
|
|
30 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
31 |
import org.txm.utils.Watcher; |
|
32 |
|
|
33 |
// TODO: Auto-generated Javadoc |
|
34 |
/** |
|
35 |
* The Class RserveWatcher. |
|
36 |
*/ |
|
37 |
//FIXME: not used ? |
|
38 |
public class RserveWatcher extends Watcher { |
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Instantiates a new rserve watcher. |
|
43 |
*/ |
|
44 |
public RserveWatcher() |
|
45 |
{ |
|
46 |
this.processname = "RSERVE"; //$NON-NLS-1$ |
|
47 |
} |
|
48 |
|
|
49 |
/* (non-Javadoc) |
|
50 |
* @see org.txm.Watcher#check() |
|
51 |
*/ |
|
52 |
@Override |
|
53 |
protected boolean check() { |
|
54 |
RWorkspace rw; |
|
55 |
try { |
|
56 |
rw = RWorkspace.getRWorkspaceInstance(); |
|
57 |
} catch (RWorkspaceException e1) { |
|
58 |
System.out.println("Rserve watcher encounter an error: "+e1); //$NON-NLS-1$ |
|
59 |
return false; |
|
60 |
} |
|
61 |
|
|
62 |
if (rw == null) |
|
63 |
{ |
|
64 |
return false; |
|
65 |
} |
|
66 |
else |
|
67 |
{ |
|
68 |
try { |
|
69 |
rw.eval("print(\"test\")"); //$NON-NLS-1$ |
|
70 |
} catch (Exception e) { |
|
71 |
System.out.println("Rserve watcher encounter an error: "+e); //$NON-NLS-1$ |
|
72 |
return false; |
|
73 |
} |
|
74 |
} |
|
75 |
return true; |
|
76 |
} |
|
77 |
|
|
78 |
/* (non-Javadoc) |
|
79 |
* @see org.txm.Watcher#restart() |
|
80 |
*/ |
|
81 |
@Override |
|
82 |
protected boolean restart() { |
|
83 |
return Toolbox.restartStatEngine(true); |
|
84 |
} |
|
85 |
} |
|
0 | 86 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/StartRserve.java (revision 281) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2015-06-15 15:29:16 +0200 (Mon, 15 Jun 2015) $ |
|
25 |
// $LastChangedRevision: 2989 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.statsengine.r.core; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.rosuda.REngine.Rserve.RConnection; |
|
33 |
import org.txm.statsengine.r.core.messages.RCoreMessages; |
|
34 |
import org.txm.utils.OSDetector; |
|
35 |
import org.txm.utils.StreamHog; |
|
36 |
import org.txm.utils.logger.Log; |
|
37 |
|
|
38 |
// TODO: Auto-generated Javadoc |
|
39 |
/** |
|
40 |
* Helper class that consumes output of a process. In addition, it filter output |
|
41 |
* of the REG command on Windows to look for InstallPath registry entry which |
|
42 |
* specif ies the location of R. |
|
43 |
* |
|
44 |
* @author RServe library |
|
45 |
*/ |
|
46 |
|
|
47 |
/** |
|
48 |
* simple class that start Rserve locally if it's not running already - see |
|
49 |
* mainly <code>checkLocalRserve</code> method. It spits out quite some |
|
50 |
* debugging outout of the console, so feel free to modif y it for your |
|
51 |
* application if desired. |
|
52 |
* <p> |
|
53 |
* <i>Important:</i> All applications should shutdown every Rserve that they |
|
54 |
* started! Never leave Rserve running if you started it after your application |
|
55 |
* quits since it may pose a security risk. Inform the user if you started an |
|
56 |
* Rserve instance. |
|
57 |
*/ |
|
58 |
public class StartRserve { |
|
59 |
|
|
60 |
/** shortcut to <code>launchRserve(cmd, "--no-save --slave", "--no-save --slave", false)</code>. */ |
|
61 |
public static Process Rserveprocess; |
|
62 |
|
|
63 |
/** |
|
64 |
* Launch rserve. |
|
65 |
* |
|
66 |
* @param cmd the cmd |
|
67 |
* @param options |
|
68 |
* @return true, if successful |
|
69 |
*/ |
|
70 |
protected static boolean launchRserve(String cmd, int port, boolean debug, String rArgs, String rServeArgs) { |
|
71 |
if (new File(cmd).exists() && !new File(cmd).isDirectory() |
|
72 |
&& new File(cmd).canExecute()) |
|
73 |
return launchRserve(cmd, |
|
74 |
"--no-save --slave --encoding utf8 "+rArgs, "--RS-encoding utf8 --no-save --slave --encoding utf8 "+rServeArgs, port, debug); //$NON-NLS-1$ //$NON-NLS-2$ |
|
75 |
return false; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* attempt to start Rserve. Note: parameters are <b>not</b> quoted, so avoid |
|
80 |
* using any quotes in arguments |
|
81 |
* |
|
82 |
* @param cmd command necessary to start R |
|
83 |
* @param rargs arguments are are to be passed to R |
|
84 |
* @param rsrvargs arguments to be passed to Rserve |
|
85 |
* @param debug the debug |
|
86 |
* @return <code>true</code> if Rserve is running or was successfully |
|
87 |
* started, <code>false</code> otherwise. |
|
88 |
*/ |
|
89 |
protected static boolean launchRserve(String cmd, String rargs, |
|
90 |
String rsrvargs, int port, boolean debug) { |
|
91 |
//System.out.println("LAUNCH R SERVER "+cmd+" "+port+" "+debug); |
|
92 |
try { |
|
93 |
String[] cmdline = null; |
|
94 |
// FIXME: don't forget to remove this Window dedicated code if we manage to use http_proxy command line argument |
|
95 |
boolean isWindows = false; |
|
96 |
|
|
97 |
// Windows OS |
|
98 |
if (OSDetector.isFamilyWindows()) { |
|
99 |
isWindows = true; /* Windows startup */ |
|
100 |
|
|
101 |
|
|
102 |
// TODO: old tests for setting proxy in R |
|
103 |
//Windows : set --internet2 option to manage proxy if any |
|
104 |
|
|
105 |
// // set Proxy configuration using Eclipse RCP stored values |
|
106 |
// String proxy_conf = ""; |
|
107 |
// ProxyConf conf = new ProxyConf(RWorkspace.getRWorkspaceInstance()); |
|
108 |
// if (conf.mustSetProxyConfiguration()) { |
|
109 |
// proxy_conf = "http_proxy="+conf.getHttpProxyUrl(); |
|
110 |
// rsrvargs += " "+proxy_conf; // add the http_proxy parameter |
|
111 |
// Log.info("Run Rserve with proxy configuration: "+proxy_conf); |
|
112 |
// } |
|
113 |
|
|
114 |
cmdline = new String[] { |
|
115 |
cmd, |
|
116 |
rargs, |
|
117 |
"-e", //$NON-NLS-1$ |
|
118 |
"library(Rserve);Rserve(" //$NON-NLS-1$ |
|
119 |
+ (debug ? "TRUE" : "FALSE") //$NON-NLS-1$ //$NON-NLS-2$ |
|
120 |
+ ",port=" + port + "" //$NON-NLS-1$ //$NON-NLS-2$ |
|
121 |
+ ",args='" //$NON-NLS-1$ |
|
122 |
+ rsrvargs + "')\" " //$NON-NLS-1$ |
|
123 |
}; |
|
124 |
} |
|
125 |
// Mac, Linux |
|
126 |
else { |
|
127 |
cmdline = new String[] { |
|
128 |
"/bin/sh", //$NON-NLS-1$ |
|
129 |
"-c", //$NON-NLS-1$ |
|
130 |
"echo 'library(Rserve);Rserve(" //$NON-NLS-1$ |
|
131 |
+ (debug ? "TRUE" : "FALSE") //$NON-NLS-1$ //$NON-NLS-2$ |
|
132 |
+ ",port="+port+"" //$NON-NLS-1$ //$NON-NLS-2$ |
|
133 |
+ ",args=\"" + rsrvargs //$NON-NLS-1$ |
|
134 |
+ "\")'|" + cmd //$NON-NLS-1$ |
|
135 |
+ " " + rargs }; //$NON-NLS-1$ |
|
136 |
} |
|
137 |
|
|
138 |
// ProcessBuilder builder = new ProcessBuilder(cmdline); |
|
139 |
// Rserveprocess = builder.start(); |
|
140 |
|
|
141 |
Runtime runtime = Runtime.getRuntime(); |
|
142 |
Rserveprocess = runtime.exec(cmdline); |
|
143 |
|
|
144 |
//Log.info(Messages.StartRserve_0+Arrays.toString(cmdline)); |
|
145 |
StreamHog errStream = new StreamHog(Rserveprocess.getErrorStream(), debug); |
|
146 |
StreamHog inStream = new StreamHog(Rserveprocess.getInputStream(), debug); |
|
147 |
RWorkspace.getRWorkspaceInstance().registerLogger(errStream, inStream); |
|
148 |
|
|
149 |
if (!debug && !isWindows) |
|
150 |
Rserveprocess.waitFor(); |
|
151 |
// System.out.println("call terminated, let us try to connect ..."); |
|
152 |
} catch (Exception x) { |
|
153 |
System.err.println(RCoreMessages.StartRserve_21 + x.getMessage()); |
|
154 |
return false; |
|
155 |
} |
|
156 |
|
|
157 |
System.err.print(RCoreMessages.StartRserve_22); |
|
158 |
|
|
159 |
try { |
|
160 |
Thread.sleep(200); |
|
161 |
} catch (InterruptedException ix) { } |
|
162 |
|
|
163 |
int attempts = 20; |
|
164 |
while (attempts > 0) { |
|
165 |
try { |
|
166 |
System.out.print("."); //$NON-NLS-1$ |
|
167 |
RConnection c = new RConnection("127.0.0.1", port); //$NON-NLS-1$ |
|
168 |
c.close(); |
|
169 |
return true; |
|
170 |
} catch (Exception e2) { |
|
171 |
try { |
|
172 |
Thread.sleep(2000); |
|
173 |
} catch (InterruptedException ix) { } |
|
174 |
} |
|
175 |
|
|
176 |
attempts--; |
|
177 |
} |
|
178 |
System.out.println(""); //$NON-NLS-1$ |
|
179 |
return false; |
|
180 |
} |
|
181 |
|
|
182 |
/** |
|
183 |
* checks whether Rserve is running and if that's not the case it attempts |
|
184 |
* to start it using the defaults for the platform where it is run on. This |
|
185 |
* method is meant to be set-and-forget and cover most default setups. For |
|
186 |
* special setups you may get more control over R with < |
|
187 |
* <code>launchRserve</code> instead. |
|
188 |
* @param rServeArgs |
|
189 |
* @param rargs |
|
190 |
* |
|
191 |
* @return true, if successful |
|
192 |
*/ |
|
193 |
protected static boolean checkLocalRserve(int port, boolean debug, String rargs, String rServeArgs) { |
|
194 |
Log.info(RCoreMessages.StartRserve_2); |
|
195 |
if (isRserveRunning(port)) { |
|
196 |
Log.info(RCoreMessages.StartRserve_3+port); |
|
197 |
return true; |
|
198 |
} |
|
199 |
// Windows OS |
|
200 |
if (OSDetector.isFamilyWindows()) { |
|
201 |
// System.out.println("Windows: query registry to find where R is installed ..."); |
|
202 |
String installPath = null; |
|
203 |
try { |
|
204 |
Process rp = Runtime.getRuntime().exec( |
|
205 |
"reg query HKLM\\Software\\R-core\\R"); //$NON-NLS-1$ |
|
206 |
StreamHog regHog = new StreamHog(rp.getInputStream(), true); |
|
207 |
rp.waitFor(); |
|
208 |
regHog.join(); |
|
209 |
installPath = regHog.getInstallPath(); |
|
210 |
} catch (Exception rge) { |
|
211 |
System.err.println(RCoreMessages.StartRserve_28 + rge); |
|
212 |
return false; |
|
213 |
} |
|
214 |
if (installPath == null) { |
|
215 |
System.err.println(RCoreMessages.StartRserve_29); |
|
216 |
return false; |
|
217 |
} |
|
218 |
// System.out.println(" Found R in : "+installPath + |
|
219 |
// "\\bin\\R.exe"); |
|
220 |
return launchRserve(installPath + "\\bin\\R.exe", port, debug, rargs, rServeArgs); //$NON-NLS-1$ |
|
221 |
} |
|
222 |
|
|
223 |
Log.info(RCoreMessages.StartRserve_4); |
|
224 |
if (launchRserve("R", port, debug, rargs, rServeArgs)) return true; //$NON-NLS-1$ |
|
225 |
|
|
226 |
// R not in the PATH env, try with R common paths |
|
227 |
String[] paths = { |
|
228 |
"/Library/Frameworks/R.framework/Resources/bin/R", //$NON-NLS-1$ |
|
229 |
"/usr/local/lib/R/bin/R", //$NON-NLS-1$ |
|
230 |
"/usr/lib/R/bin/R", //$NON-NLS-1$ |
|
231 |
"/sw/bin/R", //$NON-NLS-1$ |
|
232 |
"/usr/common/bin/R", //$NON-NLS-1$ |
|
233 |
"/opt/bin/R" }; //$NON-NLS-1$ |
|
234 |
for (String path : paths) { |
|
235 |
Log.info(RCoreMessages.StartRserve_6+path); |
|
236 |
if (new File(path).exists() && launchRserve(path, port, debug, rargs, rServeArgs)) return true; |
|
237 |
} |
|
238 |
|
|
239 |
return false; |
|
240 |
// |
|
241 |
// return (launchRserve("R", port, debug) //$NON-NLS-1$ |
|
242 |
// || /* try some common unix locations of R */ |
|
243 |
// (( && launchRserve("/Library/Frameworks/R.framework/Resources/bin/R", port, debug)) //$NON-NLS-1$ |
|
244 |
// || ((new File("/usr/local/lib/R/bin/R")).exists() && launchRserve("/usr/local/lib/R/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$ |
|
245 |
// || ((new File("/usr/lib/R/bin/R")).exists() && launchRserve("/usr/lib/R/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$ |
|
246 |
// || ((new File("/usr/local/bin/R")).exists() && launchRserve("/usr/local/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$ |
|
247 |
// || ((new File("/sw/bin/R")).exists() && launchRserve("/sw/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$ |
|
248 |
// || ((new File("/usr/common/bin/R")).exists() && launchRserve("/usr/common/bin/R")) || ((new File( //$NON-NLS-1$ //$NON-NLS-2$ |
|
249 |
// "/opt/bin/R")).exists() && launchRserve("/opt/bin/R"))); //$NON-NLS-1$ //$NON-NLS-2$ |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* check whether Rserve is currently running (on local machine and default |
|
254 |
* port). |
|
255 |
* |
|
256 |
* @return <code>true</code> if local Rserve instance is running, |
|
257 |
* <code>false</code> otherwise |
|
258 |
*/ |
|
259 |
protected static boolean isRserveRunning(int port) { |
|
260 |
try { |
|
261 |
new RConnection("127.0.0.1", port); //$NON-NLS-1$ |
|
262 |
// System.out.println("Rserve is running."); |
|
263 |
// c.close(); |
|
264 |
return true; |
|
265 |
} catch (Exception e) { |
|
266 |
// System.out.println("First connect try failed with: "+ |
|
267 |
// e.getMessage()); |
|
268 |
} |
|
269 |
return false; |
|
270 |
} |
|
271 |
|
|
272 |
|
|
273 |
public static void main(String[] args) { |
|
274 |
System.out.println("result=" + checkLocalRserve(8212, false, "", "")); |
|
275 |
try { |
|
276 |
System.out.println("Start RServe"); |
|
277 |
RConnection c = new RConnection("localhost", 8212); |
|
278 |
System.out.println("Stop RServe"); |
|
279 |
c.eval("print(1+1)"); |
|
280 |
c.eval("2+2"); |
|
281 |
c.shutdown(); |
|
282 |
System.out.println("Done"); |
|
283 |
} catch (Exception x) { |
|
284 |
x.printStackTrace(); |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
0 | 288 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RStatsEngine.java (revision 281) | ||
---|---|---|
1 |
package org.txm.statsengine.r.core; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.txm.core.preferences.TXMPreferences; |
|
6 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
7 |
import org.txm.statsengine.r.core.messages.RCoreMessages; |
|
8 |
import org.txm.statsengine.r.core.preferences.RPreferences; |
|
9 |
import org.txm.utils.OSDetector; |
|
10 |
import org.txm.utils.logger.Log; |
|
11 |
|
|
12 |
/** |
|
13 |
* R statistics engine. Contains methods to start, stop, kill, etc. the R and RServe process. |
|
14 |
* |
|
15 |
* @author mdecorde |
|
16 |
* @author sjacquot |
|
17 |
* |
|
18 |
*/ |
|
19 |
public class RStatsEngine { |
|
20 |
|
|
21 |
|
|
22 |
/** The state of the stats engine. */ |
|
23 |
private static boolean started = false; |
|
24 |
|
|
25 |
|
|
26 |
private static boolean mandatory = false; |
|
27 |
|
|
28 |
|
|
29 |
private RStatsEngine() { |
|
30 |
// no instantiation |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* start the statengine if the engine is not remote then launch Rserve. |
|
36 |
* |
|
37 |
* @return true, if successful |
|
38 |
*/ |
|
39 |
public static boolean start() { |
|
40 |
try { |
|
41 |
|
|
42 |
if (TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.DISABLE)) { |
|
43 |
System.err.println("Warning, Statistics Engine is disabled."); |
|
44 |
return false; |
|
45 |
} |
|
46 |
|
|
47 |
Log.warning("Starting Statistics Engine."); |
|
48 |
|
|
49 |
// try launching R server and connecting to it |
|
50 |
int port = TXMPreferences.getInt(RPreferences.PREFERENCES_NODE, RPreferences.PORT); |
|
51 |
String user = TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.USER); |
|
52 |
String password = TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.PASSWORD); |
|
53 |
boolean remote = TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.REMOTE); |
|
54 |
boolean debug = TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.DEBUG); |
|
55 |
mandatory = TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.IS_MANDATORY); |
|
56 |
|
|
57 |
|
|
58 |
Log.info(RCoreMessages.Log_STARTING_STATS_ENGINE + user + RCoreMessages.Log_REMOTE + remote + RCoreMessages.Log_PORT + port + RCoreMessages.Log_DEBUG + debug); |
|
59 |
// System.out.println("test remote :" + R_PATH_TO_EXECUTABLE + ":" + properties.getProperty(R_PATH_TO_EXECUTABLE)); |
|
60 |
if (!remote) { |
|
61 |
// start Rserve executable |
|
62 |
started = RWorkspace.startExec( |
|
63 |
TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.PATH_TO_EXECUTABLE), |
|
64 |
port, |
|
65 |
debug, |
|
66 |
TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.RARGS), |
|
67 |
TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.RSERVEARGS)); |
|
68 |
|
|
69 |
if (started) { // try connecting to R witout login |
|
70 |
started = RWorkspace.connect("127.0.0.1", port); //$NON-NLS-1$ |
|
71 |
} |
|
72 |
} else { // try connecting to R, with login and password |
|
73 |
started = RWorkspace.connect(TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.SERVER_ADDRESS), port, user, password); |
|
74 |
} |
|
75 |
|
|
76 |
if (started) { // post configuration of R |
|
77 |
String rPackagesPath = TXMPreferences.getString(RPreferences.PREFERENCES_NODE, RPreferences.PACKAGES_PATH); |
|
78 |
started = RWorkspace.getRWorkspaceInstance().postConfiguration(rPackagesPath); |
|
79 |
} |
|
80 |
|
|
81 |
//System.out.println("try to set R_FILE_TRANSFERT to " + TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.R_FILE_TRANSFERT)); |
|
82 |
RWorkspace.setUseFileCommunication(TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.FILE_TRANSFERT)); |
|
83 |
// System.out.println("success"); |
|
84 |
//System.out.println("file transfert ? "+RWorkspace.isFileTranfert()); |
|
85 |
} catch (RWorkspaceException e) { |
|
86 |
System.err.println(RCoreMessages.Error_CONNECTION_FAILED_2); |
|
87 |
started = false; |
|
88 |
} |
|
89 |
|
|
90 |
return started; |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
/** |
|
95 |
* kill Rserve process. |
|
96 |
*/ |
|
97 |
public static void kill() { |
|
98 |
if (!TXMPreferences.getBoolean(RPreferences.PREFERENCES_NODE, RPreferences.REMOTE)) { |
|
99 |
// Windows OS |
|
100 |
if (OSDetector.isFamilyWindows()) { |
|
101 |
try { |
|
102 |
Process p = Runtime.getRuntime().exec( |
|
103 |
//"taskkill /IM Rserve.exe /F"); //$NON-NLS-1$ |
|
104 |
"cmd /c FOR /F \"tokens=5 delims= \" %P IN ('netstat -ano ^| findstr :6330 ^| findstr LISTENING') DO taskkill /F /PID %P"); //$NON-NLS-1$ |
|
105 |
|
|
106 |
p.waitFor(); |
|
107 |
started = false; |
|
108 |
} catch (IOException e) { |
|
109 |
Log.severe(RCoreMessages.Error_FAILED_TO_KILL_RSERVE+Log.toString(e)); |
|
110 |
System.out.println(RCoreMessages.Error_FAILED_TO_KILL_RSERVE+Log.toString(e)); |
|
111 |
try { |
|
112 |
Process p = Runtime.getRuntime().exec( |
|
113 |
//"tskill Rserve.exe"); //$NON-NLS-1$ |
|
114 |
"cmd /c FOR /F \"tokens=5 delims= \" %P IN ('netstat -ano ^| findstr :6330 ^| findstr LISTENING') DO tskill %P"); //$NON-NLS-1$ |
|
115 |
p.waitFor(); |
|
116 |
started = false; |
|
117 |
} catch (IOException e2) { |
|
118 |
Log.severe(RCoreMessages.Error_FAILED_TO_KILL_RSERVE_2+Log.toString(e2)); |
|
119 |
System.out.println(RCoreMessages.Error_FAILED_TO_KILL_RSERVE_2+Log.toString(e2)); |
|
120 |
Log.printStackTrace(e2); |
|
121 |
} catch (InterruptedException e3) { |
|
122 |
Log.severe(Log.toString(e3)); |
|
123 |
System.out.println(Log.toString(e3)); |
|
124 |
org.txm.utils.logger.Log.printStackTrace(e3); |
|
125 |
} |
|
126 |
} catch (InterruptedException e) { |
|
127 |
Log.severe("Error while closing R: " + e.getLocalizedMessage()); |
|
128 |
System.out.println(Log.toString(e)); |
|
129 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
130 |
} |
|
131 |
} |
|
132 |
// Mac, Linux |
|
133 |
else { |
|
134 |
try { |
|
135 |
Process p = Runtime.getRuntime().exec( |
|
136 |
"kill -9 `lsof -t -a -c Rserve-bin.so -i : " + TXMPreferences.getInt(RPreferences.PREFERENCES_NODE, RPreferences.PORT) + "`"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
137 |
p.waitFor(); |
|
138 |
started = false; |
|
139 |
} catch (IOException e) { |
|
140 |
Log.severe(RCoreMessages.Error_FAILED_TO_KILL_RSERVE_3 + Log.toString(e)); |
|
141 |
System.out.println(RCoreMessages.Error_FAILED_TO_KILL_RSERVE_3 + Log.toString(e)); |
|
142 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
143 |
} catch (InterruptedException e) { |
|
144 |
Log.severe("Error while closing R: " + e.getLocalizedMessage()); |
|
145 |
System.out.println(Log.toString(e)); |
|
146 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
/** |
|
154 |
* Shut the stats engine down. |
|
155 |
*/ |
|
156 |
public static void shutdown() { |
|
157 |
try { |
|
158 |
RWorkspace.shutdown(); |
|
159 |
RStatsEngine.kill(); |
|
160 |
started = false; |
|
161 |
} catch (Exception e) { |
|
162 |
Log.severe("Error while closing R: " + e.getLocalizedMessage()); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Retuns the running state of the stats engine. |
|
168 |
*/ |
|
169 |
public static boolean isStarted() { |
|
170 |
return started; |
|
171 |
} |
|
172 |
|
|
173 |
|
|
174 |
/** |
|
175 |
* @return the mandatory |
|
176 |
*/ |
|
177 |
public static boolean isMandatory() { |
|
178 |
return mandatory; |
|
179 |
} |
|
180 |
|
|
181 |
} |
|
0 | 182 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RFileCommunication.java (revision 281) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2015-05-22 09:06:15 +0200 (Fri, 22 May 2015) $ |
|
25 |
// $LastChangedRevision: 2973 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.statsengine.r.core; |
|
29 |
|
|
30 |
import java.io.BufferedWriter; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileWriter; |
|
33 |
import java.io.IOException; |
|
34 |
|
|
35 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
|
36 |
import org.txm.utils.OSDetector; |
|
37 |
|
|
38 |
|
|
39 |
// TODO: Auto-generated Javadoc |
|
40 |
/** |
|
41 |
* The Class RFileCommunication. |
|
42 |
*/ |
|
43 |
public class RFileCommunication { |
|
44 |
|
|
45 |
/** The transfertfile. */ |
|
46 |
File transfertfile; |
|
47 |
|
|
48 |
/** The transfertfilepath. */ |
|
49 |
String transfertfilepath; |
|
50 |
|
|
51 |
/** |
|
52 |
* Instantiates a new r file communication. |
|
53 |
* |
|
54 |
* @throws IOException Signals that an I/O exception has occurred. |
|
55 |
*/ |
|
56 |
public RFileCommunication() throws IOException |
|
57 |
{ |
|
58 |
createTempFile(); |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Creates the temp file. |
|
64 |
* |
|
65 |
* @throws IOException Signals that an I/O exception has occurred. |
|
66 |
*/ |
|
67 |
public void createTempFile() throws IOException |
|
68 |
{ |
|
69 |
transfertfile = File.createTempFile("Rtransfert","file"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
70 |
//transfertfile = new File("~/Bureau/RTRANSFERT.txt"); |
|
71 |
transfertfilepath = transfertfile.getAbsolutePath(); |
|
72 |
if (OSDetector.isFamilyWindows()) //$NON-NLS-1$ //$NON-NLS-2$ |
|
73 |
{ |
|
74 |
//System.out.println("patch path"); |
|
75 |
transfertfilepath = transfertfilepath.replace("\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
76 |
} |
|
77 |
//System.out.println("Transfert file: "+transfertfilepath); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Assign. |
|
82 |
* |
|
83 |
* @param variablename the variablename |
|
84 |
* @param matrix the matrix |
|
85 |
* @param nrow the nrow |
|
86 |
* @param ncol the ncol |
|
87 |
* @throws RWorkspaceException the r workspace exception |
|
88 |
*/ |
|
89 |
public void assign(String variablename, int[] matrix, int nrow, int ncol) throws RWorkspaceException |
|
90 |
{ |
|
91 |
writeVector(matrix); |
|
92 |
RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
93 |
RWorkspace.getRWorkspaceInstance().eval(variablename+" <- matrix(vectorint, nrow="+nrow+", ncol="+ncol+", byrow=T);"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* Assign. |
|
98 |
* |
|
99 |
* @param variablename the variablename |
|
100 |
* @param matrix the matrix |
|
101 |
* @param nrow the nrow |
|
102 |
* @param ncol the ncol |
|
103 |
* @throws RWorkspaceException the r workspace exception |
|
104 |
*/ |
|
105 |
public void assign(String variablename, double[] matrix, int nrow, int ncol) throws RWorkspaceException |
|
106 |
{ |
|
107 |
writeVector(matrix); |
|
108 |
RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
109 |
RWorkspace.getRWorkspaceInstance().eval(variablename+" <- matrix(vectordouble, nrow="+nrow+", ncol="+ncol+", byrow=T);"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Assign. |
|
114 |
* |
|
115 |
* @param variablename the variablename |
|
116 |
* @param vector the vector |
|
117 |
* @throws RWorkspaceException the r workspace exception |
|
118 |
*/ |
|
119 |
public void assign(String variablename, int[] vector) throws RWorkspaceException |
|
120 |
{ |
|
121 |
//System.out.println("assign vector "+variablename+" size "+vector.length); |
|
122 |
writeVector(vector); |
|
123 |
RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
124 |
RWorkspace.getRWorkspaceInstance().eval(variablename+" <- vectorint;"); //$NON-NLS-1$ |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Assign. |
|
129 |
* |
|
130 |
* @param variablename the variablename |
|
131 |
* @param vector the vector |
|
132 |
* @throws RWorkspaceException the r workspace exception |
|
133 |
*/ |
|
134 |
public void assign(String variablename, double[] vector) throws RWorkspaceException |
|
135 |
{ |
|
136 |
//System.out.println("assign vector "+variablename+" size "+vector.length); |
|
137 |
writeVector(vector); |
|
138 |
RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
139 |
RWorkspace.getRWorkspaceInstance().eval(variablename+" <- vectordouble;"); //$NON-NLS-1$ |
|
140 |
|
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Assign. |
|
145 |
* |
|
146 |
* @param variablename the variablename |
|
147 |
* @param vector the vector |
|
148 |
* @throws RWorkspaceException the r workspace exception |
|
149 |
*/ |
|
150 |
public void assign(String variablename, String[] vector) throws RWorkspaceException |
|
151 |
{ |
|
152 |
//System.out.println("assign vector "+variablename+" size "+vector.length); |
|
153 |
writeVector(vector); |
|
154 |
RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
155 |
RWorkspace.getRWorkspaceInstance().eval(variablename+" <- vectorstr;"); //$NON-NLS-1$ |
|
156 |
} |
|
157 |
|
|
158 |
/* |
|
159 |
public boolean writeMatrix(int[][] matrix) |
|
160 |
{ |
|
161 |
//System.out.println("WRITE MATRIX"); |
|
162 |
try { |
|
163 |
BufferedWriter writer = new BufferedWriter(new FileWriter(transfertfilepath)); |
|
164 |
for(int i = 0 ; i < matrix.length ; i++) |
|
165 |
{ |
|
166 |
StringBuffer str = new StringBuffer(); |
|
167 |
for(int j = 0 ; j < matrix[i].length ; j++) |
|
168 |
if (j == matrix[i].length -1) |
|
169 |
str.append(matrix[i][j]); |
|
170 |
else |
|
171 |
str.append(""+matrix[i][j]+"\t"); |
|
172 |
writer.write(str.toString()+"\n"); |
|
173 |
} |
|
174 |
writer.close(); |
|
175 |
} catch (IOException e) { |
|
176 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
177 |
return false; |
|
178 |
} |
|
179 |
return true; |
|
180 |
} |
|
181 |
|
|
182 |
public boolean writeMatrix(double[][] matrix) |
|
183 |
{ |
|
184 |
//System.out.println("WRITE MATRIX"); |
|
185 |
try { |
|
186 |
BufferedWriter writer = new BufferedWriter(new FileWriter(transfertfilepath)); |
|
187 |
for(int i = 0 ; i < matrix.length ; i++) |
|
188 |
{ |
|
189 |
StringBuffer str = new StringBuffer(); |
|
190 |
for(int j = 0 ; j < matrix[i].length ; j++) |
|
191 |
if (j == matrix[i].length -1) |
|
192 |
str.append(matrix[i][j]); |
|
193 |
else |
|
194 |
str.append(""+matrix[i][j]+"\t"); |
|
195 |
writer.write(str.toString()+"\n"); |
|
196 |
} |
|
197 |
writer.close(); |
|
198 |
} catch (IOException e) { |
|
199 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
200 |
return false; |
|
201 |
} |
|
202 |
return true; |
|
203 |
} |
|
204 |
|
|
205 |
*/ |
|
206 |
/** |
|
207 |
* Write vector. |
|
208 |
* |
|
209 |
* @param vector the vector |
|
210 |
* @return true, if successful |
|
211 |
*/ |
|
212 |
private boolean writeVector(String[] vector) { |
|
213 |
//System.out.println("WRITE VECTOR"); |
|
214 |
try { |
|
215 |
BufferedWriter writer = new BufferedWriter(new FileWriter(transfertfilepath)); |
|
216 |
|
|
217 |
StringBuffer str = new StringBuffer(); |
|
218 |
str.append("vectorstr <- c("); //$NON-NLS-1$ |
|
219 |
for(int j = 0 ; j < vector.length ; j++) |
|
220 |
if (j == vector.length -1) |
|
221 |
str.append("\""+vector[j]+"\""); //$NON-NLS-1$ //$NON-NLS-2$ |
|
222 |
else |
|
223 |
str.append("\""+vector[j]+"\", "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
224 |
str.append(");"); //$NON-NLS-1$ |
|
225 |
writer.write(str.toString()); |
|
226 |
|
|
227 |
writer.close(); |
|
228 |
} catch (IOException e) { |
|
229 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
230 |
return false; |
|
231 |
} |
|
232 |
return true; |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Write vector. |
|
237 |
* |
|
238 |
* @param vector the vector |
|
239 |
* @return true, if successful |
|
240 |
*/ |
|
241 |
public boolean writeVector(int[] vector) |
|
242 |
{ |
|
243 |
//System.out.println("WRITE VECTOR"); |
|
244 |
try { |
|
245 |
BufferedWriter writer = new BufferedWriter(new FileWriter(transfertfilepath)); |
|
246 |
|
|
247 |
StringBuffer str = new StringBuffer(); |
|
248 |
str.append("vectorint <- as.integer(c("); //$NON-NLS-1$ |
|
249 |
for(int j = 0 ; j < vector.length ; j++) |
|
250 |
if (j == vector.length -1) |
|
251 |
str.append(vector[j]); |
|
252 |
else |
|
253 |
str.append(""+vector[j]+", "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
254 |
str.append("));"); //$NON-NLS-1$ |
|
255 |
writer.write(str.toString()); |
|
256 |
writer.close(); |
|
257 |
} catch (IOException e) { |
|
258 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
259 |
return false; |
|
260 |
} |
|
261 |
return true; |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* Write vector. |
|
266 |
* |
|
267 |
* @param vector the vector |
|
268 |
* @return true, if successful |
|
269 |
*/ |
|
270 |
public boolean writeVector(double[] vector) |
|
271 |
{ |
|
272 |
//System.out.println("WRITE VECTOR"); |
|
273 |
try { |
|
274 |
BufferedWriter writer = new BufferedWriter(new FileWriter(transfertfilepath)); |
|
275 |
|
|
276 |
StringBuffer str = new StringBuffer(); |
|
277 |
str.append("vectordouble <- c("); //$NON-NLS-1$ |
|
278 |
for(int j = 0 ; j < vector.length ; j++) |
|
279 |
{ |
|
280 |
if (j == vector.length -1) |
|
281 |
str.append(vector[j]); |
|
282 |
else |
|
283 |
str.append(""+vector[j]+", "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
284 |
} |
|
285 |
str.append(");"); //$NON-NLS-1$ |
|
286 |
writer.write(str.toString()); |
|
287 |
writer.close(); |
|
288 |
} catch (IOException e) { |
|
289 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
290 |
return false; |
|
291 |
} |
|
292 |
return true; |
|
293 |
} |
|
294 |
|
|
295 |
/** |
|
296 |
* The main method. |
|
297 |
* |
|
298 |
* @param args the arguments |
|
299 |
*/ |
|
300 |
public static void main(String[] args) |
|
301 |
{ |
|
302 |
double[][] matrix ={{1,2,3}, {4,5,6}, {7,8,9}}; |
|
303 |
RFileCommunication comm; |
|
304 |
try { |
|
305 |
comm = new RFileCommunication(); |
|
306 |
} catch (IOException e) { |
|
307 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
308 |
return; |
|
309 |
} |
|
310 |
|
|
311 |
//comm.writeMatrix(matrix); |
|
312 |
} |
|
313 |
} |
|
0 | 314 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/messages/RCoreMessages.java (revision 281) | ||
---|---|---|
1 |
package org.txm.statsengine.r.core.messages; |
|
2 |
|
|
3 |
import org.eclipse.osgi.util.NLS; |
|
4 |
import org.txm.utils.messages.Utf8NLS; |
|
5 |
|
|
6 |
public class RCoreMessages extends NLS { |
|
7 |
|
|
8 |
private static final String BUNDLE_NAME = "org.txm.statsengine.r.core.messages.messages"; //$NON-NLS-1$ |
|
9 |
|
|
10 |
|
|
11 |
public static String Error_STATS_ENGINE_NOT_READY_CANCELING_COMMAND; |
|
12 |
|
|
13 |
public static String Log_STARTING_STATS_ENGINE; |
|
14 |
public static String Log_REMOTE; |
|
15 |
public static String Log_PORT; |
|
16 |
public static String Log_DEBUG; |
|
17 |
|
|
18 |
public static String Error_CONNECTION_FAILED_2; |
|
19 |
public static String Error_FAILED_TO_KILL_RSERVE; |
|
20 |
public static String Error_FAILED_TO_KILL_RSERVE_2; |
|
21 |
public static String Error_FAILED_TO_KILL_RSERVE_3; |
|
22 |
|
|
23 |
public static String StartRserve_2; |
|
24 |
public static String StartRserve_21; |
|
25 |
public static String StartRserve_22; |
|
26 |
public static String StartRserve_28; |
|
27 |
public static String StartRserve_29; |
|
28 |
public static String StartRserve_3; |
|
29 |
public static String StartRserve_4; |
|
30 |
public static String StartRserve_6; |
|
31 |
|
|
32 |
public static String RWorkspace_0; |
|
33 |
public static String RWorkspace_1; |
|
34 |
public static String RWorkspace_10; |
|
35 |
public static String RWorkspace_11; |
|
36 |
public static String RWorkspace_2; |
|
37 |
public static String RWorkspace_3; |
|
38 |
public static String RWorkspace_6; |
|
39 |
public static String RWorkspace_7; |
|
40 |
public static String RWorkspace_8; |
|
41 |
|
|
42 |
public static String LIBRARY_NOT_LOADED; |
|
43 |
|
|
44 |
public static String RException_0; |
|
45 |
public static String RException_1; |
|
46 |
public static String RException_2; |
|
47 |
|
|
48 |
public static String RSERVE_PATH_NOT_SET_ERROR; |
|
49 |
public static String RSERVE_PATH_SET_ERROR; |
|
50 |
public static String CONNECTED_TO_STATS_MODULE; |
|
51 |
public static String CHAR_VECTOR_ADDED_TO_WORKSPACE; |
|
52 |
public static String CONNECTION_OK; |
|
53 |
public static String ERROR_EXTRACT_ITEM; |
|
54 |
public static String REQUESTED_OBJECT_NOT_FOUND_IN_R; |
|
55 |
|
|
56 |
|
|
57 |
// FIXME: unused keys |
|
58 |
public static String StartRserve_0; |
|
59 |
public static String RWorkspace_21; |
|
60 |
public static String RSERVE_ACTIVATED; |
|
61 |
public static String R_EXPR; |
|
62 |
public static String R_READ_CONSOLE; |
|
63 |
public static String R_SAVE_HISTORY; |
|
64 |
public static String R_SHOW_MESSAGE; |
|
65 |
public static String R_WRITE_CONSOLE; |
|
66 |
//end of fixme |
|
67 |
|
|
68 |
static { |
|
69 |
// initialize resource bundle |
|
70 |
Utf8NLS.initializeMessages(BUNDLE_NAME, RCoreMessages.class); |
|
71 |
} |
|
72 |
|
|
73 |
private RCoreMessages() { |
|
74 |
} |
|
75 |
} |
|
0 | 76 |
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/messages/messages.properties (revision 281) | ||
---|---|---|
1 |
|
|
2 |
Error_CONNECTION_FAILED_2 = ** Error while connecting to the stat engine. |
|
3 |
Error_FAILED_TO_KILL_RSERVE = Failed to exec 'taskkill /IM Rserve.exe /F': |
|
4 |
Error_FAILED_TO_KILL_RSERVE_2 = Failed to exec 'tskill Rserve.exe': |
|
5 |
Error_FAILED_TO_KILL_RSERVE_3 = Failed to exec 'killall -9 Rserve-bin.so': |
|
6 |
Error_STATS_ENGINE_NOT_READY_CANCELING_COMMAND = Statistics Engine is not ready, canceling command. |
|
7 |
|
|
8 |
LIBRARY_NOT_LOADED = Failed to load the {0} library: {1} |
|
9 |
|
|
10 |
Log_DEBUG = debug: |
|
11 |
Log_PORT = \ port: |
|
12 |
Log_REMOTE = \ remote: |
|
13 |
Log_STARTING_STATS_ENGINE = Starting Statistics Engine: user: |
|
14 |
|
|
15 |
RException_0 = ** R error: " |
|
16 |
RException_1 = " |
|
17 |
RException_2 = \nwhile evaluating: |
|
18 |
|
|
19 |
RSERVE_ACTIVATED = Statistics Engine running |
|
20 |
RSERVE_PATH_NOT_SET_ERROR = ** The Statistics Engine program path is not set and we could not find it |
|
21 |
RSERVE_PATH_SET_ERROR = ** The Statistics Engine program path is set but we couldn't find it |
|
22 |
|
|
23 |
RWorkspace_0 = ** Failed to connect to the R Workspace |
|
24 |
RWorkspace_1 = ** Evaluation Error: |
|
25 |
RWorkspace_10 = Starting R using path: |
|
26 |
RWorkspace_11 = Last safeeval: |
|
27 |
RWorkspace_2 = try : connect to R at |
|
28 |
RWorkspace_21 = Full command: |
|
29 |
RWorkspace_3 = Saving graphic in file |
|
30 |
RWorkspace_6 = ** Failed to initialize file transfert: |
|
31 |
RWorkspace_7 = Matrix is empty |
|
32 |
RWorkspace_8 = Failed to start RServe : |
|
33 |
|
|
34 |
R_EXPR = Expression sent to the Statistics Engine for evaluation: {0}. |
|
35 |
R_READ_CONSOLE = The Statistics Engine waits for something to read from the console ({0}, {1}). |
|
36 |
R_SAVE_HISTORY = The Statistics Engine has saved an history ({0}). |
|
37 |
R_SHOW_MESSAGE = The Statistics Engine displayed this message: {0}. |
|
38 |
R_WRITE_CONSOLE = The Statistics Engine displayed this message in the console: {0}. |
|
39 |
|
|
40 |
StartRserve_0 = Starting R with command line: |
|
41 |
StartRserve_2 = No R path given, trying to find it... |
|
42 |
StartRserve_21 = ** Failed to start Rserve with command: |
|
43 |
StartRserve_22 = Statistical Engine launched |
|
44 |
StartRserve_28 = ** Failed to run REG to find the location of R program: |
|
45 |
StartRserve_29 = \ You need the 'R' software and you need to configure in the 'Tools/Preferences' window the correct path to it. |
|
46 |
StartRserve_3 = Rserve already running on port |
|
47 |
StartRserve_4 = try R path : 'R' |
|
48 |
StartRserve_6 = try R path : |
|
49 |
|
|
50 |
|
|
51 |
CHAR_VECTOR_ADDED_TO_WORKSPACE = Vector "{1}" ({0,number,integer} "character") has been transmited to the Statistics Engine. |
|
52 |
CONNECTED_TO_STATS_MODULE = connected. |
|
53 |
CONNECTION_OK = Connected to the Statistics Engine. |
|
54 |
|
|
55 |
ERROR_EXTRACT_ITEM = ** Error extracting list item: |
|
56 |
|
|
57 |
REQUESTED_OBJECT_NOT_FOUND_IN_R = The requested object ({0}) was not found in the R workspace. |
|
0 | 58 |
Formats disponibles : Unified diff