tags:

views:

39

answers:

2

Is it possible to have R's Sys.glob() function expand braces? What I mean is a pattern similar to /home/foo/{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...

A: 

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?

Dirk Eddelbuettel
I will look into it. The actual coding part is easy; it's the getting involved in such a large and mature project is where all the effort lies...
frankc
+1  A: 

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)
Shane
yeah, i was hoping not to do something like that...
frankc