[R] Replacing backslashes with slashes

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Wed Jan 4 19:29:15 CET 2006


On 04-Jan-06 yvonnick noel wrote:
> [...]
> The string I get is an ASCII string in a web page, through
> the use of an <INPUT> type="file" ... > tag (with a "browse"
> button). This string is caught as is by R through the Rpad
> interface (using tcltk as a mini local webserver).
> 
> So it is not manually input by the user.
> [...]

Yvonnik, the only line of approach I can think of at the
moment is to somehow read from the web page into a file
(though perhaps a socket/FIFO might work as well).

For example, if I make a file names.txt with contents

  c:\My Documents\data.dat

(even without quotes) then

  A<-readLines("names.txt",n=1)
  > A
  [1] "c:\\My Documents\\data.dat"

so the result is now in the format such that gsub will work.

E.g.

  gsub("\\\\","/",readLines("names.txt",n=1))
  [1] "c:/My Documents/data.dat"

So now all that would remain is for you to work out how best
to get the filename from the web page into the file which is
read by 'readLines'. One would need more information to work
out how to do that in the context of your usage.

Might reading it from the Windows clipboard work?

Hoping, anyway, that this helps a bit!
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 04-Jan-06                                       Time: 18:29:12
------------------------------ XFMail ------------------------------




More information about the R-help mailing list