Skip to content
Prev 156973 / 398506 Next

How to convert backslash to slash?

Shengqiao Li wrote:
I didn't say it was not legitimate, I said that it contains no 
backslashes.  If you replace f or b with d, you do not have a legitimate 
string.
That's not true.  If you enter a backslash in the string, setwd() works 
fine.

Your problem is that you are confusing R source code with the strings 
that it represents.  The R source code for the file path C:\Acer is 
"C:\\Acer".  The
R source code "C:\foo\bar" contains no backslashes, it contains the 
characters C, :, formfeed, o, o,  backspace, a, r.

If you have the string C:\Acer in the Windows clipboard, then you can 
read it from there using readClipboard().  (There are many other ways to 
read the clipboard as well;
using 'clipboard' as a filename generally works.) You can then pass it 
to setwd(), and it will be fine.

Duncan Murdoch