Displaying 20 results from an estimated 8000 matches similar to: ""registering" a generic method for a class"
2011 Jun 06
1
Seeking help to define method for show() for an S4 object
Dear all, I have created a new S4 class with name "MyClass". Please see
below for it's definition. Now I want to create a
method for the show() function for this class. In defining this method, what
I want is, once user would like see an object of this class
some values will be displayed. Then R will ask for **press Enter**. Once
user presses enter then, remaining values will be
2005 Dec 07
1
Dots argument in apply method
Hello everyone,
I'm working on a package using S4 classes and methods and I ran into the
following "problem" when I tried to create an "apply" method for objects
of one of my new classes. I've found a way around the problem but I
wonder if I did not paint myself into the corner. I'd like your opinion
about that.
So I have an object "myObj" of class
2011 Feb 01
1
Help need to define method of an s4 class
I need some help in defining a "print" method for my new S4 class
definition. So fer I have worked like this:
setClass("MyClass", sealed=F, representation(slot1 = "list", #create a
new class
slot2 = "vector",
slot3 = "vector",
slot4 = "vector"))
setMethod("print",
2005 Jun 02
1
showMethods doubt
Hi,
I'm developing in S4 and I wanted to see the methods for a specific
class using showMethods but I didn't succed. Can someone help ? See the
example below.
setClass("myclass",
representation(
name ="character"
)
)
setGeneric("mymeth", function(obj, ...){
standardGeneric("mymeth")
}
)
setMethod("mymeth",
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
Dear all,
Assume that I have an S4 class "MyClass" with a slot "myname", which
is initialized to: myname="" in method("initialize"):
myclass <- new("MyClass", myname="")
Assume that class "MyClass" has a method "mymethod":
"mymethod.MyClass" <-
function(object, myname=character(0), ...) {
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"),
2014 Jan 07
1
Why do methods of "initialize" have no "srcref" attribute as other S4 mehtods?
For documentation we use a system that generates Rd files from special
comments in the code. (inlinedocs).
It is crucial to be able to get the defining source code for objects like
methods to extract the comments from it.
Here is an R session that shows how this works for several kinds of methods
and (at the end of the session) how if fails for methods of "initialize"
>
2004 Nov 11
1
"<<-" assignment no long work in class methods
Hi-
I used to use "<<-" to do assignment inside a class method, and
just found that now it is broken in R 2.0. For example, the
following code
-----------------------------------------------------------------------
setClass( "myclass", representation(x="numeric") )
setGeneric("incrXByOne", function(obj) standardGeneric("incrXByOne"))
2008 Mar 20
1
setMethod for "["
Hi R-Help,
Please consider the following simple case: I have a class like
setClass("myClass",
representation(x="matrix", y="character"))
and I would like to use the method *"["* for a *myClass* objects (but
changing the default *drop* argument from TRUE to FALSE):
setMethod("[","myClass",
function(x,i,j,...,drop=FALSE)
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)
return(out)
}
setMethod("[",
2002 Jul 19
1
Rprof and setMethod conflict?
I noticed this oddity about R profiling and setMethod.
First, I "test out" Rprof.
> require(methods)
Loading required package: methods
[1] TRUE
>
> Rprof("test.out")
> data.frame("a")
X.a.
1 a
> Rprof(NULL)
So far, so good. Next, I define myClass.
> setClass("myClass", representation(mySlot = "numeric"))
[1]
2003 Dec 02
1
setMethod("min", "myclass", ...)
Hello,
I have defined a new class
> setClass("myclass", representation(min = "numeric", max = "numeric"))
and want to write accessor functions, so that for
> foo = new("myclass", min = 0, max = 1)
> min(foo) # prints 0
> max(foo) # prints 1
At first i created a generic function for "min"
> setGeneric("min",
2002 Aug 06
2
[ and setMethod conflict?
I noticed this oddity about [ and setMethod.
First, I define testFunc, which sorts a data frame by the first column and
returns the entries that aren't NAs, and testIt, which runs testFunc
repeatedly on a random large data frame, each time saving the return into a
dummy placeholder (for demonstration's sake).
> require(methods)
Loading required package: methods
[1] TRUE
> testFunc
2002 Aug 06
2
[ and setMethod conflict?
I noticed this oddity about [ and setMethod.
First, I define testFunc, which sorts a data frame by the first column and
returns the entries that aren't NAs, and testIt, which runs testFunc
repeatedly on a random large data frame, each time saving the return into a
dummy placeholder (for demonstration's sake).
> require(methods)
Loading required package: methods
[1] TRUE
> testFunc
2010 Jun 13
1
S4 classes and S3 generic functions
A general goal for the next version of R is to make S4 and S3 play
better together.
As mentioned in a previous thread, one limitation has been that S3
generic functions, specifically the UseMethod() call, did not make use
of S4 inheritance when dispatching on general S4 objects.
This has been fixed in a version committed today (updated to rev 52267).
The code change is not large, but it
2008 Apr 07
3
Overriding axis formatting with custom Axis method, Axis.numeric etc
Dear list:
I would like to override the default way R formats plot axes with a
custom method(s). Obviously I would prefer to define it as general as
possible avoiding writing a custom method for each individual class
where possible.
The plot.default method (and I assume other methods as well) calls
Axis(...) to produce the axis layout depending on data. In this sense it
seems reasonable to
2009 Jan 19
1
pass by reference for S4
Hi all;
Is it possible to modify the "@" operator that it can handle references
(or external pointers)
of S4 Object instead of the real Objects?
Or is there any technical or compatibility issue which make it
impossible?
I look forward to hear from you and also hope that you don't hate me for
my nooby question.
Yours sincerely,
Rudolf Biczok
[[alternative
2002 Dec 30
2
Writing packages with `methods' package
I'm trying to write a package which uses classes/methods as defined in the
`methods' package. I have a single .R file which defines the class and
various methods for that class. At the top of the file I have
require(methods)
and then
setClass("myclass", ...)
setGeneric("intersect")
setMethod("intersect", "myclass", function(x,y) ...)
I noticed
2004 May 28
1
Is there a way to represent the ... argument in signature?
Hi!
I guess that it cant work. but maybee I am wrong.
I would like to define a function rbind.
> rbind
function (..., deparse.level = 1)
{
which works only for objects of class Myclass
Is it possible to use something like
setMethod("rbind",signature(...="Myclass",deparse.level="numeric")
This gives an error.
Or should I use
rbind.Myclass
Eryk.
Dipl. bio-chem.
2002 Sep 10
1
adding a method to a class
Hello,
I don't see how to add a method to a class.
I can add "slots" (and retreive them by : myObject at slot1)
but not methods, for example accessor for these slots
and others functions.
I've read the "methods" library documentation but I can't figure out how to
do this.
Thanks for any help/tips
Vincent