From sfalcon at fhcrc.org  Sun Mar  4 18:23:06 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Sun, 04 Mar 2007 09:23:06 -0800
Subject: [Rd] Problem using callNextMethod() in S4
In-Reply-To: <45EAF340.50707@aon.at> (cstrato@aon.at's message of "Sun,
	04 Mar 2007 17:26:40 +0100")
References: <45EAF340.50707@aon.at>
Message-ID: <m2odn8apol.fsf@ziti.local>

cstrato <cstrato at aon.at> writes:

> Dear all,
>
> Maybe, I am doing something wrong, but using R-2.5.0 on my Intel-Mac, I 
> have problems
> using function callNextMethod() in method initialize.
>
> I am loading the following code as file "testS4.R":

I don't think this is the code in the same state as that which you ran
the examples.  Did you add/remove some comment lines perhaps?

After copy/pasting the code you posted, I get:

    > tmp<-new("derivedClass")
    [1] "---initialize:derivedClass---"
    [1] "mytitle =  MyTitle"
    > tmp<-new("derivedClass",myname="testname",mytitle="testitle")
    [1] "---initialize:derivedClass---"
    [1] "mytitle =  MyTitle"

> 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
> print(paste("myname = ",object at myname))
>       strg <- object at mydir;
>       if (!(is(strg, "character") && file.exists(strg))) {
>          warning(paste(sQuote("mydir"), "is not a system directory"));
>       }#if
>       if (substr(strg, nchar(strg), nchar(strg)) == "/") {
>          object at mydir <- substr(strg, 0, nchar(strg)-1);
>       }#if
> print(paste("mydir = ",object at mydir))
>    }
> )#setValidity

Your validity function isn't valid :-P It should either return TRUE or
return a character vector describing what isn't valid about the
object.  Don't call warning() or print().

Also, you don't need those ';'

And finally, you are operating on a _copy_ in the validity method
(just like everywhere else) and so this

>       if (substr(strg, nchar(strg), nchar(strg)) == "/") {
>          object at mydir <- substr(strg, 0, nchar(strg)-1);
>       }#if

will not have any effect on the instance passed in.  It is an odd
thing to do in a validity method.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



[Rd] Problem using callNextMethod() in S4
Seth Falcon