[R] Regex - subsetting parts of a file name.

2014-07-31 Thread arnaud gaboury
A directory is full of data.frames cache files. All these files have the same pattern: df.some_name.RData my.cache.list - c(df.subject_test.RData, df.subject_train.RData, df.y_test.RData, df.y_train.RData) I want to keep only the part inside the two points. After lots of headache using grep()

Re: [R] Regex - subsetting parts of a file name.

2014-07-31 Thread S Ellison
I want to keep only the part inside the two points. After lots of headache using grep() when trying something like this: grep('.(.*?).','df.subject_test.RData',value=T) Does anyone have any suggestion ? gsub(df\\.(.+)\\.RData, \\1, 'df.subject_test.RData') Steve E

Re: [R] Regex - subsetting parts of a file name.

2014-07-31 Thread arun
Try: gsub(.*\\.(.*)\\..*,\\1, my.cache.list) [1] subject_test  subject_train y_test    y_train #or library(stringr) str_extract(my.cache.list, perl('(?=\\.).*(?=\\.)')) [1] subject_test  subject_train y_test    y_train  A.K. On Thursday, July 31, 2014 11:05 AM, arnaud gaboury

Re: [R] Regex - subsetting parts of a file name.

2014-07-31 Thread Sarah Goslee
Hi, Here are two possibilities: R as.vector(sapply(my.cache.list, function(x)strsplit(x, \\.)[[1]][2])) [1] subject_test subject_train y_testy_train R gsub(df\\.(.*)\\.RData, \\1, my.cache.list) [1] subject_test subject_train y_testy_train Note that . will match any

Re: [R] Regex - subsetting parts of a file name.

2014-07-31 Thread arnaud gaboury
R as.vector(sapply(my.cache.list, function(x)strsplit(x, \\.)[[1]][2])) [1] subject_test subject_train y_testy_train R gsub(df\\.(.*)\\.RData, \\1, my.cache.list) [1] subject_test subject_train y_testy_train Note that . will match any character, while \\. matches a