[R] passing args to R CMD BATCH in win 2000

2007-08-01 Thread Stephen . Bond
Hello and sorry to bother.

Please help.
I searched the archives but could not find out why --args is being ignored 
on Windows 2000.
I try

R CMD BATCH --slave 11.R 11.Rout --args 12

and 11.R has

x=commandArgs(trail=T)
print(x)
a=x[length(x)]
write.csv(a,file=13.out)
q(no)


the argument is not passed to the R process.
11.Rout only shows processing time and 13.out does not have the value.


Thank you all.
stephen
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] help with tryCatch

2007-02-15 Thread Stephen Bond
Henrik,
Please, stay with me.
there is a problem with the way tryCatch processes statements and that 
is exactly what the help file does not describe at all. I am trying


catch=function(vec){
  ans=NULL;err=NULL;
  for (i in vec) {
  tryCatch({
  source(i);
  ans=c(ans,i);
  cat(ans, from try);
  },
  error=function(er){
cat(i, from catch\n);
err=c(err,i);

  }
   )
 
}
  ret=list(ans=ans,err=err)
  ret
}

v=c(gdhfdh,hdhdfjh)  #non-existent files
ret=catch(v)  # err is NULL and none of the statements in that block is 
executed ??

below is a Java example that executes the catch block as it should. How 
can I achieve the same in R?
***
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class ReadFiles {
   
public static void main(String[] args) {
String[] files={asdf,qwert};
Vector err=new Vector();
FileReader inputStream = null;
for (int j=0;j2;j++){
try {
inputStream = new FileReader(files[j]);
int c;
while ((c = inputStream.read()) != -1) {}
} catch(IOException e){
err.add(j,files[j]); // this statement executes!
} finally {
if (inputStream != null) {
inputStream.close(); // IO not encapsulated here, 
but declared in main throws. pls ignore since source(arg) in R takes 
care of closing.
}
}
}
for (Object j:err){
System.out.println(j);
}
}
}









Henrik Bengtsson wrote:

 To be more precise, put the tryCatch() only around the code causing
 the problem, i.e. around source().  /H

 On 2/13/07, Henrik Bengtsson [EMAIL PROTECTED] wrote:

 Put the for loop outside the tryCatch(). /H

 On 2/13/07, Stephen Bond [EMAIL PROTECTED] wrote:
  Henrik,
 
  thank you for the reference. Can you please tell me why the following
  does not work?
 
  vec=c(hdfhjfd,jdhfhjfg)# non-existent file names
  catch=function(vec){
tryCatch({
  ans =NULL;err=NULL;
  for (i in vec) {
source(i)
ans=c(ans,i)
  }
},
interrupt=function(ex){print(ex)},
error=function(er){
   print(er)
   cat(i,\n)
   err=c(err,i)
},
finally={
  cat(finish)
}
   ) #tryCatch
  }
 
  catch(vec) # throws an error after the first file and stops there 
 while
  I want it to go through the list and accumulate the nonexistent
  filenames in err.
 
  Thank you
  Stephen
 
  Henrik Bengtsson wrote:
 
   Hi,
  
   google R tryCatch example and you'll find:
  
http://www.maths.lth.se/help/R/ExceptionHandlingInR/
  
   Hope this helps
  
   Henrik
  
   On 2/13/07, Stephen Bond [EMAIL PROTECTED] wrote:
  
   Henrik,
  
   I had looked at tryCatch before posting the question and asked the
   question because the help file was not adequate for me. Could 
 you pls
   provide a sample code of
   try{ try code}
   catch(error){catch code}
  
   let's say you have a vector of local file names and want to 
 source them
   encapsulating in a tryCatch to avoid the skipping of all good 
 file names
   after a bad file name.
  
   thank you
   stephen
  
  
   Henrik Bengtsson wrote:
  
See ?tryCatch. /Henrik
   
On 2/12/07, Stephen Bond [EMAIL PROTECTED] wrote:
   
Could smb please help with try-catch encapsulating a function 
 for
downloading. Let's say I have a character vector of symbols and
   want to
download each one and surround by try and catch to be safe
   
# get.hist.quote() is in library(tseries), but the question 
 does not
depend on it, I could be sourcing local files instead
   
ans=null;error=null;
for ( sym in sym.vec){
try(ans=cbind(ans,get.hist.quote(sym,start=start))) 
 #accumulate in
   a zoo
matrix
catch(theurlerror){error=c(error,sym)} #accumulate failed 
 symbols
}
   
I know the code above does not work, but it conveys the idea.
   tryCatch
help page says it is similar to Java try-catch, but I know 
 how to
   do a
try-catch in Java and still can't do it in R.
   
Thank you very much.
stephen
   
__
R-help@stat.math.ethz.ch 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.
   
  
 



__
R-help@stat.math.ethz.ch 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.


Re: [R] help with tryCatch

2007-02-13 Thread Stephen Bond
Henrik,

thank you for the reference. Can you please tell me why the following 
does not work?

vec=c(hdfhjfd,jdhfhjfg)# non-existent file names
catch=function(vec){
  tryCatch({
ans =NULL;err=NULL;
for (i in vec) {
  source(i)
  ans=c(ans,i)
}
  },
  interrupt=function(ex){print(ex)},
  error=function(er){
 print(er)
 cat(i,\n)
 err=c(err,i)  
  },
  finally={
cat(finish)
  }
 ) #tryCatch
}
 
catch(vec) # throws an error after the first file and stops there while 
I want it to go through the list and accumulate the nonexistent 
filenames in err.

Thank you
Stephen

Henrik Bengtsson wrote:

 Hi,

 google R tryCatch example and you'll find:

  http://www.maths.lth.se/help/R/ExceptionHandlingInR/

 Hope this helps

 Henrik

 On 2/13/07, Stephen Bond [EMAIL PROTECTED] wrote:

 Henrik,

 I had looked at tryCatch before posting the question and asked the
 question because the help file was not adequate for me. Could you pls
 provide a sample code of
 try{ try code}
 catch(error){catch code}

 let's say you have a vector of local file names and want to source them
 encapsulating in a tryCatch to avoid the skipping of all good file names
 after a bad file name.

 thank you
 stephen


 Henrik Bengtsson wrote:

  See ?tryCatch. /Henrik
 
  On 2/12/07, Stephen Bond [EMAIL PROTECTED] wrote:
 
  Could smb please help with try-catch encapsulating a function for
  downloading. Let's say I have a character vector of symbols and 
 want to
  download each one and surround by try and catch to be safe
 
  # get.hist.quote() is in library(tseries), but the question does not
  depend on it, I could be sourcing local files instead
 
  ans=null;error=null;
  for ( sym in sym.vec){
  try(ans=cbind(ans,get.hist.quote(sym,start=start))) #accumulate in 
 a zoo
  matrix
  catch(theurlerror){error=c(error,sym)} #accumulate failed symbols
  }
 
  I know the code above does not work, but it conveys the idea. 
 tryCatch
  help page says it is similar to Java try-catch, but I know how to 
 do a
  try-catch in Java and still can't do it in R.
 
  Thank you very much.
  stephen
 
  __
  R-help@stat.math.ethz.ch 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.
 


__
R-help@stat.math.ethz.ch 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.


[R] help with tryCatch

2007-02-12 Thread Stephen Bond
Could smb please help with try-catch encapsulating a function for 
downloading. Let's say I have a character vector of symbols and want to 
download each one and surround by try and catch to be safe

# get.hist.quote() is in library(tseries), but the question does not 
depend on it, I could be sourcing local files instead

ans=null;error=null;
for ( sym in sym.vec){
try(ans=cbind(ans,get.hist.quote(sym,start=start))) #accumulate in a zoo 
matrix
catch(theurlerror){error=c(error,sym)} #accumulate failed symbols
}

I know the code above does not work, but it conveys the idea. tryCatch 
help page says it is similar to Java try-catch, but I know how to do a 
try-catch in Java and still can't do it in R.

Thank you very much.
stephen

__
R-help@stat.math.ethz.ch 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.