search for: nextmethod

Displaying 20 results from an estimated 187 matches for "nextmethod".

2012 Oct 17
1
Do *not* pass '...' to NextMethod() - it'll do it for you; missing documentation, a bug or just me?
Hi, although I've done S3 dispatching for more than a decade now, I think I managed to overlook/avoid the following pitfall when using NextMethod(): If you explicitly pass argument '...' to NextMethod(), you will effectively pass those argument twice to the "next" method! EXAMPLE: foo0 <- function(...) UseMethod("foo0"); foo1 <- function(...) UseMethod("foo1"); foo2 <- function(...) UseMetho...
2010 Feb 14
1
NextMethod() example from S Programming by Venables and Ripley (page 78)
S Programming by Venables and Ripley (page 78) has the example listed at the end of this email. However, I get the following error when I try the example. I don't understand the descriptions of NextMethod on its help page. Could somebody let me know how to fix the error of this example? > test(x) c1 c2 Error in NextMethod() : no method to invoke Calls: test -> test.c1 -> NextMethod -> test.c2 -> NextMethod Execution halted #### test=function(x) UseMethod('test') test.c1=fun...
2018 Feb 22
2
How to modify dots and dispatch NextMethod
On 02/22/2018 12:07 PM, I?aki ?car wrote: > 2018-02-22 10:29 GMT+01:00 Tomas Kalibera <tomas.kalibera at gmail.com>: >> The example is invoking NextMethod via an anonymous function, which is not >> allowed (see documentation for NextMethod). > Thanks for your response. I definitely missed that bit. > >> Normally one gets a runtime >> error "'NextMethod' called from an anonymous function", but not here as the...
2006 Apr 14
3
The object argument of NextMethod.
My question is when the object argument of NexthMethod be used? In the following example, weather object argument is used will not affects the result. ### foo=function(x) {UseMethod("foo")} foo.cls1=function(x) { x=x+1;class(x)<-"ncls" NextMethod() } foo.ncls=function(x) { cat("ncls\n") } foo.cls2=function(x) { cat("cls2\n");print(x) } a=1;class(a)=c("cls1","cls2") > foo(a) cls2 [1] 2 attr(,"class") [1] "ncls" ### > foo=function(x) {UseMethod("foo")} > >...
2018 Feb 22
2
How to modify dots and dispatch NextMethod
The example is invoking NextMethod via an anonymous function, which is not allowed (see documentation for NextMethod). Normally one gets a runtime error "'NextMethod' called from an anonymous function", but not here as the anonymous function is called via do.call. I will fix so that there is a runtime error in...
1999 Apr 16
1
NextMethod
...nces. The "if it's not broken don't fix it" principle makes me reluctant to consider the following, but... In cleaning up parts of my library I realized that many of my old summary methods actually print things instead of returning an object for a print method. Some of these use NextMethod, and I've always been even more confused by NextMethod than by UseMethod. Is the following a good model of how this should be done: summary.level1.level2 <- function(object) { r <- list("level2 before") r <- append(r,NextMethod("summary")) r <- append(r,&quo...
2004 Oct 28
1
Another problem with next method
I have another problem with NextMethod. Not sure if its related to the last problem. In this example, we have a generic called ff with methods for AsIs and test classes. We call the generic with an object of AsIs class. The corresponding method adds 1 to it and then changes the class to test followed by issuing a NextMethod. Howeve...
2018 Feb 20
2
How to modify dots and dispatch NextMethod
Hi all, Not sure if this belongs to R-devel or R-package-devel. Anyways... Suppose we have objects of class c("foo", "bar"), and there are two S3 methods c.foo, c.bar. In c.foo, I'm trying to modify the dots and forward the dispatch using NextMethod without any success. This is what I've tried so far: c.foo <- function(..., recursive=FALSE) { dots <- list(...) # inspect and modify dots # ... do.call( function(..., recursive=FALSE) structure(NextMethod("c"), class="foo"), c(dots, recursive=recursiv...
2019 Aug 07
1
NextMethod() and argument laziness
Hi all, I'd like to ask if the following behavior is a bug. To me it certainly feels surprising, at the very least. In this example, I would like to call NextMethod() from my `child` object, have `cols` be left untouched, and then substitute(cols) in the parent method. It works when you use a `parent` object (as expected), but I would have also expected to get `mpg` back when calling it from the `child` method. my_generic <- function(x, cols) { UseMethod...
2005 Dec 21
3
NextMethod causes R 2.2.0 to crash (PR#8416)
I found writing the following default method the for the generic function "julian" causes R to crash. julian.default <- function(x, ...) { x <- as.Date(x) NextMethod("julian", x, ...) } Here is a test example > m <- as.Date("1972-09-27") + 0:10 > m [1] "1972-09-27" "1972-09-28" "1972-09-29" "1972-09-30" "1972-10-01" "1972-10-02" "1972-10-03" [8] "1972-1...
2018 Feb 22
0
How to modify dots and dispatch NextMethod
2018-02-22 12:39 GMT+01:00 Tomas Kalibera <tomas.kalibera at gmail.com>: > On 02/22/2018 12:07 PM, I?aki ?car wrote: >> >> 2018-02-22 10:29 GMT+01:00 Tomas Kalibera <tomas.kalibera at gmail.com>: >>> >>> The example is invoking NextMethod via an anonymous function, which is >>> not >>> allowed (see documentation for NextMethod). >> >> Thanks for your response. I definitely missed that bit. >> >>> Normally one gets a runtime >>> error "'NextMethod' called from an anon...
1997 Dec 02
1
R-alpha: NextMethod in 0.50-a4
I am encountering difficulty with NextMethod in 0.50-a4. We created a class of groupedData objects which are data.frames with additional attributes. The most important attribute is a formula describing roles of some of the variables in the experimental design. The class of such objects ends in "groupedData", "data.frame&quot...
2006 Mar 07
3
Making an S3 object act like a data.frame
"[.ggobiDataset" <- function(x, ..., drop=FALSE) { x <- as.data.frame(x) NextMethod("[", x) } "[[.ggobiDataset" <- function(x, ..., drop=FALSE) { x <- as.data.frame(x) NextMethod("[[", x) } "$.ggobiDataset" <- function(x, ..., drop=FALSE) { x <- as.data.frame(x) NextMethod("$", x) } > class(x) [1] "ggobiD...
2001 Dec 11
4
crash bug in get("function.name")() (PR#1211)
R : Copyright 2001, The R Development Core Team Version 1.3.1 (2001-08-31) > tmp <- factor(1:3) > get("print.factor")(tmp) [1] 1 2 3 Levels: 1 2 3 > print.a <- function(x,...) { + print("this is a") + NextMethod("print", x, quote = FALSE, right = TRUE, ...) + } > > get("print.a") function(x,...) { print("this is a") NextMethod("print", x, quote = FALSE, right = TRUE, ...) } > print.a(tmp) [1] "this is a" [1] 1 2 3 Levels: 1 2 3 > get(&quo...
2010 Apr 23
0
dot dot dot and NextMethod
...ethod for the "pmin" function. I first make "pmin" generic pmin <- function (..., na.rm = FALSE) UseMethod("pmin") pmin.default <- base::pmin Now, within my new method, I would like to change the arguments in . (dot dot dot) before sending it to the NextMethod. pmin.myobject <- function(., na.rm=FALSE){ args <- list(.) # Here, I change my args. For example: args <- lapply(args, function(x) x + 1) # and now, I would like to use NextMethod, and then rebuild the ....
2010 Jul 22
1
class
...w("A") myB=new("B")   ####  I created functions for "A" and "B"   f1=function(x,...) UseMethod("f") f.default=function(x,...){     print("default")  }  f.A=function(x,...) {      print(paste("x@s1=", x@s1, sep=""))      NextMethod()  }  f.B=function(x,...) {      print(paste("x@s2=", x@s2, sep=""))      NextMethod()  }   #### when I do  f1(myB) ## R gave me the result [1] "x@s2=hi" [1] "default" ## but I think the result should be [1] "x@s2=hi" [1] "x@s1=8" [1] &qu...
1998 Jan 03
1
R-beta: NextMethod(.Generic) bug
I'm a day-old R newbie (but a war-weary S veteran), with couple of first-day questions: In R 0.61, this code fails. Ops.test <- function(e1,e2) { e1 <- NextMethod(.Generic) e1 } x <- 4 class(x) <- "test" y <- x < 3 The error message is "Error in NextMethod(.Generic) : negative length vectors are not allowed.". I assume it is a bug. It works in Splus 3.4. Is there a fix/workaround? Also, why doesn't the &qu...
2005 May 23
2
Documentation of S3 and S4 classes, inheritance
...e a class A that computes a likelihood, and a subclass B that computes the same likelihood by sometimes throws in an additional term (B includes measurement error). So B's likelihood needs to call A's, and then (sometimes) multiply by an additional term. It sounds as if, in the S3 scheme, NextMethod is supposed to do this: like.A <- function(stuff) compute value like.B <- function(stuff) extraFactor*NextMethod() ? but, after some study of both the Language Manual (2.1) and the online help of NextMethod I can't tell exactly what it does. In particular, I'm not sure if it return...
2018 Feb 21
0
How to modify dots and dispatch NextMethod
...: > Hi all, > > Not sure if this belongs to R-devel or R-package-devel. Anyways... > > Suppose we have objects of class c("foo", "bar"), and there are two S3 > methods c.foo, c.bar. In c.foo, I'm trying to modify the dots and > forward the dispatch using NextMethod without any success. This is > what I've tried so far: > > c.foo <- function(..., recursive=FALSE) { > dots <- list(...) > # inspect and modify dots > # ... > do.call( > function(..., recursive=FALSE) structure(NextMethod("c"), class="foo...
2006 Sep 22
2
behavior of [<-.foo
...nly inserts into the first column: > x <- matrix(rnorm(10),nrow=5,ncol=2) > class(x) <- "foo" > "[<-.foo" <- function(x, i, j, value) { + if(missing(i)) i <- 1:nrow(x) + if(missing(j)) j <- 1:ncol(x) + + x <- unclass(x) + x <- NextMethod(.Generic) + class(x) <- "foo" + x + } > > x[] <- 100.0 > x [,1] [,2] [1,] 100 -0.1465296 [2,] 100 -0.2615796 [3,] 100 -0.8882629 [4,] 100 -0.2886357 [5,] 100 -0.9565273 attr(,"class") [1] "foo" Based on the behavior of [<- fo...