regex - List files in R that do NOT match a pattern -


r has function list files in directory, list.files(). comes optional parameter pattern= list files match pattern.

files in directory data: file1.csv file2.csv new_file1.csv new_file2.csv

list.files(path="data", pattern="new_") 

results in [1] "new_file1.csv" "new_file2.csv".

but how can invert search, i.e. list file1.csv , file2.csv?

i belive have yourself, list.files not support perl regex (so couldn't pattern=^(?!new_)).

i.e. list files filter them grep:

grep(list.files(path="data"), pattern='new_', inv=t, value=t) 

the grep(...) pattern matching; inv=t inverts match; value=t returns values of matches (i.e. filenames) rather indices of matches.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -