[R] Command Line Programs

Kissell, Robert [EQRE] robert.kissell at citigroup.com
Thu Mar 4 23:19:11 CET 2004


Hi,
I have recently started using R again (switched from MatLab) and have a question regarding programming. How can I set up a file that will run several lines of R code? For example, in Fortran and DOS this used to be done via a batch file, and in MatLab I would write the code and save it in a script file, e.g., Test.m.

An example of what I am trying to do is the following:

x=matrix(c(1,2,3,4,5,6,7,8,9),3,3)
y=matrix(c(rnorm(9),3,3)
z1=x*y
z2=x%*%y

eigen(z1)
eigen(z2)


I would like to store these commands in a file and simply run/call/invoke that file rather than have to type in the line commands everyday. The above is a very simple snapahot of what I am doing.

Right Now I have a function that runs these commands. Also, I can easily COPY the commands from some editor (e.g., Word) and PASTE to the R Console, and R will automatically run the commands.

The question is, Is there anyway to invoke a series of commands outside of the function? In MatLab, as I mentioned, I would save the commands in a script file say TEST.m and run the commands from the MatLab command line prompt simply by typing TEST <enter>.

Thanks in advance.


Rob




More information about the R-help mailing list