Re: [R] bug: Editing function formals deletes the environment

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

Ah, it's fixed in 2.4.0. I'll work around it.

-Alex

On 13 Oct 2006, at 11:19, Alex Brown wrote:

> 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.



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 21:23:56 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 - 13:30:08 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.