Bug 16214 - substring<-"" replaces one letter
Summary: substring<-"" replaces one letter
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.1.2
Hardware: All All
: P5 minor
Assignee: R-core
Depends on:
Reported: 2015-02-18 16:54 UTC by Erik Wright
Modified: 2015-02-20 09:59 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Erik Wright 2015-02-18 16:54:30 UTC
In the help file for `substring<-` it states:

"If the portion to be replaced is longer than the replacement string, then only the portion the length of the string is replaced."

However, if we give a zero length replacement, then substring will still remove one letter.  For example:

> x <- "qwerty"
> substring(x, 1, 5) <- "a"
> x
[1] "awerty"
> substring(x, 1, 5) <- ""
> x
[1] "werty"

According to my interpretation of the help file, no letter should have been removed because the replacement string has no characters.

This should probably be clarified in the help file, or the behavior of substring should be changed.

Thanks, Erik
Comment 1 Brian Ripley 2015-02-20 09:59:33 UTC
Neither R-patched nor R-devel do this: see the FAQ about not reporting bugs which are already fixed.