[R] Why does substr<- truncate and not replace...
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sat Sep 8 08:47:05 CEST 2001
On 8 Sep 2001, Peter Dalgaard BSA wrote:
> Thomas Vogels <tov at ece.cmu.edu> writes:
>
> > ... when the replacement string is shorter than the portion of the
> > string to be replaced?
> >
> > The documentation to substr (in R 1.3.1) gives me:
> >
> > If the portion to be replaced is longer than the replacement
> > string, then only the portion the length of the string is
> > replaced.
> >
> > And so I try:
> >
> > R> x <- "abcdef"
> > R> substr(x,2,3) <- "xy" #ok
> > R> x
> > [1] "axydef"
> > R> substr(x,2,3) <- "w" #ko
> > R> x
> > [1] "aw"
> >
> > hmm, I would have expected "awdef". Am I reading the docs wrong? (Or
> > am I just blinded to expect this string because that's what Perl would do?)
> >
> > Thanks!
> > -tom
>
> Looks like a bit of a bug. I bet the \0 terminator gets copied in from
> the replacement.
Yes, the test was one off. Fixed now.
--
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list