From jmc at r-project.org  Thu Oct  3 19:03:29 2013
From: jmc at r-project.org (John Chambers)
Date: Thu, 3 Oct 2013 10:03:29 -0700
Subject: [Rd] check warning  with .onLoad() and setClass()
In-Reply-To: <m2zjqqfybi.fsf@krugs.de>
References: <m2zjqqfybi.fsf@krugs.de>
Message-ID: <AD583E37-4E49-406C-B4A8-8F13C31E9B14@r-project.org>

Don't use .onLoad() to set class (or other nontrivial) information at load time.  Use setLoadActions(), which was created exactly to get around the limitations of .onLoad().

For an example, see the Rcpp package, which uses this to set up load-time C++ linkages.

John Chambers

On Oct 3, 2013, at 3:22 AM, Rainer M Krug <Rainer at krugs.de> wrote:

> Hi
> 
> I am writing a package in which I define a new class in the .onLoad()
> hook:
> 
> ,----
> | .onLoad <- function(libname, pkgname) {
> |     setClass(
> |         "inDrak",
> |         representation(
> |             init = "SpatialGridDataFrame"
> |             ),
> |         contains = "simObj"
> |         )
> | }
> `----
> 
> The class "simObj" is defined in the package, which is in the depends
> section in the DESCRIPTION file:
> 
> ,----
> | Package: InDrak
> | Type: Package
> | Title: Alien spread management simulation model for the Drakensberg
> | Version: 0.1-0
> | Date: 2013-10-03_11-55
> | Author: Rainer M. Krug
> | Maintainer: Rainer M Krug <Rainer at krugs.de>
> | Description: Simulate the spread of three Invasive Alien Plants under different
> |     management and budget scenarios
> | License: GPL-3
> | LazyLoad: yes
> | Depends:
> |     RSQLite,
> |     simecol
> | Imports:
> |     methods,
> |     sp,
> |     spgrass6,
> |     DBI,
> |     logger,
> |     fireSim,
> |     seedProd,
> |     seedGerm,
> |     seedDisp
> | LinkingTo: Rcpp
> | Collate:
> |     'beginYear.R'
> |     'clearAliens.R'
> |     'competition.R'
> |     'cumulativeDc.R'
> |     'dcToIndLayer.R'
> |     'dispProb2D.R'
> |     'endYear.R'
> |     'fireAliens.R'
> |     'germEst.R'
> |     'initfunc.R'
> |     'layerIO.R'
> |     'layerNames.R'
> |     'main.R'
> |     'newInDrak.R'
> |     'onLoad.R'
> |     'package.R'
> |     'parameter.R'
> |     'parmsAcacia.R'
> |     'parmsBudget.R'
> |     'parmsFire.R'
> |     'parmsPinus.R'
> |     'parmsRubus.R'
> |     'resetOptions.R'
> |     'seedDispersal.R'
> |     'seedProduction.R'
> |     'stats.R'
> `----
> 
> If important, the NAMESPACE file is here:
> 
> ,----
> | export(depRateName)
> | export(exportRaster)
> | export(fireLayerName)
> | export(ignitionRiskName)
> | export(importAliens)
> | export(importClearingHistory)
> | export(importFireHistory)
> | export(importIgnitionRisk)
> | export(importSpecies)
> | export(importVegetation)
> | export(layerExists)
> | export(layerName)
> | export(newInDrak)
> | export(parameter)
> | export(parmsAcacia)
> | export(parmsBudget)
> | export(parmsFire)
> | export(parmsPinus)
> | export(parmsRubus)
> | export(resetOptions)
> | export(statDistName)
> | export(suitName)
> | import(DBI)
> | import(fireSim)
> | import(logger)
> | import(methods)
> | import(seedDisp)
> | import(seedGerm)
> | import(seedProd)
> | import(sp)
> | import(spgrass6)
> `----
> 
> The package builds fine, it installs without problems and works as
> expected, but when checking it, I get the following error:
> 
> ,----
> | $ R CMD check ./InDrak_0.1-0.tar.gz 
> | * using log directory ?/Users/rainerkrug/Documents/Projects/R-Packages/inDrak/InDrak.Rcheck?
> | * using R version 3.0.1 (2013-05-16)
> | * using platform: x86_64-apple-darwin10.8.0 (64-bit)
> | * using session charset: UTF-8
> | * checking for file ?InDrak/DESCRIPTION? ... OK
> | * checking extension type ... Package
> | * this is package ?InDrak? version ?0.1-0?
> | * checking package namespace information ... OK
> | * checking package dependencies ... OK
> | * checking if this is a source package ... OK
> | * checking if there is a namespace ... OK
> | * checking for executable files ... OK
> | * checking for hidden files and directories ... OK
> | * checking for portable file names ... OK
> | * checking for sufficient/correct file permissions ... OK
> | * checking whether package ?InDrak? can be installed ... OK
> | * checking installed package size ... OK
> | * checking package directory ... OK
> | * checking DESCRIPTION meta-information ... OK
> | * checking top-level files ... OK
> | * checking for left-over files ... OK
> | * checking index information ... OK
> | * checking package subdirectories ... OK
> | * checking R files for non-ASCII characters ... OK
> | * checking R files for syntax errors ... OK
> | * checking whether the package can be loaded ... OK
> | * checking whether the package can be loaded with stated dependencies ... OK
> | * checking whether the package can be unloaded cleanly ... OK
> | * checking whether the namespace can be loaded with stated dependencies ... WARNING
> | Error: .onLoad failed in loadNamespace() for ?InDrak?, details:
> |   call: reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, 
> |   error: no definition was found for superclass ?simObj? in the specification of class ?inDrak?
> | Execution halted
> | 
> | A namespace must be able to be loaded with just the base namespace
> | loaded: otherwise if the namespace gets loaded by a saved object, the
> | session will be unable to start.
> | 
> | Probably some imports need to be declared in the NAMESPACE file.
> | * checking whether the namespace can be unloaded cleanly ... WARNING
> | Error: .onLoad failed in loadNamespace() for ?InDrak?, details:
> |   call: reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, 
> |   error: no definition was found for superclass ?simObj? in the specification of class ?inDrak?
> | Execution halted
> | * checking loading without being on the library search path ... OK
> | * checking for unstated dependencies in R code ... OK
> | * checking S3 generic/method consistency ... OK
> | * checking replacement functions ... OK
> | * checking foreign function calls ... OK
> | * checking R code for possible problems ... NOTE
> | .initfunc: no visible global function definition for
> |   ?initialSeedProductionAliens?
> | .initfunc: no visible global function definition for ?endYear?
> | .main: no visible global function definition for ?beginYear?
> | .main: no visible global function definition for ?fireAliens?
> | .main: no visible global function definition for ?seedProductionAliens?
> | .main: no visible global function definition for ?seedDispersalAliens?
> | .main: no visible global function definition for ?germEstAliens?
> | .main: no visible global function definition for ?endYear?
> | * checking Rd files ... OK
> | * checking Rd metadata ... OK
> | * checking Rd cross-references ... OK
> | * checking for missing documentation entries ... OK
> | * checking for code/documentation mismatches ... OK
> | * checking Rd \usage sections ... OK
> | * checking Rd contents ... OK
> | * checking for unstated dependencies in examples ... OK
> | * checking examples ... NONE
> | * checking PDF version of manual ... OK
> | 
> | WARNING: There were 2 warnings.
> | NOTE: There was 1 note.
> | See
> |   ?/Users/rainerkrug/Documents/Projects/R-Packages/inDrak/InDrak.Rcheck/00check.log?
> | for details.
> `----
> 
> I am sure I am missing something simple here and I really think I
> overlooked it in the "Writing R extensions"...
> 
> Thanks,
> 
> Rainer
> 
> -- 
> Rainer M. Krug
> 
> email: RMKrug<at>gmail<dot>com
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] check warning with .onLoad() and setClass()
John Chambers