How can one convert back slashes to forward slashes, e.g, changing "c:\a\b" to "c:/a/b"? I tried the following: > gsub("\\\\", "/", "c:\a\b") [1] "c:\a\b" Since this didn't work, I eliminated the replacement as a contributor as follows: > gsub("X", "/", "c:XaXb") [1] "c:/a/b" The following seems to illustrate the problem: strsplit("c:\a\b", "") [[1]] [1] "c" ":" "\a" "\b" How can one automate this? Thanks, spencer graves -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves at pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915
On 26 June 2005 at 20:30, Spencer Graves wrote: | How can one convert back slashes to forward slashes, e.g, changing | "c:\a\b" to "c:/a/b"? I tried the following: | | > gsub("\\\\", "/", "c:\a\b") | [1] "c:\a\b" This does work, provided you remember that single backslashed "don't exist" as e.g. \a is a character in itself. So use doubles are you should be fine:> gsub("\\\\", "/", "c:\\a\\b")[1] "c:/a/b" Hth, Dirk -- Statistics: The (futile) attempt to offer certainty about uncertainty. -- Roger Koenker, 'Dictionary of Received Ideas of Statistics'
> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Henrik Bengtsson > Sent: Tuesday, 28 June 2005 2:54 AM > To: Spencer Graves > Cc: r-help at stat.math.ethz.ch; Dirk Eddelbuettel > Subject: Re: [R] How to convert "c:\a\b" to "c:/a/b"? >... snipped> Thus, you cannot write your program such that it fools the parser, > because your program is evaluated first after the parser. In other > words, there is no way you can get nchar("\n") to equal 2. >I had been waiting for this answer because it was the conclusion I had come to. Given that I mainly work in a windows world this has been a problem. For various reasons I receive files liberally sprinkled with such pathnames. I generally pre-process them using whatever is at hand. It's not a big problem, just annoying to have to explain to collegues that this is something R can't do. Not a good advertisment for those who have no idea about escape codes. However I can't believe that this problem cannot be solved. The thoughts that have come through my head are to write a c routine that effectively ignores the possibility that \n means newline and thus remaps all the escape codes into text (\\ and the character code.) I've never written in C which is one of the reasons that I have never attempted this. I would be interested in any thoughts about the viability of my proposal. It seems an awful lot of work (at least for someone who hasn't done this sort of stuff before) for something that can be achieved in many other ways. Tom
Possibly Parallel Threads
- Replace back slashes with forward slashes?
- postscript() filenames with forward slashes cause abort
- [SPAM] - Re: How to assess significance of random effect in lme4 - Bayesian Filter detected spam
- FW: FDR analyses: minimum number of features
- quotation marks and scan