[R] Re-sent to correct list: passing parameters
Shravan Vasishth
vasishth.1 at osu.edu
Fri Nov 9 16:33:10 CET 2001
Hi,
My apologies for sending this message earlier to the wrong list (next
time I'll wait till I'm fully awake).
I'm a new R user. I want to do the following:
I want to pass a filename to R repeatedly (about 400 times) in order to
do a repetitive task (calculating regressions).
The way I'm setting it up is to write a bash script that will create an
R source file on the fly for each file. Here's the script in the
abstract:
#!/bin/sh
for f in *.vec; do
#for each file f with extension .vec, create an
#R source file that reads in the file f (as a table or whatever) and
#then load it as an object (here, "foo"); there will be other code
#as well, of course, after that. After that R source file has
#completed its job, remove it and repeat with the next file
TEMPFILE=temp$$.R
echo "foo <- read.table(\"$f\"); bar <- t(foo); bar;" | cat - template.R
> $TEMPFILE
R --silent --slave < $TEMPFILE >> outfile.test
rm -f $TEMPFILE done
It works, but this is a really ugly hack, so my question is: is there a
better way to do this? For example, is there some way to pass a
filehandle as a parameter to R? From reading the manuals and old news
posts and responses, it seems the answer is no. I'm thinking of a
command like
R --silent -slave < source.R $f >> outfile.test
where $f will be used as the variable for the file to be converted to an
object ("foo" in my toy example above).
I hope my explanation makes sense.
Thanks in advance,
Shravan Vasishth
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list