[Rd] Question about Unix file paths

Gabor Grothendieck ggrothendieck at myway.com
Wed Nov 26 19:30:56 MET 2003


> 
> 
> --- 
> Date: Wed, 26 Nov 2003 16:52:09 +0000 (GMT) 
> From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
> To: John W. Eaton <jwe at bevo.che.wisc.edu> 
> Cc: <Kurt.Hornik at wu-wien.ac.at>,Martin Maechler <maechler at stat.math.ethz.ch>, <r-devel at stat.math.ethz.ch> 
> Subject: Re: [Rd] Question about Unix file paths 
> 
>  
>  
> On Wed, 26 Nov 2003, John W. Eaton wrote:
> 
> > On 26-Nov-2003, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
> > 
> > | >>>>> " Kurt" == Kurt Hornik <Kurt.Hornik at wu-wien.ac.at>
> > | >>>>> on Wed, 26 Nov 2003 10:05:42 +0100 writes:
> > | 
> > | Kurt> Right. In any case, an explicit glob() function
> > | Kurt> seems preferable to me ...
> > | 
> > | Good idea!
> > | 
> > | More than 12 years ago, I had a similar one, and wrote a
> > | "pat2grep()" {pattern to grep regular expression} function
> > | --- for S-plus on Unix --- which I have now renamed to glob2regexp():
> > | -- still not really usable outside unix (or windows with the
> > | 'sed' tool in the path), nor perfect, but maybe a good start:
> > | 
> > | sys <- function(...) system(paste(..., sep = ""))
> > | 
> > | glob2regexp <- function(pattern)
> > | {
> > | ## Purpose: Change "ls pattern" to "grep regular expression" pattern.
> > | ## -------------------------------------------------------------------------
> > | ## Author: Martin Maechler ETH Zurich, ~ 1991
> > | sys("echo '", pattern, "'| sed ",
> > | "'s/\\./\\\\./g;s/*/.*/g;s/?/./g; s/^/^/;s/$/$/; s/\\.\\*\\$$//'")
> > | }
> > 
> > It seems to me that using this approach to implement a proper glob()
> > function would be more work than using the glob code that is available
> > as part of bash, which I think will allow you to handle much more
> > complex patterns, including [xyz] {a,b,c} etc.
> 
> Or even the glob code from Perl, which is cross-platform. It is not clear 
> to me what we would want glob() to do on Windows, BTW.
> 
> -- 
> Brian D. Ripley, ripley at stats.ox.ac.uk

It would work similarly to:

	readLines(pipe("cmd /c dir/b a*.dat"))

If the question is what would it be used for then I have a number
of data files with nearly the same name and want the most recent.

I started out using list.files but found the pattern matching
less natural when it comes to files than file globbing so I changed
this to use the above.  After that I use file.info to find out which
is the most recent and then read in that.



More information about the R-devel mailing list