Hi Erin,
On Jul 23, 2009, at 2:12 PM, Erin Hodgess wrote:
Dear R People:
I'm having trouble with something that should be very simple.
I'm setting up a matrix outside of a loop and writing items into it
during the loop.
Here is the output:
glob3b("sites.info")
dim 27 3
[1] "/raid1/osg-app"
Error in xy[i, ] : incorrect number of dimensions
Here is the function:
glob3b
function(xx) {
x.df <- read.table(xx,header=FALSE,as.is=TRUE,sep="\t")
n1 <- nrow(x.df)
xy <- matrix(rep("",n1*3),nrow=n1,ncol=3)
cat("dim",dim(xy),"\n")
for(i in 1:n1) {
xz <- paste("globus-job-run ",x.df[i,2]," /bin/sh -c 'echo
$OSG_APP'",
sep="")
xw <- system(xz,intern=TRUE)
if(length(xw)>0) {
xy[i,1:2] <- x.df[i,1:2]
print(xw)
cat(i,xy[i,],"\n")
cat(i,length(xw),dim(xw),"\n")
xy[i,3] <- xw
}
}
return(xy)
}
This is somehow hard for me to parse, but a few comments:
1. The object returned from your `system` call (xw) will be a
character vector, calling dim(xw) will return NULL (doesn't look like
that matters here, just sayin').
2. xw maybe of length > 1, in which case your final call `xy[,3] <-
xw` is likely tripping you up (try: `xy[,3] <- xw[1]`.
That said, I expect some of the output from your calls to "cat" to be
shown, but I'm not seeing it in the output you pasted.
Other randomness:
xy <- matrix(rep("",n1*3),nrow=n1,ncol=3)
can be:
xy <- matrix("", nrow=n1, ncol=3)
Also, are you sure you want to store this in a matrix? The fact that
you want to save your `xw` var (which can be of length > 1) suggests
to me that you might want to be stuffing whatever-it-is you're saving
into a list of lists structure instead ... just a thought.
-steve
--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.