[R] How to convert backslash to slash?
ggrothendieck at gmail.com
Wed Sep 24 16:19:00 CEST 2008
On Wed, Sep 24, 2008 at 9:59 AM, Shengqiao Li <shli at stat.wvu.edu> wrote:
> On Wed, 24 Sep 2008, jim holtman wrote:
>> It probably depends on how you are prompting the user for input. Here
>> is what happens with 'readline' and you will see that the string after
>> input does have the backslashes escaped.
>>> x <- readline("Input File: ")
>> Input File: c:\dir1\dir2\file.name
>>  "c:\\dir1\\dir2\\file.name"
>>> gsub("\\\\", "/", x) # notice the double escape
>>  "c:/dir1/dir2/file.name"
> Great! Thanks. By the way, it would be nice if R have a third way to quote a
> string and automatically escape the backslashes in memory. For instance:
> #not run now
> s<- `C:\Acer'
>  "C:\\Acer"
I agree that that some sort of facility would be convenient. Creating
latex output is
another situation where not having to escape backslashes would be convenient.
Other languages do have special purpose constructs for this.
More information about the R-help