... 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 -- mailto:tov at ece.cmu.edu (Tom Vogels) Tel: (412) 268-6638 FAX: -3204 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Sep-07 22:00 UTC
[R] Why does substr<- truncate and not replace...
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! > -tomLooks like a bit of a bug. I bet the \0 terminator gets copied in from the replacement. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kurt Hornik
2001-Sep-08 06:28 UTC
[Rd] Re: [R] Why does substr<- truncate and not replace...
>>>>> Peter Dalgaard BSA writes:> Thomas Vogels <tov@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.There are yet more interesting effects when using longer portions: R> x <- "abcdef" R> x [1] "abcdef" R> substr(x, 2, 4) <- "x" R> x [1] "ax" -k -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._