search for: callgeneric

Displaying 20 results from an estimated 43 matches for "callgeneric".

2006 May 10
1
What is callGeneric used for?
I've recently come across two pieces of code using calls to callGeneric() inside the definition of a method. In both cases, it appears to me that the callGeneric call could be replaced with a "real" call to the generic, say foo(x) instead of callGeneric(x) inside method foo. My understanding from the docs is that when called with arguments, it is just like...
2004 Jun 07
1
Lazy Evaluation?
...ist(fun = "function")) NumFunction <- function(f) new("NumFunction", fun = f) square <- function(x) x^2 NF <- NumFunction(square) setMethod("Math", "NumFunction", function(x){ nfun <- function(n) callGeneric(x at fun(n)) tmp <- function(n) nfun(n) NumFunction(tmp) }) sinNF <- sin(NF) sinNF at fun(sqrt(pi/2)) # works as expected, returns 1 # now a slightly different version of setMethod("Math", "NumFunction", # ...), which disp...
2012 Jul 22
0
callGeneric(...) and lazy evaluation
There seems to be an issue with passing "..." to callGeneric(), because it assumes that the call can be evaluated in the parent frame. Due to lazy evaluation, that is often not going to work for arguments that are simply passed down via "...". Here is an example: setClass("A", contains = "character") setClass("B", co...
2006 May 09
1
YA S4 method dispatch question
...;, signature(x = "vector", val = "numeric"), function(x, val) { cat(match.call()[[1]], "(vector, numeric)", "\n") cat("\t", "val =", val, "\n") ## HERE ## # return(drop(callGeneric(matrix(x, nrow = 1), val))) return(drop(callGeneric(array(x, c(1, length(x)), val)))) # return(drop(callGeneric(xm <- array(x, c(1, length(x))), val))) }) setMethod("foo", signature(x = "vector"), function(x, val) {...
2009 Nov 25
1
group generics
...tClass("B", representation=representation(xb="numeric"), contains=c("A") ) setMethod("Arith", signature(e1="numeric", e2="B"), function(e1, e2) { # the next line does not work right v <- selectMethod("callGeneric", signature=c("numeric", "A"))(e1, e2) print(v) new("B", v, xb=e1*e2 at xb) } ) Results: > t1 <- new("B", new("A", xa=4), xb=2) > t1 An object of class ?B? Slot "xb": [1] 2 Slot "xa": [1] 4 > 3*t1 Error i...
2010 Aug 26
1
Passing arguments between S4 methods fails within a function:bug? example with raster package.
...here is a method xyValues defined with the signature (object="RasterLayer",xy="matrix"). There is also a method with signature (object="Raster",xy="vector"). The only thing this method does, is change xy into a matrix and then pass on to the next method using callGeneric again. Arguments are passed. Now this all works smoothly, as long as you stay in the global environment : require(raster) a <- raster() a[] <- 1:ncell(a) origin <- c(-80,50) eff.dist <- 100000 unlist(xyValues(a,xy=origin,buffer=eff.dist)) [1] 14140 14141 14500 14501 Now let's m...
2005 Jun 20
3
How to define S4 methods for '['
...,representation(dat='matrix', id='character') ) I wish to define a '[' method for foo that will extract from the 'dat' slot. I would have thought that the following would work, but it doesn't: setMethod("[","foo",function(x,i, j, .,drop=TRUE)callGeneric(x@dat,i, j,drop=drop) ) The only way I have succeeded in defining this method is using brute force eval(parse(. : {eval(parse(text=paste('.dat(x)[', ifelse(missing(i),',','i,'), ifelse(missing(j),']','j]')))) } This works. However,...
2009 Jun 15
1
S4: Bug in group method defenition ("Compare")
...ce one method is set ,redefining it or even removing does not change the behavior: setClass("foo" ,representation(range="numeric") ) #[1] "foo" setMethod("Compare",c(e1="ANY",e2="foo"), function(e1,e2){ browser() callGeneric(e1,e2 at range) }) #[1] "Compare" o<-new("foo",range=c(1,2)) 2>o #Called from: 2 > o #Browse[1]> #[1] TRUE FALSE ##Enters browser as expected !!! # Now, remove browser() setMethod("Compare",c(e1="ANY",e2="foo"), function(e1,...
2007 Dec 24
0
callNextMethod() with builtin group methods fails to create proper environment
...hod("Compare", signature(e1="Foo", e2="Foo"), function(e1, e2) { callNextMethod() }) [1] "Compare" > f1 = new("Foo") > f1 == f1 Error in get(fname, envir = envir) : variable ".nextMethod" was not found 7: get(fname, envir = envir) 6: callGeneric(e1 at .Data, e2 at .Data) 5: .nextMethod(e1 = e1, e2 = e2) 4: .Call("R_nextMethodCall", call, callEnv, PACKAGE = "methods") 3: callNextMethod() 2: f1 == f1 1: f1 == f1 It appears that the issue occurs because the particular set of branches through the logic of callNextMethod()...
2004 Jun 26
1
S4 group "Math", "getGroupMembers", "genericForPrimitive"
...########## ## Example Code ################################################### ## Example Code from the "green book" setClass("track", representation(x = "numeric", y = "numeric")) setMethod("Math", "track", function(x){ x@y = callGeneric(x@y); x }) tr1 <- new("track", x = 1:3, y = 1:3) tr1 ## are documented as belonging to group "Math" ## see ?"Math" ## but don't work log(tr1) log10(tr1) gamma(tr1) lgamma(tr1) ## are not generic and don't belong to any group! is("log", "gen...
2013 Feb 14
1
mapply error with Math (S4 group generic)
...racter'". Does anyone understand why? The problem is illustrated below. Thanks, Robert > # First a general example that works > setClass('Foo',representation (value = 'numeric')) > setMethod("Math", signature(x='Foo'),function(x){ x@value <- callGeneric(x@value); x } ) [1] "Math" > f <- new('Foo') > f@value = 1 > ff <- list(f,f) > e1 <- exp(f) > e2 <- mapply(exp, ff) > e3 <- mapply(function(x)exp(x), ff) > # Now for the raster package that also has the Math group generic implemented > libr...
2005 Dec 29
1
trouble with S4 methods for group "Summary"
...> setClass("track", representation(x="numeric", y="character")) [1] "track" > setGeneric("max", group="Summary") [1] "max" > setMethod("Summary", signature(x="track"), function(x, ..., na.rm) callGeneric(x at x, ..., na.rm)) [1] "Summary" > dd<-new("track", x=c(1,2), y="abc") > max(dd) [1] -Inf Warning message: no finite arguments to max; returning -Inf > showMethods("max") Function "max": na.rm = "ANY" na.rm = &quo...
2006 Apr 12
1
S4 method dispatch matrixOrArray
..."foo", function(A, ...) { cat("generic", match.call()[[1]], "\n") standardGeneric("foo") }) setMethod("foo", signature(A = "vector"), function(A, ...) { callGeneric(matrix(A, nrow = 1), ...) }) setClassUnion("matrixOrArray", c("matrix", "array")) setMethod("foo", signature(A = "matrixOrArray"), function(A, ...) { cat("A =", A, "\n") })...
2008 Feb 29
1
inheritence in S4
Hi the list I define a class A (slot a and b), a class C (slot c and d) and a class E that inherit from A and B. I define print(A) and print(B). For print(C), I would like to use both of them, but I do not see how... Thanks for your help... Christophe ---------------------------------------------------------------- Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
2003 Oct 09
1
S4 group generic Complex not working (PR#4483)
The Complex group generic for S4 methods is not working: > setClass('foo', representation(z='complex')) [1] "foo" > setMethod('Complex', 'foo', function(z) callGeneric(z@z)) [1] "Complex" > Arg(new('foo', z=1+0i)) Error in Arg(new("foo", z = 1 + (0+0i))) : non-numeric argument to function > The fix is to add if (DispatchGroup("Complex", call, op, args, env, &x)) return x; near the beginning of do...
2005 Jul 19
1
S4 Dispatching
...etMethod("onthefly", signature(mydata = "character"), function(mydata) { cat(match.call()[[1]], "(character)\n") # Simulating EXTPTRSXP mydata <- list(name = "mydata") class(mydata) <- "mydata" callGeneric(mydata) }) setMethod("onthefly", signature(mydata = "mydata"), function(mydata) { cat(match.call()[[1]], "(mydata)\n") str(mydata) }) > version _ platform powerpc-apple-darwin7.9.0 arch powerpc os darwin7.9...
2008 Aug 07
1
'"ts" treated as a registered S3 class, but keep its "structure" behaviour' ?
...- new("foo", 1:10, header = "foo") ts <- ts(1:10) foo / ts ## but the problem appears when one defines an "Ops" method for class "foo" setMethod("Ops", c("foo", "foo"), function(e1, e2) { .Data <- callGeneric(e1 at .Data, e2 at .Data) header <- paste(e1 at header, e2 at header, sep = "_") new("foo", .Data, header = header) }) foo <- new("foo", 1:10, header = "foo") foo + foo ts <- ts(1:10) foo / ts # Error in getDa...
2006 Apr 13
2
[R] S4 method dispatch matrixOrArray (fwd)
...quot;\n") >>>> standardGeneric("foo") >>>> }) >>>> >>>>setMethod("foo", >>>> signature(A = "vector"), >>>> function(A, ...) { >>>> callGeneric(matrix(A, nrow = 1), ...) >>>> }) >>>> >>>>setClassUnion("matrixOrArray", c("matrix", "array")) >>>> >>>>setMethod("foo", >>>> signature(A = "matrixOrArray"), &g...
2005 Oct 05
0
Asterisk 1.0.9-BRIstuffed-0.2.0-RC8o memory leak when using call files ?
Hi all, I'm using Asterisk 1.0.9-BRIstuffed-0.2.0-RC8o on box A with a TE410P (EuroISDN cpe) connected to another similar asterisk box B acting as EuroISDN master. I'm performing some load tests by contiously feeding up to concurrent 30 call files to /var/spool/asterisk/outgoing/ on box A which inititate via a dialplan context/extension a outbound call (redirected via chan_local) to
2006 Aug 30
1
setMethod() and log()
...cumsum =, exp =, floor =, gamma =, lgamma =, sin =, sinh =, tan =, tanh =, trunc = as.brob(callGeneric(as.numeric(x))), stop(paste(.Generic, "not allowed on Brobdingnagian numbers")) ) } ) -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-805...