Class RUtil
java.lang.Object
com.eco.bio7.rbridge.RUtil
The API of the embedded R of Bio7 (the FFM bridge) for Java,
Groovy and BeanShell scripts, as
PythonUtil
for Python. Plain Java types: the variables are created in the global
environment of R (visible in the console and the R-Shell).
RUtil.toR("x", 1.0, 2.0, 3.0); // numeric vector
RUtil.toR("m", new double[][] { { 1, 2 }, { 3, 4 } }); // matrix
Map<String, Object> cols = new LinkedHashMap<>();
cols.put("id", new int[] { 1, 2 });
cols.put("name", new String[] { "a", "b" });
RUtil.dataFrameToR("df", cols); // data frame
RUtil.exec("fit <- lm(dist ~ speed, cars)");
double[] coef = RUtil.fromRDoubles("coef(fit)"); // R -> Java
String text = RUtil.print("summary(fit)"); // the printed output
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddataFrameToR(String name, Map<String, ?> columns) Assigns a data frame.static double[]Numbers of a value (numeric, integer, logical; NA as NaN).static RValueEvaluates R code and returns the value.static voidEvaluates R code (statements), errors as exception.static doublefromRDouble(String code) The first value of a numeric result.static double[]fromRDoubles(String code) The result as doubles (numeric, integer or logical; NA as NaN).static int[]The result as integers (also a factor: its codes).A list or data frame: the elements by name (in order).static double[][]fromRMatrix(String code) A matrix as rows.static StringfromRString(String code) The first string of the result.static String[]fromRStrings(String code) The result as strings (also a factor: its labels).static ij.ImagePlusimageFromR(String code, String title) Creates and shows an ImageJ image (32-bit) from a numeric matrix (rows = y).static voidTransfers an ImageJ image (the current one if null) as numeric matrix (rows = y).static booleanisAlive()Returns true if the embedded R (FFM) runs.static voidAssigns a list with names (the values as fordataFrameToR(String, Map)or RValue).static StringThe printed output of an expression (as in the console).static com.eco.bio7.rffm.RSessionsession()The session of the embedded R (for the full API of com.eco.bio7.rffm).static String[]Strings of a value (character, factor labels, numbers as text).static voidAssigns a logical vector.static voidAssigns a numeric vector.static voidAssigns a matrix (the rows of Java).static voidAssigns an integer vector.static voidAssigns any value (e.g., an RValue of a former call).static voidAssigns a character vector.
-
Method Details
-
isAlive
public static boolean isAlive()Returns true if the embedded R (FFM) runs. -
session
The session of the embedded R (for the full API of com.eco.bio7.rffm).- Throws:
RException
-
toR
Assigns a numeric vector.- Throws:
RException
-
toR
Assigns an integer vector.- Throws:
RException
-
toR
Assigns a character vector.- Throws:
RException
-
toR
Assigns a logical vector.- Throws:
RException
-
toR
Assigns a matrix (the rows of Java).- Throws:
RException
-
toR
Assigns any value (e.g., an RValue of a former call).- Throws:
RException
-
dataFrameToR
Assigns a data frame. The columns (in the order of the map, e.g., a LinkedHashMap) are double[], int[], String[] or boolean[] of the same length.- Throws:
RException
-
listToR
Assigns a list with names (the values as fordataFrameToR(String, Map)or RValue).- Throws:
RException
-
imageToR
Transfers an ImageJ image (the current one if null) as numeric matrix (rows = y).- Throws:
RException
-
exec
Evaluates R code (statements), errors as exception.- Throws:
RException
-
eval
Evaluates R code and returns the value.- Throws:
RException
-
print
The printed output of an expression (as in the console).- Throws:
RException
-
fromRDoubles
The result as doubles (numeric, integer or logical; NA as NaN).- Throws:
RException
-
fromRDouble
The first value of a numeric result.- Throws:
RException
-
fromRInts
The result as integers (also a factor: its codes).- Throws:
RException
-
fromRStrings
The result as strings (also a factor: its labels).- Throws:
RException
-
fromRString
The first string of the result.- Throws:
RException
-
fromRMatrix
A matrix as rows.- Throws:
RException
-
fromRList
A list or data frame: the elements by name (in order). Convert the elements withdoubles(RValue),strings(RValue).- Throws:
RException
-
imageFromR
Creates and shows an ImageJ image (32-bit) from a numeric matrix (rows = y).- Throws:
RException
-
doubles
Numbers of a value (numeric, integer, logical; NA as NaN).- Throws:
RException
-
strings
Strings of a value (character, factor labels, numbers as text).- Throws:
RException
-