Re: [R] search path question

From: Zhiliang Ma <zhiliang.ma_at_gmail.com>
Date: Tue, 29 May 2007 13:36:01 -0400

Thanks, Barry.
In fact, I have a function just like yours, and I'm looking for a simple
alternative function, which is like "path" in Matlab.

On 5/29/07, Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk> wrote:
>
> Zhiliang Ma wrote:
> > I want to find a function that can simply add
> > "C:\inFiles\" into R's search path, so that we I scan a file R will go
> to
> > all the search paths to find it. In matlab, path(path,"C:\inFiles") will
> do
> > this job, I'm just wondering if there is a similar function in R can do
> this
> > job.
>
> Something like this (not extensively tested):
>
> `sscan` <-
> function(name, path=options()$scanpath,...){
>
> for(p in path){
> file=file.path(p,name)
> if(file.exists(file)){
> return(scan(file,...))
> }
> ## last resort..
> return(scan(name,...))
> }
> }
>
> Then do:
>
> options(scanpath="/tmp")
>
> and then:
>
> sscan("foo.data")
>
> will look for /tmp/foo.data first, then if that fails it will do the
> 'last resort' which is to look in the current directory.
>
> My worry is that this will bite you one day - if you have two files
> with the same name, it will get the first one in your scanpath - one day
> this will not be the one you think it is....
>
> Note this only works with 'scan' - you'll have to do the same thing
> for read.table, source, etc etc if you want them to behave with a search
> path too. Unless there's a lower-level approach. But that really will
> bite you!
>
> Barry
>
>
> Barry
>

        [[alternative HTML version deleted]]



R-help_at_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. Received on Tue 29 May 2007 - 18:05:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 May 2007 - 19:31:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.