Jon Olav Skoien
2009-Jun-09 16:58 UTC
[R] Dependency between packages for Windows-binaries
Hi, I have already asked a similar question without response (https://stat.ethz.ch/pipermail/r-help/2009-June/200300.html) so I am here reformulating in the hope that someone is able to help. If something is unclear, please ask. I am working on the development of two packages, pkg1 and pkg2 (based on work in two different projects). pkg1 is quite generic, pkg2 tries to solve a particular problem within same field (geostatistics). Therefore, there might be users who want to use pkg2 as an add-on package to increase the functionality of pkg1. In other words, functions in pkg1 are based on the S3 class system, and I want pkg2 to offer methods for pkg2-objects to functions defined in pkg1, for users having both packages installed. Merging the packages or making pkg2 directly dependent pkg1 would be the easiest solution, but it is a bad solution as most users will only be interested in one of the packages. I thought this could be solved by including the following in NAMESPACE of pkg2: if ("pkg1" %in% rownames(utils:::installed.packages()) { importFrom(pkg1, fun1, fun2, fun3) S3method(fun1, class2) S3method(fun2, class2) S3method(fun3, class2) } Unfortunately, this doesn't seem to work as I expected, particularly when I try to build a binary for Windows-users (R CMD build -binary pkg2). It seems for me that the dependency between pkg2 and pkg1 is defined at the time of building a binary, not when the package is loaded with library(pkg2): If I have pkg1 installed when I build pkg2, the package will not load for users who do not have pkg1 installed: > install.packages("d:/pkg2_0.1-1.zip", repos=NULL) > library(pkg2) (...) Error : object 'fun1' not found whilst loading namespace 'pkg2' Error: package/namespace load failed for 'pkg2' If I remove pkg1 from the library before building pkg2, pkg2 can be installed and loaded by everyone, but the new method is not visible for those with pkg1 installed: > install.packages("d:/pkg2_0.1-2.zip", repos=NULL) > library(pkg1) > library(pkg2) > methods(fun1) [1] fun1.class1* Non-visible functions are asterisked I have tried with and without one of the following: Suggests: pkg1 Enhances: pkg1 in the DESCRIPTION file of pkg2, but I cannot see that either of them make a difference. I can of course solve this problem temporarily, building two different versions of pkg2, with and without having pkg1 installed on my computer. But first of all, that seems unnecessary complicated, and more important, the plan is also to upload these packages to CRAN where I doubt that such a two-version solution is possible or accepted. Is there a way to build one binary that works both with and without having pkg1 installed? I have tried to search in mail archives and "Writing R extensions", but either it is not there, or I have missed it. Thanks, Jon BTW, I am using R version 2.9.0 and Rtools version 29 under Windows XP-SP3