R-project and PSPad how-to
Introduction
Here is a method to be able to use R (a language and environment for statistical computing
and graphics) with PSPad (a free text editor).
Find R here : www.r-project.org (release used : R-2.6.1)
Find PSPad here : http://www.pspad.com ( release used :
PSPad 4.5.0).
Why ?
PSPad is stable, has a lot of features, is free and supports well console-type
collaboration with other tools.
R is a very well featured language for statistics, and is free.
It is usefull to open some file containing R-language with PSPad, and run R from it.
Install
This tutorial is working on Ms Windows XP SP2. It should works on any Ms Windows
installation.
Download and install R anywhere (further, C:\Program Files\R-2.6.1
is
assumed).
Download and install PSPad anywhere.
In PSPad, modify settings :
- "Settings" > "Highlighters Settings..." > "R" > "External Applications"
- "Name" : add
r
- "Application" :
"C:\Program Files\R-2.6.1\bin\R.exe" --vanilla < "%File%" --args
"%File%"
- "LOG File" :
C:\Program Files\R-2.6.1\mine\sink.txt
(this directory being
where you put your .r files)
Base file
Use this a base file, put it anywhere, name it anyname.r
:
#Settings
args<-commandArgs(TRUE)
FILE_PATH<-unlist(strsplit(args[1],"\\\\"))
FILE_PATH<-paste(FILE_PATH[0:(length(FILE_PATH)-1)],collapse="\\")
logfile<-file(paste(R.home(),"\\sink.txt",sep=""),"w")
sink(logfile,type=c("output"))
sink(logfile,type=c("message"))
USE_WINDOW<-FALSE
USE_WINDOW<-TRUE
if(USE_WINDOW)windows()
#your code in r-language here instead of the following line
pie(rep(1,12), col=rainbow(12))
if(USE_WINDOW)getGraphicsEvent(onMouseDown = function(buttons,x,y){"End"})else "End"
sink(type=c("output"));
sink(type=c("message"));
close(logfile);
Comment (#) USE_WINDOW<-TRUE
to not use a window (if you do not create any
graphic output).
You may want to use s=read.csv(paste(BASE_PATH,"\\x.csv",sep=""), sep=",")
in order to open x.csv
in the same directory.
Result
You can open you xyz.r
file with PSPad. Press F9 to execute it.
If a window is open (i.e. USE_WINDOW<-TRUE
not commented), click on it to close
it and end the script.
More infos and comments
Any mail sent here will be read.
askywhale, 2008