On Thu, 21 Jun 2001, Karl Nissen wrote:
> Morning,
>
> I'm reading a string from a file using scan(). The file contains a typical
> DOS/Window directory string:
>
> "D:\datasets\geog3009\fred.dat"
>
> When this is read into Splus using scan(), the back slashes are removed:
>
> "D:datasetsgeog3009fred.dat"
>
> This is consistent with the use of the backslash as an escape character in
> the UNIX world.
>
> Is there a simple way to tell scan(), or Splus, to interpret the single
> backslash as a directory character, rather than an escape character, so the
> string is not modified?
The short answer would be to use readLines, but that is not available
in Splus 2000 (now I look at your subject).
> readLines("foo.dat")
[1] "\"D:\\datasets\\geog3009\\fred.dat\""
in S-PLUS 6.0.1 release candidate 2. Don't be confused by the way it is
printed:
> cat(readLines("foo.dat"), "\n", sep="")
"D:\datasets\geog3009\fred.dat"
and the quotes were on the file and so are part of the string.
The only way I know in earlier versions is to alter the file to have
\\ in place of \, a simple operation using sed, then use scan.
But then knowing one way is enough ....
BTW, almost everything internally in Windows accepts / as a path separator,
so many of us just use that and avoid such problems.
--
Brian D. Ripley, ripley@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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
|