[R] FW: S4 classes, creating in C

Douglas Bates bates at stat.wisc.edu
Mon Jun 23 17:38:05 CEST 2003


Laurence Kell FM CEFAS <L.T.Kell at cefas.co.uk> writes:

>  
>  I am using C code to create an S4 object based on Douglas Bates's example
> in his lecture notes on
> <http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Tutorials/RExtensions/slide
> s.pdf>
> http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Tutorials/RExtensions/slides
> .pdf
> 
> e.g.
> 
> SEXP La_DGE_dc(SEXP A)
>         {
>         SEXP aa = PROTECT(duplicate(A));
>         SEXP adims, pivot, val;
>         int m, n, info;
>        
>         if (!isMatrix(aa) || !isReal(aa)) {
>                 error("A must be a double precision matrix");
>                 }
> 
>         adims = GET_DIM(aa); m = INTEGER(adims)[0]; n = INTEGER(adims)[1];
>         pivot = PROTECT(NEW_INTEGER(m < n ? m : n));
> 
>         F77_CALL(dgetrf)(&m, &n, REAL(aa), &m, INTEGER(pivot), &info);
>        
>         check_Lapack_error(info, "dtrtrf");
>        
>         val = PROTECT(NEW_OBJECT(MAKE_CLASS("LUdecomposition")));
> 
>         SET_SLOT(val, install("a"), aa);
>         SET_SLOT(val, install("pivot"), pivot);
>        
>         UNPROTECT(3);
>         return val;
>         }
> 
> LUdecomposition is an S4 class defined as
> 
> setClass("LUdecomposition", representation(a="matrix", pivot = "integer"))
> 
> This works in R 1.7.0 and R 1.7.1 but if I initialise any of the slots
> 
> setClass("LUdecomposition", representation(a="matrix", pivot = "integer"),
>                             prototype=list(pivot = NA)                    )
> 
> then I get the following error message in R 1.7.1 but not R 1.7.0
> 
> Error in makePrototypeFromClassDef(properties, ClassDef, immediate) :
>         In making the prototype for class "LUdecomposition" elements of the
> prototype
>         failed to match the corresponding slot class: pivot (class " integer
> ")
> 
> Why  can I no longer use the prototype to set the default values?

I'm not sure.  This may be the type of question that requires John
Chambers' attention and I think he is away from his email this week.




More information about the R-help mailing list