From Rainer at krugs.de  Mon Oct  7 14:15:33 2013
From: Rainer at krugs.de (Rainer M Krug)
Date: Mon, 7 Oct 2013 14:15:33 +0200
Subject: [Rd] SOLVED:  check warning  with .onLoad() and setClass()
In-Reply-To: <706F64ED-1815-4E92-AF2A-F054580B27D4@r-project.org> (John
	Chambers's message of "Fri, 4 Oct 2013 09:56:44 -0700")
References: <m2zjqqfybi.fsf@krugs.de>
	<AD583E37-4E49-406C-B4A8-8F13C31E9B14@r-project.org>
	<m28uy9b8tu.fsf@krugs.de> <21070.43875.526391.331124@max.nulle.part>
	<m2fvshfd09.fsf@krugs.de> <21070.47559.867778.190980@max.nulle.part>
	<m238ohuo1s.fsf@krugs.de>
	<706F64ED-1815-4E92-AF2A-F054580B27D4@r-project.org>
Message-ID: <m2a9ili8ey.fsf_-_@krugs.de>

Thanks John and Dirk for your input.

I solved the problem by importing the package "simecol" which defines
the superclass simEcol in the NAMESPACE file with import(simEcol) and to
leave it in the DESCRIPTION file in the Depends section (as the
functions have to be available for the end user).

I reverted back to the .onLoad() function:

,----
| .onLoad <- function(libname, pkgname) {
|     setClass(
|         "inDrak",
|         representation(
|             init = "SpatialGridDataFrame"
|             ),
|         contains = "simObj"
|         )
| }
`----

and it works and does not give an error on R CMD check.

Thanks a lot,

Rainer



John Chambers <jmc at r-project.org> writes:

> The basic tool is setLoadActions(), which takes a function definition,
> with the package's namespace as its argument.  Read ?setLoadActions
>
> There is no such thing as setLoadFunction, as far as the standard code in R.
>
> While you haven't defined "didn't work", an off-the-top-of-the-head
> idea would be something like:
>
>    setLoadActions(function(ns) {setClass(....., where = ns)})
>
>
> On Oct 4, 2013, at 7:07 AM, Rainer M Krug <Rainer at krugs.de> wrote:
>
>> Dirk Eddelbuettel <edd at debian.org> writes:
>> 
>>> On 4 October 2013 at 14:15, Rainer M Krug wrote:
>>> | Hm. loadModule is Rcpp function, but I am only interested in using the
>>> | setClass() function, which has nothing to do with Rcpp. I don't even use
>>> | Rcpp in the package, only in one which is imported.
>>> 
>>> Sorry, assumed Reference Class created via Modules. My bad, and never mind.
>>> 
>>> But as John said, .onLoad() can be replaces since he made those changes in R
>>> (and also in Rcpp). See ?setLoadAction, evalOnLoad(), ...
>> 
>> Ok - theat far I folow you. But how do I implement this?
>> 
>> I have now the following .onLoad() function:
>> 
>> ,----
>> | .onLoad <- function(libname, pkgname) {
>> |     setClass(
>> |         "inDrak",
>> |         representation(
>> |             init = "SpatialGridDataFrame"
>> |             ),
>> |         contains = "simObj"
>> |         )
>> | }
>> `----
>> 
>> in the file ./R/onLoad.R in my package.
>> 
>> Now how can I now use the setLoadFunction()? I tried to simply put the
>> setClass in the setLoadFunction() as follow into the ./R/onLoad.R file:
>> 
>> ,----
>> | setLoadFunction( function(libname, pkgname) {
>> |     setClass(
>> |         "inDrak",
>> |         representation(
>> |             init = "SpatialGridDataFrame"
>> |             ),
>> |         contains = "simObj"
>> |         )
>> | }
>> `----
>> 
>> but this did not work. 
>> 
>> So what do I have to do with it? I only find very few examples using
>> setLoadFunction().
>> 
>> Rainer
>> 
>> 
>>> 
>>> Dirk
>> 
>> 
>> -- 
>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)
>> 
>> Centre of Excellence for Invasion Biology
>> Stellenbosch University
>> South Africa
>> 
>> Tel :       +33 - (0)9 53 10 27 44
>> Cell:       +33 - (0)6 85 62 59 98
>> Fax :       +33 - (0)9 58 10 27 44
>> 
>> Fax (D):    +49 - (0)3 21 21 25 22 44
>> 
>> email:      Rainer at krugs.de
>> 
>> Skype:      RMkrug
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer at krugs.de

Skype:      RMkrug



[Rd] SOLVED: check warning with .onLoad() and setClass()
Rainer M Krug