similar to: S4 classes and S3 generic functions

Displaying 20 results from an estimated 30000 matches similar to: "S4 classes and S3 generic functions"

2017 Sep 22
2
S4 method implementation for S3 class
Hi all, I'm trying to implement the matrix multiplication operator, which is S4 generic, for an old-style S3 class. The following works as expected: x <- 1:10 class(x) <- "myClass" setOldClass("myClass") setGeneric("myMethod", function(x, y) standardGeneric("myMethod")) setMethod("myMethod", c("myClass", "myClass"),
2010 Jul 12
1
S4 class extends "data.frame", getDataPart sees "list"
R-Devel: When I get the data part of an S4 class that contains="data.frame", it gives me a list, even when the "data.frame" is the S4 version: > d<-data.frame(x=1:3) > isS4(d) [1] FALSE # of course > dS4<-new("data.frame",d) > isS4(dS4) [1] TRUE # ok > class(dS4) [1] "data.frame"
2017 Sep 22
2
S4 method implementation for S3 class
2017-09-22 19:04 GMT+02:00 Michael Lawrence <lawrence.michael at gene.com>: > The %*% function is a primitive. As it says in the documentation under > ?Methods_Details > > Methods may be defined for most primitives, and corresponding > metadata objects will be created to store them. Calls to the > primitive still go directly to the C code, which will
2009 Mar 18
1
Why S4 methods of S3 'base' generics are not used in 'base' functions ?
Dear list, It seems that S4 methods defined for an S3 'base' generic are not used in 'base' functions. This can be problematic when 'base' functions start with something like 'as.matrix'. ### START R code setClass("classA", contains = "matrix", representation(realData = "numeric")) setMethod("as.matrix",
2012 Dec 08
1
namespace S3 and S4 generic imports cannot both be satisfied:
PkgA wishes to write a method for 'unique' on S4 class 'A'. ?Methods indicates that one should setGeneric("unique") setClass("A") unique.A <- function(x, incomparables=FALSE, ...) {} setMethod(unique, "A", unique.A) Both S3 and S4 methods need to be exported in the NAMESPACE import(methods) S3method(unique, A)
2017 Sep 22
0
S4 method implementation for S3 class
The %*% function is a primitive. As it says in the documentation under ?Methods_Details Methods may be defined for most primitives, and corresponding metadata objects will be created to store them. Calls to the primitive still go directly to the C code, which will sometimes check for applicable methods. The definition of ?sometimes? is that methods must have been detected
2003 Jul 23
1
S3 and S4 classes
Hi helpers, I've been programming in R for a few months now but I still have doubts about my code - I would like it to be completely S4-compatible. The current code works fine but is probably 'unclean'. I read the interesting article in the last R News and it helped me understand the difference on the whole between S3 and S4 classes, but I need a practical example. Could anyone
2019 Nov 01
3
R C api for 'inherits' S3 and S4 objects
Dear R developers, Motivated by discussion about checking inheritance of S3 and S4 objects (in head matrix/array topic) I would light to shed some light on a minor gap about that matter in R C API. Currently we are able to check inheritance for S3 class objects from C in a robust way (no allocation, thread safe). This is unfortunately not possible for S4 classes. I would kindly request new
2008 Jan 07
2
S3 vs S4 for a simple package
I am writing a package and need to decide whether to use S3 or S4. I have a single class, "multipol"; this needs methods for "[" and "[<-" and I also need a print (or show) method and methods for arithmetic +- */^. In S4, an object of class "multipol" has one slot that holds an array. Objects of class "multipol" require specific arithmetic
2005 May 23
2
Documentation of S3 and S4 classes, inheritance
I'd like to have 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
2009 Jul 29
1
RFC: methods() and showMethods() {was "debug"}
(a new thread, on purpose) >>>>> "RobG" == Robert Gentleman <rgentlem at fhcrc.org> >>>>> on Mon, 27 Jul 2009 16:55:50 -0700 writes: RobG> Hi, I just committed a change to R-devel so that if RobG> debug is called on an S3 generic function, all methods RobG> will also automatically have debug turned on for them RobG>
2019 Nov 01
4
[External] R C api for 'inherits' S3 and S4 objects
Thank you Luke. That is why I don't use Rf_inherits but INHERITS which does not allocate, provided in the email body. I cannot do similarly for S4 classes, thus asking for some API for that. On Fri, Nov 1, 2019 at 5:56 PM Tierney, Luke <luke-tierney at uiowa.edu> wrote: > > On Fri, 1 Nov 2019, Jan Gorecki wrote: > > > Dear R developers, > > > > Motivated by
2012 Nov 22
1
Data Extraction - benchmark()
Hi Berend, I see you are one of the contributors to the rbecnhmark package. I am sorry that I am bothering you again. I have tried to run your code (slightly tweaked) involving the benchmark function, and I am getting the following error message. What am I doing wrong? Error in benchmark(d1 <- s1(df), d2 <- s2(df), d3 <- s3(df), d4 <- s4(df), : could not find function
2011 Sep 08
1
S4 - Upgrade options from S3
We've been running samba3 with an ldap backend for several years now in our company. We use a separate exchange server for email, requiring users to keep two separate passwords - one for the domain (samba) and one for exchange. I've been looking at samba4 for a while and am running a test server with it, built from the latest git source as per the howto description. We would be quite
2018 May 24
1
Creating S3 methods for S4 classes (coming from r-package-devel)
On Thu, May 24, 2018 at 6:20 PM, Michael Lawrence <lawrence.michael at gene.com > wrote: > You only have to make an S4 method if there is already an S4 generic. > If there is just an S3 generic, then just define S3 methods on it. I was refering to the recommendations in ?Methods_for_S3 ( https://stat.ethz.ch/R-manual/R-devel/library/methods/html/Methods_for_S3.html). : "Two
2014 Jul 06
2
Depot for S3 to S4 generics (as in stats4)?
Dear developers, the implementation of S4 generics for existing S3 ones in the base package is concerned to be a threat to quick startup times [1]. But since S4 is promoted, and S3/S4 interoperability a pain when package developing [2], are there efforts to improve the situation? E.g. an S3 free system, etc. A good thing [2] is the package 'stats4', including some setGeneric calls (e.g.
2014 Nov 17
1
common base functions stripping S3 class
Hi all --- this is less a specific question and more general regarding S3 classes. I've noticed that quite a few very common default implementations of generic functions (e.g. `unique`, `[`, `as.data.frame`) strip away class information. In some cases, it appears conditionals have been created to re-assign the class, but only for a few special types. For example, in `unique.default`, if the
2016 Jan 05
2
For integer vectors, `as(x, "numeric")` has no effect.
On Dec 19, 2015, at 3:32 AM, Martin Maechler <maechler at stat.math.ethz.ch> wrote: >>>>>> Martin Maechler <maechler at stat.math.ethz.ch> >>>>>> on Sat, 12 Dec 2015 10:32:51 +0100 writes: > >>>>>> John Chambers <jmc at r-project.org> >>>>>> on Fri, 11 Dec 2015 10:11:05 -0800 writes: >
2012 Nov 24
1
Adding a new variable to each element of a list
Hello, I have a list of data with multiple elements, and each element in the list has multiple variables in it. Here's an example: ### Make the fake data dv <- c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6) subject <- factor(c("s1","s1","s1","s2","s2","s2","s3","s3","s3",
2010 Oct 30
1
overloading "[" and "[<-" using S3 classes
How can I overload the "[" and "[<-" operators using S3 classes? Something like '['.{class} did not work or at least I do not know how to define it properly. For S4 it is straightforward: setMethod("[", signature(x = "myClass", i = "numeric"), function (x, i, j, ..., drop){ ... some operations }) How to do the same for S3? TIA!