[R] dir() and RegEx and gsub()

Hans-Peter gchappi at gmail.com
Thu Jun 9 18:35:21 CEST 2005


Dear R-Users,

I have two questions:

a)
in a directory there are 3 files:
[1] "Data.~csv"            "Kopie von Data.~csv"  "VorlageTradefile.csv"

The command "dir( fold, pattern = "\.csv" )" gives back *all* the 3 files 
With dir( fold, pattern = "\\.csv" ) I get back only VorlageTradefile.csv. 
I don't understand this behaviour, IMHO the regex expression "\.csv"
becomes the string ".csv" and "\\.csv" becomes "\.csv". So the first
string should catch it. This is also consistent with the result when I
tried with the TRegExpr Tool. Could somebody explain what's going on
here?

b)
I need to handle a copied windows file path. This is certainly often
asked but I didn't find a solution.
How can I convert, e.g.

myfile <- "D:\UebungenNDK\DataMining\DataMiningSeries.r"
in either:

myfile
[1]  "D:\\UebungenNDK\\DataMining\\DataMiningSeries.r"

or:
myfile
[1]  "D:/UebungenNDK/DataMining/DataMiningSeries.r"

Would be great to hear about a possibility!

A nice evening to everybody,
Hans-Peter




More information about the R-help mailing list