similar to: Problem with S3 to S4 transition

Displaying 20 results from an estimated 7000 matches similar to: "Problem with S3 to S4 transition"

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
2009 Jun 05
2
Problem with generic methods
Hi I want to create a new generic method, but I end up with an error (evaluation nested too deeply). see the transcript below. The function beginYear.Fun() works, but not beginYear. I have no idea why. Any ideas welcome, Rainer > setClass("fun", representation(x = "numeric")) [1] "fun" > new("fun") An object of class ?fun? Slot "x":
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
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, ...) { } )
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
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
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' )
2007 Apr 19
2
setClass inside a function
Hello, I would like to create a function that gets passed a class name and then calls setClass, and a few other functions, inside. I have done this in the past with setmethod, creating accessors for all slots in a set of S4 classes. But setClass is choking when my function is called isnide a package, telling about an error in exists(cname, where). I assume this to be a problem with 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(
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
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"))
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 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'
2012 Nov 06
2
Question on callNextMethod
I don't understand why I get the following results. I define two classes 'Base' and 'Derived', the latter of which 'contains' the first. I then define a generic method 'test' and overload it for each of these classes. I call 'callNextMethod()' in the overload for Derived. From the output, it appears that the overload for Base gets called twice. Why is
2017 Jun 23
1
setReplaceMethod creates 'object' in the userworkspace
Hi, I recognized that the function 'setReplaceMethod' is creating a character vector in the user workspace having the name (e.g. "newClass") of the class used as value. If you can sort out a mistake by myself, I would like you to file a bug report. BBFN, Jonathan setClass("newClass", representation(value="numeric")) setMethod(f = "initialize",
2017 Jun 23
1
setReplaceMethod creates 'object' in the userworkspace
Hi, I recognized that the function 'setReplaceMethod' is creating a character vector in the user workspace having the name (e.g. "newClass") of the class used as value. If you can sort out a mistake by myself, I would like you to file a bug report. BBFN, Jonathan setClass("newClass", representation(value="numeric")) setMethod(f = "initialize",
2006 May 22
2
confused by inheritance...
Hi r-devels, I am stuck in some S4 inheritance problem: setClass("A",representation(a="numeric")) setClass("A1",representation(b="numeric"),contains="A") setClass("A2",representation(c="numeric"),contains="A1") if(!isGeneric("foo")){ setGeneric("foo", function(x,y,z, ...)
2010 Sep 07
1
Dispatch method on S3 or S4 class
Hello, I've been attempting to make a generic method that dispatches on the first argument, which can be either an S3 or an S4 class. This is as far as I've gotten. Any suggestions about what to try next ? library(aroma.affymetrix) library(GenomicRanges) setGeneric("analyse", function(x, y, ...) standardGeneric("analyse")) setMethodS3("analyse",
2020 Feb 19
2
Possible Regression in setClassUnion between 3.5.0 and 3.6.0
Thanks, I'll look into it. On Tue, Feb 18, 2020 at 8:32 AM Ezra Tucker <ezztucker at gmail.com> wrote: > > Hi Robert, > > This looks like a bug to me (tested in R 3.6.2 on Windows), f(new("a")) > should return "hi!". I'll add that this DOES work properly in 3.6.1 > which leads me to suspect this could be due to the subtle change in the > way
2010 Jun 23
2
format: different S4 behavior in a package
R-Devel-ers: I have an S4 method that simply formats an object: setGeneric("formatMe", function(x) standardGeneric("formatMe")) setMethod("formatMe", "ANY", function(x) format(x)) If I issue the above in an R session, then define an S4 class with its own format method, I get the desired result: > setClass("A",contains="numeric")