[Rd] S4 class, passing argument names to function, modify original

From: <soeren.vogel_at_uzh.ch>
Date: Sat, 04 Jun 2011 12:07:00 +0200

Hello, an S4 class "Foo" is defined with a setter, $. For several reasons, the setter calls a function, .foo.update(). However, bypassing the argument names of the setter does not work. Question 1: Why not and how can I fix this? Question 2: What is the way to define either the function or the setter to modify the original object (not returning the modified copy of it an overwrite the original by assignment)? Thanks, Sören

    N = "numeric"
    N = 10000

.foo.update <- function(object, ...) {
  args <- list(...)
  for (i in slotNames("Foo")[pmatch(names(args), slotNames("Foo"), nomatch=0)]) {     slot(object, i) <- args[[i]]
    # indeed more to do here

setReplaceMethod("$", "Foo",
  function(x, name, value) {

    x <- .foo.update(x, name=value)

x <- new("Foo")
x$N <- 99
x # NULL????

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 04 Jun 2011 - 10:14:10 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Sat 04 Jun 2011 - 14:40:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive