From roger at ysidro.econ.uiuc.edu  Sat Nov 27 17:12:00 2004
From: roger at ysidro.econ.uiuc.edu (roger koenker)
Date: Sat Nov 27 17:12:00 2004
Subject: [Rd] Namespaces, coercion and setAs
In-Reply-To: <1059.132.180.246.92.1101550298.squirrel@mail.uni-bayreuth.de>
References: <Pine.LNX.4.44.0411261922360.7240-100000@reclus.nhh.no>
	<DAFB50C4-3FDA-11D9-9DB8-000393A361A2@ysidro.econ.uiuc.edu>
	<1059.132.180.246.92.1101550298.squirrel@mail.uni-bayreuth.de>
Message-ID: <11E1CB74-408F-11D9-BBD9-000393A361A2@ysidro.econ.uiuc.edu>

Yes,  precisely.  This was done yesterday and the new version of SparseM
with NAMESPACE -- thanks again to Roger Bivand for his help with this --
should now be on CRAN.


On Nov 27, 2004, at 4:11 AM, Matthias.Kohl@uni-bayreuth.de wrote:

> Hello,
>
> does adding the line
>
> \alias{coerce,numeric,matrix.diag.csr-method}
>
> to the Rd-file of your "matrix.diag.csr" class solve the mysterium?
>
> Matthias
>
>
>> Absolutely correct.  Adding coerce to the NAMESPACE list of
>> exportMethods
>> resolves the problem.  Leaves only the mildly mysterious
>>
>> Undocumented S4 methods:
>>    generic coerce and siglist numeric,matrix.diag.csr
>> All user-level objects in a package (including S4 classes and methods)
>> should have documentation entries.
>>
>> to clean up.  Thanks very much!!
>>
>> Roger
>>
>> On Nov 26, 2004, at 12:29 PM, Roger Bivand wrote:
>>
>>> On Fri, 26 Nov 2004, roger koenker wrote:
>>>
>>>> I'm trying to resolve a small problem that has arisen from
>>>> introducing a
>>>> NAMESPACE for the package SparseM.  Prior to the namespace I had a
>>>> class
>>>> "matrix.diag.csr" that consisted of diagonal sparse matrices.  It 
>>>> was
>>>> defined to have the same attributes as the matrix.csr class and 
>>>> setAs
>>>> was used to define how to coerce integers and vectors into this 
>>>> form:
>>>>
>>>> setClass("matrix.diag.csr","matrix.csr")
>>>>
>>>> setAs("numeric","matrix.diag.csr",function(from){
>>>>          if(length(from)==1){
>>>>                  n <- as.integer(from)
>>>>                  if(n>0) from  <-  rep(1,n)
>>>>                  else stop("Sparse identity matrices must have
>>>> positive,
>>>> integer dimension")
>>>>                  }
>>>>          else n <- length(from)
>>>>          return(new("matrix.diag.csr", ra = from ,ja =
>>>> as.integer(1:n),
>>>>                  ia = as.integer(1:(n+1)), dimension =
>>>> as.integer(c(n,n))))
>>>>          })
>>>>
>>>> This seemed to be fine.   I could do,
>>>>
>>>> 	A  <- as(5,"matrix.diag.csr")
>>>>
>>>> and A would be a 5x5 identity matrix in sparse form.  But
>>>> post-namespace
>>>> I get:
>>>>
>>>>> A <- as(5,"matrix.diag.csr") Error in as(5, "matrix.diag.csr") : No
>>>> method or default for coercing "numeric" to "matrix.diag.csr"
>>>>
>>>> so apparently using exportClass(matrix.diag.csr)  isn't sufficient
>>>> for coerce to know what to do. Using findClass("matrix.diag.csr")
>>>> indicates
>>>> that the class is recognized to be from SparseM, so my question is:
>>>> is
>>>> there some mechanism that I'm missing in the NAMESPACE scheme that
>>>> would
>>>> enable my old setAs() directive to work, or is there some other
>>>> suggestion on how to proceed?
>>>
>>> I'm far from sure about this, but is "coerce" one of the exported
>>> methods?
>>> I'm having the same difficulty in retrofitting a NAMESPACE to the
>>> forthcoming sp package of spatial classes, for S4 classes.
>>>
>>> I see from src/library/methods/NAMESPACE that as and coerce are
>>> exported
>>> from there - should a package with a NAMESPACE and S4 classes do
>>>
>>> import(methods) ?
>>>
>>> Roger
>>>
>>>>
>>>>
>>>> url:	www.econ.uiuc.edu/~roger        	Roger Koenker
>>>> email	rkoenker@uiuc.edu			Department of Economics
>>>> vox: 	217-333-4558				University of Illinois
>>>> fax:   	217-244-6678				Champaign, IL 61820
>>>>
>>>> ______________________________________________
>>>> R-devel@stat.math.ethz.ch mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> --
>>> Roger Bivand
>>> Economic Geography Section, Department of Economics, Norwegian School
>>> of
>>> Economics and Business Administration, Breiviksveien 40, N-5045
>>> Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
>>> e-mail: Roger.Bivand@nhh.no
>>>
>>
>> ______________________________________________
>> R-devel@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>
>


[Rd] Namespaces, coercion and setAs
roger koenker