[R] bug: Editing function formals deletes the environment

From: Alex Brown <alex_at_transitive.com>
Date: Fri 13 Oct 2006 - 10:19:31 GMT


First, here's the specific bug I have. Later I'll say why I care.

> ls(zappo)

Error in try(name) : object "zappo" not found # good.
> f = function(zappo) { function(y) zappo + y }
> g = f(1)
> g(1)
[1] 2

> formals(g)

$y

> formals(g)$y
> formals(g)$y = 2
> g
function (y = 2)
zappo + y
> g(1)

Error in g(1) : object "zappo" not found

# looks like formals strips the environment off stuff.

anything I can do about this?

-Alex

Original question:

I'm trying to change the behaviour of a package, to simplify the interface.

I'd rather not change the package, although I could.

There's a hidden function whose defaults I wish to change.

I'm using R 2.3.1 for macosX. Upgrading is not an option.

This is what I do:

library(R2HTML)

# get the function to modify
x = getFromNamespace("HTML.data.frame", "R2HTML") # change the default for an argument
formals(x)["Border"]=list(NULL)
# put the function back
assignInNamespace("HTML.data.frame", x, "R2HTML")

#test the function:

HTML(data.frame(1:2), file=stdout())

Error: could not find function "HTMLReplaceNA"

# what seems to be happening is that the formals function is stripping the namespace off the variable x. I can't tell why.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Oct 13 22:38:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 13 Oct 2006 - 17:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.