Displaying 20 results from an estimated 26 matches for "setvalid".
Did you mean:
setvalue
2007 Mar 31
1
Problem with S4 inheritance: unexpected re-initialization?
...:class(.Object) = SubSubClassA"
[1] "------initialize:BaseClass------"
[1] "BaseClass:init:class(.Object) = SubSubClassA"
[1] "------pathFile------"
[1] "BaseClass:init:dirfile =
/Volumes/CoreData/CRAN/Workspaces/rclasspkg/MyFileName"
[1] "------setValidity:BaseClass------"
[1] "BaseClass:val:class(object) = SubClassB"
[1] "BaseClass:val:dirfile =
/Volumes/CoreData/CRAN/Workspaces/rclasspkg/MyFileName"
[1] "BaseClass:val:filedir = /Volumes/CoreData/CRAN/Workspaces/rclasspkg"
[1] "------setValidity:SubClas...
2007 Dec 23
1
Problem with initialize of S4 classes
...toff : num 0.5
.. ..$ epsilon: num 0.01
..@ numfilters: num 1
It seems that everything is ok, the results are as expected.
However, my problem is that copying the identical code to my package
results in an error:
> prefltr <- new("PreFilter", mad=c(0.5,0.01))
[1] "------setValidity:Filter------"
Error in validObject(.Object) :
invalid class "PreFilter" object: invalid object for slot "mad" in
class "PreFilter": got class "numeric", should be or extend class "list"
The following code avoids the error and gives the r...
2004 Jun 18
0
Problem with setValidity() or resetClass() or ... ?
Hi,
I'm working with Version 1.9.0 (2004-04-12) on Windows 98/NT/2000 where
I found the following wrong (?) behavior of setValidity().
I already mentioned this on the R-help list (2004-06-11, was
"setValidity changes Extends?") , but as I got no answer I tried to
figure out what's happening.
Well, setValidity() behaves not as I would expect (something about the
superclasses is lost,
but nothing about the su...
2007 Mar 04
1
Problem using callNextMethod() in S4
...nitialize:baseClass---")
# .Object <- callNextMethod();
if (.Object at mydir == "") {
.Object at mydir <- as.character(getwd());
}#if
print(paste("mydir = ", .Object at mydir))
.Object <- callNextMethod();
.Object;
}
)#initialize
setValidity("baseClass",
function(object) {
print("---setValidity:baseClass---")
strg <- object at myname;
if (!(is(strg, "character") && nchar(strg) > 0)) {
warning(paste(sQuote("myname"), "is missing"));
}#if
pri...
2010 Mar 08
1
setClass or setValidity?
Hi,
I'm reading up on S4 classes *). There seem to be at least two ways of input validation:
setClass() (using the 'validity' argument) and setValidity(). Is it a matter of taste which function is used? Or should more complex validation code better be put in a setValiditity call?
*) A (Not So) Short Introduction to S4 Object Oriented Programming in R
V0.5.1 Christophe Genolini August 20, 2008
And, inside those validity checks, is most of th...
2008 May 07
1
optional setValidity()
Hi
Suppose I have an S4 class "foo" and a validity checking
function ".checkfoo()":
setClass("foo", representation=representation("numeric"))
setValidity("foo" , .checkfoo)
is fine; in my application, .checkfoo() verifies that a bunch
of necessary conditions are met.
But .checkfoo() is very time consuming and I want
to give users the option of switching it off.
Most foo objects that one deals with fall into two or three standard
ty...
2003 Nov 19
2
Was: setValidity and "initialize" method conflict ? [in R-help]
...-----------------------------------------------------
>setClass("Foo", representation(woo = "numeric"))
[1] "Foo"
>validFooObject <- function(object) {
+ if(object@woo > 0) return(TRUE)
+ else return("warning: negative value for woo")}
>setValidity("Foo", validFooObject)
[1] "Foo"
>new("Foo", woo = 1) # all is fine
An object of class "Foo"
Slot "woo":
[1] 1
>new("Foo", woo = -1) # ok, negative value
Error in validObject(.Object) : Invalid "Foo" object: warning:...
2009 Jul 09
1
How to: initialize, setValidity, copy-constructor
...A with a single numeric slot
setClass('A', representation(a='numeric'))
# define class B that extends class A, adding another numeric slot
setClass('B', representation('A', b='numeric'))
# we want for example to ensure that slots a and b have the same length
setValidity('B',
function(object){
cat("*** B::validate ***\n")
print(object)
cat("*****************\n")
if( length(object at a) != length(object at b) ) return('Inconsistent lengths')
TRUE
}
)
# As a default behaviour if b is not provided, we want slot b to be
equal to...
2007 Apr 19
2
setClass inside a function
...ss', name))")
foo <- c(foo, "return(TRUE)}")
eval(parse(text=foo))
# setClass
setClass(name, representation('array'),
prototype=prototype(array(as.numeric(NA), dim=dim, dimnames=dimnames), units='NA'),
validity=validity, where=sys.parent(n=-2))
# setValidity
setValidity(name, validity)
# constructors
eval(parse(text=paste("setGeneric('", name,
"', function(object, ...) standardGeneric('", name, "'))", sep="")))
setMethod(name, signature(object='ANY'),
function(object, ...)...
2019 Aug 19
1
class() bug when used within a validity method
...s is a long-standing bug where 'class(object)' does not
return the actual class of 'object' when used inside a validity
method. Instead it seems to return the class for which the validity
method is defined. For example:
setClass("A", slots=c(stuff="ANY"))
setValidity("A", function(object) {
cat("validating an object of class:", class(object), "\n")
TRUE
})
Then:
a <- new("A")
validObject(a)
# validating an object of class: A
# [1] TRUE
which is OK. But trying to validate an object that b...
2005 Aug 03
0
A question on validity checking for S4 classes
...indows.
I'm pretty sure the following is a failure of my understanding, rather than
a bug, so may I ask for some clarification?
The Green book states that (p. 295) "Objects are checked for validity when
permanently assigned, or explicitly by the function validObject()." The Help
for setValidity() seems silent on the details, however, and this does not
appear to be the R implementation. Here's an example to show why I think
not:
> setClass('posNumber','numeric')
[1] "posNumber"
> setValidity('posNumber',function(object)
+ if(any(object at .D...
2009 Mar 20
1
classes and methods
I have put together a test class and methods
> setClass("foo",representation(x="numeric"))
[1] "foo"
> setMethod("plot","foo",function(x,y,...)boxplot(x,...))
[1] "plot"
> x <- rnorm(100)
> class(x) <- "foo"
> plot(x)
> y <- new("foo",x=rnorm(50))
> class(y)
[1] "foo"
My
2005 Aug 15
16
swig_up
Tracing down some things to add in validators and I''ve run across
something that kinda bothers me...
In order to implement validators you have to override the clone method.
The directors seems to be set up to specifically handle this situation.
However, whenever C++ calls back to the object''s methods the swig_get_up
function is returning false. It seems like swig_up
2007 Jul 25
2
initalizing and checking validity of S4 classes
...check validity
f <- function(object)
{
rval <- NULL
if( length(object@v) != length(object@l) )
rval <- c( rval, "lengths dont match")
if( is.null(rval) ) return(TRUE)
else return(rval)
}
# this should return error description
f(o)
# define the validity method
setValidity( "someclass", f)
# this should return an error
new("someclass", v=1:2, l=letters[1:3])
# but it doesn't...
-e-n-d--r--c-o-d-e-
____________________________________
Michal Bojanowski
ICS / Department of Sociology
Utrecht University
Heidelberglaan 2; 3584 CS Utrecht...
2005 Mar 18
0
2 possible bugs in function validObject (PR#7735)
...ss("track",
representation(x = "numeric", y = "numeric"))
validTrackObject <- function(x){
if(length(x@x) == length(x@y)) TRUE
else paste("Oooo that's bad", LETTERS[1:4])
}
## assign the function as the validity method for the class
setValidity("track", validTrackObject)
## Now define class "field", to include a "track" slot:
setClass("field",
representation(t = "track", z = "character"))
setValidity("field", function(object) if (length(object@z) > 0)...
2008 Apr 15
1
Pb with validObject(..., complete=TRUE)
Hi,
When called with complete=TRUE, validObject() is supposed to work in a
recursive manner. But here is a situation where it doesn't seem to be
the case.
Let's define a class with a validity method:
setClass("PosInts", representation(ii="integer"))
setValidity("PosInts",
function(object)
{
if (!all(object at ii > 0))
return("'ii' slot contains non-positive values")
NULL
}
)
Let's extend this class (no need to add new slots for illustrating the pb):
setClass("PosInts2...
2004 Jan 29
2
Object validation and formal classes
I'm using R 1.8.1 (Win32, Linux) and have some difficulties using
validation functions for S4 classes. The problem is if I specify a
validation function with setValidity("myclass", validate.myclass) object
validation is only performed when I create an instance using
new("myclass"), or when I explicitly call validObject(x) where x is of
class "myclass", of course.
According to the reference docs, I would expect that validation a...
2008 Feb 29
1
Problems initializing an extended S4 class
...uld
simply extend A by adding an extra slot. The example is contrived, but
it illustrates a key behavior that I also encounter in my real code:
setClass("A", representation(x="numeric"))
setClass("B", representation(y="character"), contains="A")
setValidity("A", function(object) {
message("start validate A")
retval <- NULL
if (any(object at x<0))
retval <- c(retval, "x must be positive")
message("done validate A")
if(is.null(retval)) return(TRUE) else return(retval)...
2004 Jul 06
1
Enumeration in R
...value, "character"),
"3" = TRUE,
"5" = TRUE,
"7" = TRUE,
FALSE)
if (valid == FALSE)
return("Value not in list of valid values [3|5|7]");
return(TRUE);
}
setValidity("stoplightColor", valid.stoplightColor)
initialize.stoplightColor <- function(.Object, value) {
.Object at value <- as.integer(value)
.Object
}
setMethod("initialize",
signature(.Object = "stoplightColor"),
initialize.stoplightColor...
2012 Jun 18
1
S4 into a data frame
Greetings,
I'm still very new to R; however I have been tasked with converting an S4
object into a data.frame. We are just trying to learn the basics of S4.
Could anyone offer a 'simple' example of coercing an S4 object (such as
might be stored in a package attribute) into a data.frame? Ultimately, we
would like to do something along the lines of
mydata <- as.data.frame(original