Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / prototypes / ExecuteRscript.groovy @ 1000

History | View | Annotate | Download (1.9 kB)

1
package org.txm.scripts.test;
2
/**
3
 * Main.
4
 *
5
 * @param args the args
6
 */
7
// Copyright © 2010-2013 ENS de Lyon.
8
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
9
// Lyon 2, University of Franche-Comté, University of Nice
10
// Sophia Antipolis, University of Paris 3.
11
// 
12
// The TXM platform is free software: you can redistribute it
13
// and/or modify it under the terms of the GNU General Public
14
// License as published by the Free Software Foundation,
15
// either version 2 of the License, or (at your option) any
16
// later version.
17
// 
18
// The TXM platform is distributed in the hope that it will be
19
// useful, but WITHOUT ANY WARRANTY; without even the implied
20
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21
// PURPOSE. See the GNU General Public License for more
22
// details.
23
// 
24
// You should have received a copy of the GNU General
25
// Public License along with the TXM platform. If not, see
26
// http://www.gnu.org/licenses.
27
// 
28
// 
29
// 
30
// $LastChangedDate:$
31
// $LastChangedRevision:$
32
// $LastChangedBy:$ 
33
//
34
import org.txm.statsengine.r.core.RWorkspace
35
// import org.txm.rcp.commands.*
36
// uncomment for test
37

    
38
// get a connection to R
39
// TODO: Auto-generated Javadoc
40

    
41
/* (non-Javadoc)
42
 * @see groovy.lang.Script#run()
43
 */
44
def r = RWorkspace.getRWorkspaceInstance()
45

    
46
// start logging R output in the console
47
r.setLog(true)
48

    
49
// a sample plotting script
50
def script = new File(System.getProperty("user.home")+"/TXM/scripts/samples/R/plot100.R")
51
// we need this for Windows
52
def scriptpath = script.getAbsolutePath().replace("\\","\\\\")
53
// use a temporary file to transfert the graphic
54
def f = File.createTempFile("txm", ".svg", script.getParentFile())
55

    
56
// generate the graphic
57
r.plot(f, "source(\""+scriptpath+"\")")
58

    
59
// draw the graphic in a new window of TXM
60
monitor.syncExec(new Runnable() {
61
        @Override
62
        public void run() {        OpenSVGGraph.OpenSVGFile(f.getAbsolutePath(), "sample plot") }
63
});
64

    
65

    
66
// stop logging R output
67
r.setLog(false)