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

From: Hans-Peter <gchappi_at_gmail.com>
Date: Fri 10 Jun 2005 - 02:35:21 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jun 10 02:46:27 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:28 EST