similar to: Problem with generic methods

Displaying 20 results from an estimated 10000 matches similar to: "Problem with generic methods"

2006 Oct 19
1
default arguments in generics and methods
i believe the following is true but would appreciate confirmation that it is intended behavior and will continue: if a default argument is employed in the definition of a generic function, and the generic is called with the argument in question (call it 'ARG') missing, then the method for signature (..., ARG = "missing", ...) will be called by 'standardGeneric'
2011 Aug 23
1
Implementing a "plugin" paradigm with R methods
Dear list, I was wondering how to best implement some sort of a "plugin" paradigm using R methods and the dispatcher: Say we have a function/method ('foo') that does something useful, but that should be open for extension in ONE specific area by OTHERS using my package. Of course they could go ahead and write a whole new 'foo' method including the features they'd
2013 Feb 14
4
2 setGeneric's, same name, different method signatures
hi. below is a small test case (hopefully minimal, though i'm still a bit confused about initializers). i would have guessed (and maybe i still would have been right) that one could re-use the name of a generic function for functions with different numbers of arguments. in the case below, class A's bB() queries the status of a single A object, so bB(A) (where here "A" is an
2005 Dec 29
1
trouble with S4 methods for group "Summary"
Hello. This question concerns the Methods package. I have created a new class and am trying to set a method for it for S4 group generic "Summary". I have run into some signature problems. An example: > setClass("track", representation(x="numeric", y="character")) [1] "track" > setGeneric("max", group="Summary")
2005 Jan 19
2
signif() generic
Dear list, I'm trying to write a class for Gaussian error propagation of measured values and their (estimated) errors, > setClass("sec", representation(val="numeric", err="numeric")) I've already successfully implemented basic arithmetics using mostly the "Arith" group generics. But I'm running into trouble when trying to get signif() to
2009 Oct 27
1
How to reduce key strokes when defining S4 classes?
I feel tedious when I define a S4 class and the methods. For each method, I have to call both setMethod and setGeneric (or both setReplaceMethod and setGeneric). I would like a more compact grammar so that I can reduce the key strokes. I'm wondering if there is a better way available. setClass( Class='A', representation=representation( x='numeric' )
2010 Jul 21
1
Bug: broken exception handling in S4 methods
Hi all: we have noticed for quite a while that certain errors cannot be handled by R try, tryCatch etc blocks, but it was fairly difficult to understand what were the conditions for this incorrect behaviour. Finally I stabbed across a very understandable case, which is outlined in the (runnable) example below. The main message is: wrapping an S4 method call in a try block will not help if an
2008 May 10
2
Hashes as S4 Classes, or: How to separate environments
For learning purposes mainly I attempted to implement hashes/maps/dictionaries (Python lingua) as S4 classes, see the coding below. I came across some rough S4 edges, but in the end it worked (for one dictionary). When testing ones sees that the dictionaries D1 and D2 share their environments D1 at hash and D2 at hash, though I thought a new and empty environment would be generated each time
2003 Sep 27
2
does isGeneric work differently in 1.8.0 ?
Hello, the last command (isGeneric) in following R-code (attached) produces different output, depending on wheter 1.8.0 alpha or 1.7.1 is used. Is that to be expected ? Both R Versions were started with option vanilla --------------------------------------------------- R.1.7.1: --------------------------------------------------- > version _ platform i686-pc-linux-gnu arch i686
2012 Nov 21
1
S3 generic/method consistency issue with R CMD check
Hi, I'm having some trouble setting methods for the qr family of functions. I believe I have distilled my misunderstanding in the code snippet below: foo <- function(x, ...) UseMethod("foo") foo.default <- function(x) { } # foo setGeneric(name = "foo", useAsDefault = foo) setMethod("foo", signature(x="bar"), function(x, ...) { } )
2006 Feb 14
3
S4 classes and methods with optional arguments
Hi, i have used S4 classes 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",
2010 May 12
1
slot assignment in S4 classes
Hi R friends,   I'm still studying S4 classes and I have a question about slot assignment. Why would I have to use a special setter method [example 2 below] if I can assign data to a slot directly when I call new() [example 1 below]?   ## first way to do it (the idiosyncratic way?) setClass(Class = "TestClass", representation = representation(myDf = "data.frame"))
2013 Oct 03
1
check warning with .onLoad() and setClass()
Hi I am writing a package in which I define a new class in the .onLoad() hook: ,---- | .onLoad <- function(libname, pkgname) { | setClass( | "inDrak", | representation( | init = "SpatialGridDataFrame" | ), | contains = "simObj" | ) | } `---- The class "simObj" is defined in the package, which
2004 Jun 26
1
S4 group "Math", "getGroupMembers", "genericForPrimitive"
Hi, I found the following on Windows 2000/NT R Version 1.9.1 (2004-06-21) (also Version 1.9.0): The S4 group "Math" doesn't work as documented; i.e., "log", "log10", "gamma" and "lgamma" are included in the documentation but don't work. See example code below. Moreover, what about 'genericForPrimitive' which is used in
2010 Apr 21
1
VERY basic question about S4 classes
Hi,   I'm new to R and S4 classes. I defined a class with two methods (myMethod1 and myMethod2). I want to call myMethod1 within myMethod2. Why does the code below not work? The name 'myMethod1' doesn't appear to have meaning inside myMethod2, even though the two methods belong to the same class.     setClass(Class="SomeClass",      representation=representation(      
2006 Oct 11
1
dispatching on group generics with more than one formal
please see the code below. foo2 fails to dispatch correctly, but foo does fine. i have tried 'cacheMetaData(1)' and a number of different variants of 'cacheGenericsMetaData', on the possibility there is a caching issue. but i still can't sort it out. also one general question: does it really matter what's in the body of the function definition in a
2005 Mar 25
1
S4 methods semantics questions
Some quick questions about S4 methods. Does the typing of S4 methods mean that lazy evaluation is no longer possible? It seems that you would need to evaluate the arguments to determine their type at dispatch. Second, what role, if any, do default arguments play in S4 methods? I notice that you can put default arguments into generics but that the dispatch is still done on the type of the
2020 Feb 18
2
Possible Regression in setClassUnion between 3.5.0 and 3.6.0
I am trying to create a class union of class unions to facilitate method dispatch. When I execute code in the global environment, everything acts as expected, however when I put the same code in the context of a package, selectMethod can no longer find the correct method. This first block below puts the code in the context of a package: fn <- "codefile.R" writeLines( c(
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
2008 Jan 22
1
deparse, substitute and S4 generics
Hello everyone, I encountered the following confusing behavior of 'deparse' and 'substitute' while programming with S4 classes (see example below). It seems like the presence of '...' argument in the definition of the generic generates the problem. I have no clue why, can anyone explain that to me? Are there any "workarounds"? Thanks a lot for your time!