[R-sig-Fedora] Problem running R from within a script
Joshua Kramer
josh at globalherald.net
Tue Nov 25 19:13:59 CET 2008
Howdy Folks,
I am running R version 2.7.2 (2008-08-25) on CentOS 5.2 - the standard RPM
distribution.
I am having a curious occurance trying to run a R script from within a
shell script. Basically, I have a small R script that processes a file.
It takes two parameters - the input file, and the output file. I then
have a shell script that runs the R script for each file matching a glob.
R is not picking up the correct parameters *when run from the script*.
When I run the command line by itself, it runs fine.
The command line is this:
/usr/bin/R CMD BATCH --no-restore --no-save '--args $taxFile $taxFile.taxonomy' batchMakeTax.R batchMakeTax.log
Here's the output of the script:
Processing /usr/bin/R CMD BATCH --no-restore --no-save '--args Call0103.xpt Call0103.xpt.taxonomy' batchMakeTax.R batchMakeTax.log
/usr/lib/R/bin/BATCH: line 55: Call0103.xpt: Permission denied
I do not know why it's trying to write to the input file... any ideas?
Here's the shellscript:
[josh at localhost cr]$ cat batchMakeTax.sh
#!/bin/sh
FILES="*.xpt"
echo MakeCommand is $makeCommand
for taxFile in $FILES
do
makeCommand="/usr/bin/R CMD BATCH --no-restore --no-save '--args $taxFile $taxFile.taxonomy' batchMakeTax.R batchMakeTax.log"
echo "Processing $makeCommand"
$makeCommand
done
...and, the R script. Note that R never gets as far as running the
script, however - the error occurs in the CMD shell script that is under
/usr/bin/R/CMD.
[josh at localhost cr]$ cat batchMakeTax.R
library(foreign)
scratchOne <- commandArgs()
inFileArg <- scratchOne[10]
taxFileArg <- scratchOne[11]
sink("debugout.txt", FALSE, "output", FALSE)
print (inFileArg)
print (taxFileArg)
bankData <- read.xport(inFileArg)
sink(NULL)
sink(taxFileArg, FALSE, "output", FALSE)
bdNames <- names(bankData)
numCol <- ncol(bankData)
i=1
while (i <= numCol) {
myVar <- paste(bdNames[i], typeof(bankData[[bdNames[i]]]),
sep=":")
print(myVar)
i=i+1
}
q()
Thanks!
-josh
--
-----
http://www.globalherald.net/jb01
GlobalHerald.NET, the Smarter Social Network! (tm)
More information about the R-SIG-Fedora
mailing list