.Platform addition (was Re: [R] where does R search when sour ce ()?)

Liaw, Andy andy_liaw at merck.com
Mon Jul 12 18:34:29 CEST 2004


> From: Paul Roebuck
> 
> On Sun, 11 Jul 2004, Gabor Grothendieck wrote:
> 
> > search.path <-
> > function(fn,
> >          paths = strsplit(Sys.getenv("PATH"), split = ";")[[1]],
> >          fsep = "\\") {
> >     for(d in paths) {
> >         f <- file.path(d, fn, fsep = fsep)
> >         if (file.exists(f))
> >             return(f)
> >     }
> >     return(NULL)
> > }
> >
> > source(search.path("myscript.R"))
> 
> I glanced this and thought this might be handy to keep for
> possible use. To make it less Windows-specific, I was going
> to replace Gabor's fsep default value with '.Platform$file.sep'
> when I noticed that .Platform doesn't have a '$path.sep'
> field. Just missing or available elsewhere?

The fsep is fine, as file.path() has the logical default (so I don't know
why Gabor had to specify it).  The bigger problem (for me) is delimiter for
PATH (used in the `sep' argument for the strsplit() call):  It's ";" on
Windows and ":" on *nix.  Don't know about other OSes that R runs on.

Andy




More information about the R-help mailing list