[R] Help with sub functions
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Sep 30 08:26:45 CEST 2009
On Tue, 29 Sep 2009, edchen51 at gmail.com wrote:
>
> I have chances to work with both linux based and win based R codes.
> And as you all know in linux, the file directories use "/" and win
> uses "\\". Is there a function like sub or gsub that could
> substitute those slashes automatically?
See ?chartr, and you can also use gsub(fixed = TRUE).
But as both the R and rw FAQs tell you, your assertion about 'win' is
incorrect for modern Windows: the Windows system functions accept
either slash or backslash, as do all but a few badly-written Windows
applications.
A word of warning: the ASCII representation of \ is both a character
in Windows DBCS encodings (used for CJK languages, it is rendered as
the Yen symbol in most DBCS fonts) and a trail byte, and you need to
be very careful with substitutions. We have had reports of both gsub
and chartr mangling Chinese file names, although it is likely they
were not in a Chinese locale and it was before many Unicode-related
changes in R under Windows.
> Thanks!
>
> Edward Chen
> Email: tkedch at msn.com
> Cell Phone: 510-371-4717
--
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