[R] how to update my own function

Edwin Sun csun at cfr.msstate.edu
Tue Nov 23 22:21:56 CET 2010


Hello all,

I wrote a function with many arguments. Then I need to call it many times
with changes on some arguments only. Is there any way to write a function or
have a method to "update" it, like the relationship between lm() and
update()?

Many thanks,

Edwin Sun

------------
This is the sample code.

> test <- function(y, z) { 
+   x <- y +1
+   w <- z * 2
+   result <- list(x=x, w=w)
+   class(result) <- "ego"
+   return(result)
+ }

> me <- test(y=3, z=4); me
$x
[1] 4

$w
[1] 8

attr(,"class")
[1] "ego"

> update(me, y=5)
Error in update.default(me, y = 5) : need an object with call component

-- 
View this message in context: http://r.789695.n4.nabble.com/how-to-update-my-own-function-tp3056256p3056256.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list