Skip to content
Prev 169045 / 398506 Next

sub question

Peter Dalgaard wrote:
an interesting point.  the two calls to gsubfn below should, in this
particular case, be equivalent:

library(gsubfn)

f = function(a) function(b) paste(a, b, sep="")
gsubfn('o', ~ f('o')(o), 'foo')
# "foooo"
gsubfn('o', ~ f(o)('o'), 'foo')
# the match seems to be ignored in the formula?

the following fails, too:

f = function(a) function() paste(a, a, sep="")
gsubfn('o', ~ f(o)(), 'foo')
# o won't capture the match

this as well, though it's rather different:

f = function() 'oo'
gsubfn('o', ~ f(), 'foo')
# really can't ignore the matched pattern if a formula is given?


while an average statistician may never write such rubbish code, these
are trivialized examples, and for a language advertised as one from the
functional family this sort of code is not so unusual and it may be
surprising that it fails.

vQ