[R] How to convert "c:\a\b" to "c:/a/b"?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 28 08:43:13 CEST 2005


This is based on a false premise.  R _can_ read files containing such 
names: use readLines() or scan(allowEscapes=FALSE).  Someone else wrote 
the C for you!

The restriction is that if you pass character strings to the parser, they 
are interpreted according to the documented rules, including interpreting 
escapes.

On Tue, 28 Jun 2005, Mulholland, Tom wrote:

>> -----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.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list