Jon Olav Skoien
2012-Feb-13 16:45 UTC
[R] Suggests/Enhances or .onLoad for S3-methods for optional package
Hi, I am developing a package B that, among other things, also offers some extra S3-methods for functions in package A if the user has installed A. I do not want to list A under Depends of B, as the dependency list of A is rather long, and most potential users of B will not be interested in package A. Unfortunately I struggle with doing this right. So far I have listed A under Suggests, and had a .onLoad function in B with if (require(A)) registerS3methods(newMethodsMatrix, package = A, env = environment(B)) But starting with R 2.13 or R 2.14, R CMD check complain about this require call in .onLoad, referring to the "good practice"-section of .onAttach. I guess this could also be a problem when uploading the package to CRAN, so I am trying to find another solution. So far I have tried: List A under Suggest of B, with a conditional import in NAMESPACE. If I build a Windows-binary from this when A is installed, this package can be installed but not loaded on computers where A is not installed. List A under Enhances of B. This seems to be the right thing, as the R extensions manual says: "the ?Enhances? field lists packages ?enhanced? by the package at hand, e.g., by providing methods for classes from these packages". However, although it seems I can install and load package B when I conditionally import package A in the NAMESPACE, R CMD check stops with the error: Namespace dependency not required: A If I remove the import, R CMD check is happier, but I cannot load the package after installing. I have read about the use of "Suggest", "Enhances" etc in "Writing R Extensions", but could not figure out the right way to do this. I am sure there is something I am missing here. Thanks, Jon -- Jon Olav Sk?ien Joint Research Centre - European Commission Institute for Environment and Sustainability (IES) Land Resource Management Unit Via Fermi 2749, TP 440, I-21027 Ispra (VA), ITALY jon.skoien at jrc.ec.europa.eu Tel: +39 0332 789206 Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.