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

From: Hans-Peter <>
Date: Fri 10 Jun 2005 - 19:16:22 EST

2005/6/9, Sarah Goslee <>:

> Under R, for reasons I've never quite understood,
> "\\." evaluates to .

Thanks to the answers of B. Ripley and Gabor I think, I understand now:

  1. the patter-string "\\.csv$" gives the regular expression "\.csv$"
  2. now the backslash lets the dot to be interpreted literally (instad of a metacharacter). As said by Gabor, an alternative is, to put the dot between brackets

>If you mean you want to change the "\" to either "\\" or "/" I'm
>really not sure.

Yes that's what I intended.
Because in windwos I copy the path from the address bar of the explorer and paste it in the R console window. Now I *have* something like

myfile <- "D:\UebungenNDK\DataMining\DataMiningSeries.r" that needs to be adjusted manually ;-(

I interpret the answers

>> myfile <- "D:\UebungenNDK\DataMining\DataMiningSeries.r"
>I am sure that's not what you intended. It has to be written as
> [snip] [1] "D:/UebungenNDK/DataMining/DataMiningSeries.r"


>> myfile <- "D:\UebungenNDK\DataMining\DataMiningSeries.r"
>Variable myfile, as you have written it above, has no backslashes in it
>so there is no way way to know where they are supposed to be.

that it's not possible at all to have a character string with backslashes in it (because they *will* act as escape characters).

> I've always just processed the strings in vim or similar, rather
than fight with R.

I do it in DOS-Batch files. Quite ugly but it works...

Hans-Peter mailing list PLEASE do read the posting guide! Received on Fri Jun 10 19:23:38 2005

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