[R] using fix()
Ben Bolker
ben at zoo.ufl.edu
Sun Jan 9 21:35:34 CET 2000
1 function (x)
2 {
3 subx <- substitute(x)
4 if (is.name(subx))
5 subx <- deparse(subx)
6 if (!is.character(subx) || length(subx) != 1)
7 stop("fix requires a name")
8 if (exists(subx, inherits = TRUE))
9 x <- edit(get(subx))
10 else stop(paste("no object named \"", subx, "\" to edit",
11 sep = ""))
12 assign(subx, x, env = .GlobalEnv)
13 }
You could edit fix() so that lines 8-11 read:
if (!exists(subx, inherits = TRUE))
assign(subx,function() {}, env=.GlobalEnv)
x <- edit(get(subx))
I don't know if there's a better/sneakier/more robust way to do this.
On Sun, 9 Jan 2000, Tony Q. Zhang wrote:
> I guess this may be well-known question, but I did search through the
> mail archive without finding the answer. so please forgive me asking.
> My problem is that I cannot use fix() to edit function. If I use
> fix(my.fun), then, it will give a "object my.fun not found" error. I have
> to use my.fun <- function() {} first whenever I want to start a new
> function, which is annoying. How can I make the fix() behave like in
> splus?
>
> Thanks
> Tony
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
>
--
Ben Bolker bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
318 Carr Hall/Box 118525 tel: (352) 392-5697
Gainesville, FL 32611-8525 fax: (352) 392-3704
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list