search for: setmethod

Displaying 20 results from an estimated 604 matches for "setmethod".

2010 Mar 16
1
Problem with S3 to S4 transition
...echanism and was convinced that I would have some benefit in turning everything on S4 formalism. This is the reason why I simply renamed my previous functions into DB.print and DB.plot (by analogy with other functions where the Class name is the leading part of the name). My idea was to use the setMethod principle to set the DB.print function as the function for the "print" method on the "DB" class. Therefore, in the .First.Lib file of my package, I introduced the setMethod line just after the setClass one, as in the following example: setClass("DB", re...
2006 Apr 13
2
[R] S4 method dispatch matrixOrArray (fwd)
What a delicious example! (I'm taking the liberty of sharing it with r-devel, since it raises some good issues.) You have two questions, presumably: 1 - how could the order of the setMethod calls make a difference in the results? 2 - what's causing the infinite loop & how could it be avoided, reliably? Second question first. The danger sign is the "vector" method: setMethod("foo", signature(A = "vector"), function(A, ...)...
2005 Jul 20
1
Default arguments for setMethod() (PR#8021)
Full_Name: Bert Gunter Version: 2.1.1 OS: Windows 2000 Submission from: (NULL) (192.12.78.250) There appears to be either a bug or documentation problem in setMethod/setGeneric with how default arguments are handled. The setMethod Help says: ****** Method definitions can have default expressions for arguments. If those arguments are then missing in the call to the generic function, the default expression in the method is used. If the method definition has no de...
2010 Jun 03
1
setMethod does not work in Window 7??
I am developing a S4 class but have had trouble to make setMethod work in Window 7. I tested an example found in the setMethod manual: > require(graphics) > setMethod("plot", signature(x="track", y="missing"), + function(x, y, ...) plot(slot(x, "x"), slot(x, "y"), ...) + ) It gave me: Er...
2006 Aug 30
1
setMethod() and log()
Hi I am having difficulty with setMethod(). I have a "brob" class of objects whose representation has two slots: "x" and "positive". Slot "x" (double) holds the log of a number and slot "positive" (logical) its sign. The idea is that large numbers can be handled. I'm trying...
2006 Mar 22
1
setting argument defaults in setMethod
Hi, I want to set a default value in a method of a generic function. This seems as though it should be possible. From R help on setMethod... Method definitions can have default expressions for arguments. If those arguments are then missing in the call to the generic function, the default expression in the method is used. If the method definition has no default for the argument, then the expression (if any...
2006 Sep 15
1
setMethod() woes
...){ stop(paste("binary operator \"", .Generic, "\" not defined for Brobdingnagian numbers")) } .ArithGlub <- function(e1,e2){ stop(paste("binary operator \"", .Generic, "\" not defined for Glub numbers")) } setMethod("Arith",signature(e1 = "brob", e2="brob"), .ArithBrob) setMethod("Arith",signature(e1 = "brob", e2="ANY" ), .ArithBrob) setMethod("Arith",signature(e1 = "ANY" , e2="brob"), .ArithBrob) setMethod("Arith&q...
2007 Aug 27
2
oddity with method definition
Just wondered about this curious behaviour. I'm trying to learn about classes. Basically setMethod works the first time, but does not seem to work the second time. Faheem. ************************************************************************* setClass("foo", representation(x="numeric")) bar <- function(o...
2013 Feb 14
4
2 setGeneric's, same name, different method signatures
...a value. class B's bB() compares values in two B objects, and returns the minimum, so bB(B1, B2) are its methods. after loading the file, i see the method for A's bB has disappeared (as measured by showMethods("bB"), as well as trying bB(A). if i have R re-parse the setGeneric/setMethod A's bB(), then B's bB() disappears. somehow my code, or my model of how things work, is wrong. any ideas what am i missing? cheers, Greg Minshall ---- setClass("A", representation( x="numeric")); setMethod( f="initialize", signature...
2006 Sep 01
1
setMethod("Logic", ...)
Hi In V&R the "polynomial" class is explicitly specified to have no logical operators: setMethod("Logic", signature(e1="polynomial"), function(e1,e2){stop ("...")}) I too have a class of objects for which I want to specify that Logic operators do not work, but executing setClass("brob", representation = representation (x="numeric&...
2011 Jan 26
1
Problem with "setMethod" in R package
...o the posting time and high traffic on this list. I experience a problem in implementing a S4 class in a package and would appreciate your help in this matter. The class is implemented using Rcpp, which works well. I then extend the class with R functions, adding them as methods with a call to setMethod(...). When I do this outside the package (after loading the package with "library(...)"), everything works smoothly. However, when I try to incorporate the call to setMethod(...) in the package code itself, the only way I get it to work is to include the call in .onLoad(...) or .onAtt...
2010 Feb 08
1
using setMethod or setGeneric to change S4 accessor symbol from @ to $
...sentially data frame objects. The S4 object definitions were necessary to verify data integrity and force a standardized data format. I am, however, finding myself redefining all the typical generic functions so that I can still manipulate my S4 objects as if they were data frames ... I have used setMethod to set methods for "subset", "head", and "tail". I would like to use setMethod or setGeneric to enable me to use object$slotname to access object@slotname for my S4 objects. Any advice is appreciated. Thanks. --Markus [[alternative HTML version deleted]]
2011 Oct 22
1
setMethod "[" - extract by names within Slot
Hi R-helper! I have problem with setMethods for "[". Here is example : setClass("myClass", representation(ID.r = "numeric", ID.c = "character", DAT = "matrix")) to.myClass <- function(ID.r, ID.c, DAT) {     out <- new("myClass", ID.r = ID.r, ID.c = ID.c, DAT = DAT)     retu...
2006 Feb 14
3
S4 classes and methods with optional arguments
...es to implement a unified access to random number generators (package rstream on CRAN). I have used a construct to allow optional arguments: if(!isGeneric("rstream.sample")) setGeneric("rstream.sample", function(stream,...) standardGeneric("rstream.sample")) setMethod("rstream.sample", c("rstream","numeric"), function(stream,n=1) { ... [ code ] ... } ) Thus if rs is an instance of an rstream object one can a random sample of size 10 using rstream.sample(rs, 10) for a sample of size 1 one can use equivalently rstream....
2010 Feb 26
2
New methods for generic functions show and print : some visible with ls(), some not
...object-oriented programming, but I still can't grasp completely what R is doing. I have a class definition for a class called PM10Meteo, and I set a initializer function. next, I include a show method and a print method as shown below. setClass( Class="PM10Meteo",...) # end setClass setMethod ("initialize",signature="PM10Meteo",...) # end setMethod ######## # Show Method # setMethod("show","PM10Meteo", function(object){ ... } # end function ) # end show method ####### # Print Method # setMethod("print","PM10Meteo", fun...
2012 Aug 05
2
setMethod sometimes fails to set package slot when signature has trailing 'ANY'
after this setClass("A") setGeneric("bar", function(x, y) standardGeneric("bar")) setMethod(bar, signature(x="A", y="A"), function(x, y) {}) setMethod(bar, signature(x="A", y="ANY"), function(x, y) {}) the method for signature c("A", "A") contains package information > str(getMethod(bar, c("A", "A")))...
2006 May 09
1
YA S4 method dispatch question
...t (third case) also provides the correct result. Example code follows: ##------------------------------------------------------------------------------ library(methods) setGeneric("foo", function(x, val = 500) { standardGeneric("foo") }) setMethod("foo", signature(x = "vector", val = "numeric"), function(x, val) { cat(match.call()[[1]], "(vector, numeric)", "\n") cat("\t", "val =", val, "\n") ## HERE ## #...
2004 Nov 18
1
Method dispatch S3/S4 through optimize()
I have been running into difficulties with dispatching on an S4 class defined in the SparseM package, when the method calls are inside a function passed as the f= argument to optimize() in functions in the spdep package. The S4 methods are typically defined as: setMethod("det","matrix.csr", function(x, ...) det(chol(x))^2) that is within setMethod() rather than by name before the setMethod(). When called from within functions passed as the f= argument to optimize, the S3 generics for det() and chol() get picked up, not the S4 generics for th...
2006 Jan 25
2
Using substitute from inside an S4 method
...passed to an S4 method. For a function, I would do this: f <- function(x) as.character(substitute(x)) This also works for a the examples I have tried for methods that do not have extra, non-dispatch args: setGeneric("A", function(x, ...) standardGeneric("A")) setMethod("A", signature(x="character"), function(x) as.character(substitute(x))) However, I'm seeing strange behavior if the method uses an extra argument: setMethod("A", signature(x="numeric"), function(x, y) as.character(substit...
2003 Jun 07
2
R CMD check: is it error to setMethod for class not currently defined?
Should R CMD check consider it an error to define a new method using setMethod for a class which is not currently defined? It seems to me that it would be best not to consider this an error. What currently happens in that setMethod issues a warning, quite correctly. This warning produces an object 'last.warning'. Then R CMD check issues a WARNING that 'last.wa...