[Rd] wishlist: \& or \0 in sub/gsub
Gabor Grothendieck
ggrothendieck at myway.com
Fri Nov 5 17:26:47 CET 2004
This is a wish list item.
It would be nice if one could use \0 or \& in sub and
gsub as in vi:
gsub("an", ":\\&:", "banana")
One can, of course, write the following right now:
gsub("(an)", ":\\1:", "banana")
But often the this is within a function and the "an"
is passed which means that one must use paste to
construct the "(an)" argument.
Thus:
f <- function(x,y) {
x <- paste("(", x, ")", sep = "")
gsub(x, ":\\1:", y)
}
simplifies to:
f <- function(x,y) gsub(x, ":\\&:", y)
I have seen at least one post on r-help where this could have been
used to good effect to simplify the answer.
It would be neater if \& or \0 could be used instead.
Obviously this is not a huge issue but it would be nice.
More information about the R-devel
mailing list