Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / r / ExecRMacro.groovy @ 499

History | View | Annotate | Download (1.1 kB)

1 479 mdecorde
package org.txm.macro.r;
2 479 mdecorde
// STANDARD DECLARATIONS
3 479 mdecorde
4 479 mdecorde
import org.kohsuke.args4j.*
5 479 mdecorde
6 479 mdecorde
import groovy.transform.Field
7 479 mdecorde
8 479 mdecorde
import org.txm.index.core.functions.Index
9 499 mdecorde
import org.txm.rcp.swt.widget.parameters.*
10 499 mdecorde
import org.txm.rcp.commands.*
11 479 mdecorde
import org.txm.Toolbox
12 479 mdecorde
import org.txm.statsengine.r.core.RWorkspace
13 479 mdecorde
14 479 mdecorde
def sel = corpusViewSelection
15 479 mdecorde
16 479 mdecorde
String symbol = null;
17 479 mdecorde
String prop = "none"
18 479 mdecorde
if (sel instanceof Index) {
19 479 mdecorde
        println "Sending Index data to R..."
20 479 mdecorde
        ((Index)sel).asRMatrix()
21 479 mdecorde
        symbol = "t("+((Index)sel).getSymbol()+'$data)'
22 479 mdecorde
        prop = ((Index)sel).getProperties().toString()
23 479 mdecorde
}
24 479 mdecorde
25 479 mdecorde
if (symbol == null) {
26 479 mdecorde
        println "Selection is not an Index. Aborting."
27 479 mdecorde
        return
28 479 mdecorde
}
29 479 mdecorde
30 479 mdecorde
def r = RWorkspace.getRWorkspaceInstance()
31 479 mdecorde
def file = File.createTempFile("IndexHist", ".svg", new File(Toolbox.getParam(Toolbox.USER_TXM_HOME), "results"))
32 479 mdecorde
33 479 mdecorde
/// BEGIN SCRIPTS
34 479 mdecorde
def script ="""
35 479 mdecorde
par(las=2)
36 479 mdecorde
barplot($symbol, xlab="$prop", ylab="f")
37 479 mdecorde
"""
38 479 mdecorde
/// END SCRIPTS
39 479 mdecorde
r.plot(file, script)
40 479 mdecorde
println "Result saved in: "+file.getAbsolutePath()
41 479 mdecorde
42 479 mdecorde
//display the graphic
43 479 mdecorde
monitor.syncExec(new Runnable() {
44 479 mdecorde
        @Override
45 479 mdecorde
        public void run() {        OpenSVGGraph.OpenSVGFile(file.getAbsolutePath(), "Distribution") }
46 479 mdecorde
});