Prof Brian Ripley wrote:

> 
> You could do this via a search_file() connection wrapper, but there is a 
> problem with ensuring connections get closed (which on.exit does here).
> 

  I'm not sure exactly what you mean by a 'search_file() connection 
wrapper', but I have realised that its probably a better idea to write a 
function that checks a search path for a file and then returns that file:

search_file =
function(name,path=options()$scanpath,...){
for(p in path){
       file=file.path(p,name)
       if(file.exists(file)){
         return(file)
       }
     }
return(name)
}

  Then you can use that in any filename-using function:

  options(scanpath=c("/data1","/data2","/etc"))

  > search_file("passwd")
  [1] "/etc/passwd"

  > passwd = read.table(search_file("passwd"),sep=":")
  > record = scan(search_file("passwd"),what='')[1]

Barry

______________________________________________
[email protected] 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.

Reply via email to