[R] two problem in writing R functions

vito muggeo vito.muggeo at giustizia.it
Tue Jul 2 13:02:36 CEST 2002


Hi all,
Although I'm able to manage functions in R, because I'm writing my first
package I'd like to optmize them, but I'm not so expert to do it and I spent
a lot of my time without success. So I was wonder whether someone could give
me some advice. Let the function
myfn<-function(glm.obj,....){ #glm.obj is a glm object
.....
class(out)<- c("myclass",class(obj))
out}

 I'm stuck on the following two problem:
1) My function needs global assignment (otherwise it doesn't work)
Instead of using "<<-", I used something like
assign("X",x,envir=sys.frame()) #to build
rm(X,envir=sys.frame()) #to delete
However if there is some X variable in the workspace, it is deleted too. (In
practice it works as the simple "<<-" and this should be avoided, of
course).
I could use .X but the problem isn't yet solved

2)I'd like that summary.myclass() works like summary.glm, printing further
information from the obj. Following summary.negbin() in MASS library from
V&R:
summary.myclass<-function(x,dispersion=NULL,correlation=FALSE){
cat(".....")
summ<-c(summary.glm(x,dispersion=dispersion, correlation=correlation),
x[c("name1","name2")])
summ
}
but it doesn't work! The obj is printed with all its component!
$call
$terms
$family
....
$name1
$name2

Where am I wronging?
Thank you very much,
vito
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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