Displaying 20 results from an estimated 20000 matches similar to: "Can "prototype" and "initialize" coexist?"
2003 Nov 19
2
Was: setValidity and "initialize" method conflict ? [in R-help]
Hello,
Thomas Stabla (statho3@web.de) has already sent this
question to R-help, Wed, 12 Nov 2003 21:21:31 +0100,
but we are not sure whether we should better post this
mail to this audience than to R-help:
---------------------------------------------------------------------
We are using S4-classes and want to force a validity check
when an object is created.
How can this be done, when an
2010 Feb 02
1
S4 setClass / initialize misunderstanding
Hi, I recently ran into this problem. I couldn't find any mention of it in
the setClass documentation.
setClass("Foo", representation(file = "character"))
setMethod("initialize", "Foo", function(.Object, file) {
print(file)
})
setClass("Bar", contains = "Foo")
And the error:
Error in print(file) : argument "file" is
2009 Oct 26
1
Why 'validity' is not called? (S4)
I thought that 'validity' defined in 'setClass' should be called in
'new'. Could somebody let me know why 'validity' is not called? How to
make it be called?
> setClass(
+ Class='A',
+ representation=representation(
+ x='numeric'
+ ),
+ validity=function(object){
+ cat("~~~ A: inspector ~~~\n")
+
2007 Dec 23
1
Problem with initialize of S4 classes
Dear all
Below is the code for "scriptPreFilter.R" which gives the following result:
> source("scriptPreFilter.R")
> prefltr <- new("PreFilter", mad=c(0.5,0.01))
[1] "------initialize:PreFilter------"
[1] "------initialize:Filter------"
> str(prefltr)
Formal class 'PreFilter' [package ".GlobalEnv"] with 2 slots
2007 Jul 25
2
initalizing and checking validity of S4 classes
Dear useRs and wizaRds,
I am currently developing a set of functions using S4 classes. On the way I encountered the problem exemplified with the code below. For some reason the 'validity' method does not seem to work, i.e. does not check for errors in the specification of the slots of the defined class. Any hints?
My understanding of the whole S4 system was that validity checks are made
2006 May 11
2
S4 initialize methods, unexpected recursive callNextMethod
Hi,
Given a simple three class hierarchy: A <-- B <-- C
I want to define an initialize method for each class such that when I
call new("C", x=5), the initialize methods for A and B are used to
incrementally build the object.
When I do what seems obvious to me using callNextMethod, I get an
infinite recursion. An example follows...
setClass("A",
2008 Feb 29
1
Problems initializing an extended S4 class
Hi all,
I am having trouble extending S4 classes in cases where I'm using both
validity and initialize methods. I've read as much S4 information as I
can find, but I've yet to have that "a-ha" moment.
In my application, I am using validity methods to guard against
inappropriate input data that my code has no way of handling, and
initialize methods to detect and deal
2009 Jul 09
1
How to: initialize, setValidity, copy-constructor
Hello list,
I'm having troubles setting up a basic calss hierarchy with S4.
Here is a simplified schema of what I'd like to do:
- Two classes: A and B that extends A
- Ensure that the slots added by B are consistent with the slots of A
- Let A initialize itself (I'm not supposed to know the internal cooking
of A)
- By default set the slots of B based on the slots that A initialized
2013 Feb 05
1
S4 Classes and Initialize methods
Hello,
I am trying to improve my skill on S4 classes. But there's something
strange (to me) happening with "initialize" methods. This is probably a
normal behaviour... but... something is unclear in my mind
I declare two classes, namely "A", and "B", which has a slot of type A. The
class "A" has an initialize method. What I do not understand is that
2009 Jun 05
2
S4: When is validObject issued? (or why S4 is killing me:( ..
Dear UseRs,
Does anyone know when exactly the validity is checked in S4? Documentation is silent:(.
Here is a small example:
setClass("test1",representation(a="numeric"))
setMethod("initialize","test1",
function(.Object,...){
a<-runif(1) ## here slot "a" is initialized ##
callNextMethod(.Object,a=a,...)
2003 Mar 17
1
What does is() mean?
Suppose you have a class, say sex, for lack of a better example, and
you are tempted, in defining the behavior of the call,
is(x,"sex")
to check whether certain basic features are satisfied, not to just trust the claim
that x is specified to be of class "sex". `Without delving into details
further sanity checking of the structure of the object is sometimes prudent to
avoid
2011 Mar 11
1
WARNING Undocumented S4 methods 'initialize' - why?
Dear all,
I am just writing the documentation file for S4 class 'QualTreeSet' and
get the following warning with R CMD check:
* checking for missing documentation entries ... WARNING
Undocumented S4 methods:
generic 'initialize' and siglist 'QualTreeSet'
All user-level objects in a package (including S4 classes and methods)
should have documentation entries.
See the
2005 Aug 05
1
S4 generating function
Can someone explain what the problem is when I use the
generating function? And how to get debug() to stop in
the Superclass initialize method?
---- source -----
setClass("Superclass",
representation(id = "character"),
contains = "VIRTUAL")
setMethod("initialize",
signature(.Object = "Superclass"),
2008 Apr 14
3
Doing the right amount of copy for large data frames.
Hi there,
Problem ::
When one tries to change one or some of the columns of a data.frame, R makes
a copy of the whole data.frame using the '*tmp*' mechanism (this does not
happen for components of a list, tracemem( ) on R-2.6.2 says so).
Suggested solution ::
Store the columns of the data.frame as a list inside of an environment slot
of an S4 class, and define the '[',
2009 Jun 29
1
S4 and connection slot [Sec=Unclassified]
Hi all,
I am having a problem trying to declare a slot representation to hold a file connection.
With V2.8.0 I had been using:
setClass("Element",
representation(
[other slots removed],
datafileConn = setOldClass(c("file","connection"))
)
)
This resulted in a warning but still ran okay.
No however with V2.9.0 I am getting
2003 May 21
1
callNextMethod
Hi,
I don't understand why this code doesn't work (f(b2)):
/////////////////
setClass("B0", representation(b0 = "numeric"))
setClass("B1", representation("B0", b1 = "character"))
setClass("B2", representation("B1", b2 = "logical"))
f <- function(x) class(x)
setMethod("f", "B0",
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
2010 Jul 20
1
Extract callNextMethod "array" calls "matrix"?
I have a class that extends array and my method for "[" stops with an error:
> setClass("A", contains="array")
[1] "A"
> setMethod("[", "A", function(x, i, j, ..., drop = TRUE) new("A",
callNextMethod()))
[1] "["
> a<-new("A",array(1:12,c(4,3,1)))
> a
An object of class "A"
, , 1
2015 May 28
3
S4 inheritance and old class
Hey everyone,
I would like to develop a package using S4 classes.
I have to define several S4 classes that inherits from each others as
follow:
# A <- B <- C <- D
I also would like to define .DollarNames methods for these class so, if I
have understood well, I also have to define an old class as follow:
# AOld <- A <- B <- C <- D
setOldClass(Classes = "AOld")
2008 Feb 08
2
learning S4
Hi the list.
I try to learn the S4 programming. I find the wiki and several doc. But
I still have few questions...
1. To define 'representation', we can use two syntax :
- representation=list(temps = 'numeric',traj = 'matrix')
- representation(temps = 'numeric',traj = 'matrix')
Is there any difference ?
2. 'validityMethod' check the