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