[R] OOP and passing by value

From: michael meyer <mjhmeyer_at_googlemail.com>
Date: Wed, 09 Jun 2010 14:28:46 +0200


Greetings,

I love the R system and am sincerely grateful for the great effort the product and contributors
are delivering.

My question is as follows:

I am trying to use S4 style classes but cannot write functions that modify an object
because paramter passing is by value.
For example I want to do this:

setGeneric("setData", function(this,fcn,k){ standardGeneric("setData") })

setClass(
  "test",
  representation(f="numeric", t="numeric")
)

setMethod("setData","test",
  function(this,fcn,k){
    this_at_t <- as.numeric(seq(-k,k))/(2*k+1)     this_at_f <- sapply(t,FUN=fcn)
  }
)

#-----------------------------------------------------------
tst <- new("test")
fcn <- function(u){ sin(2*pi*u) }
setData(tst,fcn,100)
tst_at_t # it's still empty because of pass by value

How can this be handled?

Many thanks,

Michael

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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 Wed 09 Jun 2010 - 12:36:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jun 2010 - 13:30:28 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.

list of date sections of archive