[Rd] wishlist: \& or \0 in sub/gsub

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Sat 06 Nov 2004 - 03:26:47 EST

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.


	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.

R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Nov 06 03:49:44 2004

This archive was generated by hypermail 2.1.8 : Sat 06 Nov 2004 - 04:09:52 EST