R: Brace expansion in Sys.glob()
Is it possible to have R's Sys.glob() function expand braces? What I mean is a pattern similar to /home/f开发者_JAVA百科oo/{a,b}/bar.txt should find files /home/foo/a/bar.txt and /home/foo/b/bar.txt should they both exist. By default R does not expand the braces.
Brace expansion is possible in glob(3) with the GLOB_BRACE flag. I am guessing R is just calling glob(3) underneath the covers so I hope there is some way, but I can't seem to find the right invocation...
I just mention, that you could also use system
(with the intern param set to TRUE) and call whatever system command you want to use if it isn't exposed directly in Sys.*()
in R. For example, this just calls ls
for csv files:
x <- system("ls *.csv", intern=TRUE)
The bracer
package's glob()
function is a wrapper around Sys.glob()
that finds files after performing brace expansion. In your particular example bracer::glob("/home/foo/{a,b}/bar.txt")
would indeed find files /home/foo/a/bar.txt
and /home/foo/b/bar.txt
if they should both exist.
Sounds useful.
The actual work is done by the do_glob()
subroutine in the file src/main/sysutils.c
in the R sources -- maybe you can start there with work towards a patch?
GLOB_MARK
is already added conditionally (on being available) so maybe you can shadow that work?
精彩评论