Can two R packages be on each others depends list?
Asked Answered
C

2

6

Let's say I have 3 packages A, B, and C.

B connects to data repository 1 and has functions specific to that API.

C connects to data repository 2 and has functions specific to that API.

Eventually there will be several more child packages.

Package A will have generic methods and other common functions (e.g. authentication) that apply to data acquired through B and C. The rationale here is that this would be a more streamlined way to keep up with development (e.g. one would have to update a single auth function rather than doing that inside each child package). So it makes sense for A to be on the depends list for B and C

But I would also like users to just install A and have access to all child packages. For this, I want B and C to be on its depends list.

Is this possible? Should I have a better workflow?

Crandale answered 5/2, 2012 at 22:52 Comment(3)
Yes. That's what "depends" field is there for in the DESCRIPTION file. cran.r-project.org/doc/manuals/R-exts.html#The-DESCRIPTION-fileBiological
The proper way is to use Suggests: B C in A and Depends: A in both A and B since A doesn't require the others but they do require A.Uninspired
@SimonUrbanek Thank you. That is helpful. To clarify, since A handles all common functions, it would great if users just had A and used get_data(data_source="B") or get_data(data_source=all). We could do away with child packages but right now it is necessary for async development.Crandale
H
2

The gregmisc package is one example like this that installs more focused sub-packages through depends. It doesn't have any functionality, itself, but it certainly could.

http://cran.r-project.org/web/packages/gregmisc

Hawsepipe answered 5/2, 2012 at 23:5 Comment(3)
Thanks, the perfect example I was looking for (I use those packages all the time but didn't notice the set up).Crandale
AFAIK the gregmisc example is not relevant to the question above, because the subpackages don't depend on gregmisc.Uninspired
Good point. But I do appreciate it because it does give me a precedent for how this workflow might progress. That is, Package A can be equivalent to the original gregmisc, then split up in the future if necessary.Crandale
T
1

Updated in 2021: this is not possible anymore. R RMD Check will complain and return an error - packages cannot depend on each other.

The gregmisc package mentioned in a previous answer was removed from CRAN (probably because of this reason).

Tucket answered 26/12, 2021 at 13:44 Comment(2)
Thanks for that, i thought i was going crazy! Do you by any chance have a link to where this change was announced/described?Incommensurate
No, I'm not sure when this was introduced. Looked up the NEWS file, couldn't find it there neither...Tucket

© 2022 - 2024 — McMap. All rights reserved.