Dependencies are invitations for other people to break your package.
-- Josh Ulrich, private communication
Welcome to the seventeenth post in the relentlessly random R ravings series of posts, or R4 for short.
Dependencies. A truly loaded topic.
As R users, we are spoiled. Early in the history of R, Kurt Hornik and Friedrich Leisch built support for packages right into R, and started the Comprehensive R Archive Network (CRAN). And R and CRAN had a fantastic run with. Roughly twenty years later, we are looking at over 12,000 packages which can (generally) be installed with absolute ease and no suprises. No other (relevant) open source language has anything of comparable rigour and quality. This is a big deal.
And coding practices evolved and changed to play to this advantage. Packages are a near-unanimous recommendation, use of the install.packages() and update.packages() tooling is nearly universal, and most R users learned to their advantage to group code into interdependent packages. Obvious advantages are versioning and snap-shotting, attached documentation in the form of help pages and vignettes, unit testing, and of course continuous integration as a side effect of the package build system.
But the notion of 'oh, let me just build another package and add it to the pool of packages' can get carried away. A recent example I had was the work on the prrd package for parallel recursive dependency testing --- coincidentally, created entirely to allow for easier voluntary tests I do on reverse dependencies for the packages I maintain. It uses a job queue for which I relied on the liteq package by Gabor which does the job: enqueue jobs, and reliably dequeue them (also in a parallel fashion) and more. It looks light enough:
R__ tools::package_dependencies(package=&quot;liteq&quot;, recursive=FALSE, db=AP)$liteq
[1] &quot;assertthat&quot; &quot;DBI&quot; &quot;rappdirs&quot; &quot;RSQLite&quot; R__ Two dependencies because it uses an internal SQLite database, one for internal tooling and one for configuration.
All good then? Not so fast. The devil here is the very innocuous and versatile RSQLite package because when we look at fully recursive dependencies all hell breaks loose:
R__ tools::package_dependencies(package=&quot;liteq&quot;, recursive=TRUE, db=AP)$liteq
[1] &quot;assertthat&quot; &quot;DBI&quot; &quot;rappdirs&quot; &quot;RSQLite&quot; &quot;tools&quot; [6] &quot;methods&quot; &quot;bit64&quot; &quot;blob&quot; &quot;memoise&quot; &quot;pkgconfig&quot; [11] &quot;Rcpp&quot; &quot;BH&quot; &quot;plogr&quot; &quot;bit&quot; &quot;utils&quot; [16] &quot;stats&quot; &quot;tibble&quot; &quot;digest&quot; &quot;cli&quot; &quot;crayon&quot; [21] &quot;pillar&quot; &quot;rlang&quot; &quot;grDevices&quot; &quot;utf8&quot; R__
R__ tools::package_dependencies(package=&quot;RSQLite&quot;, recursive=TRUE, db=AP)$RSQLite
[1] &quot;bit64&quot; &quot;blob&quot; &quot;DBI&quot; &quot;memoise&quot; &quot;methods&quot; [6] &quot;pkgconfig&quot; &quot;Rcpp&quot; &quot;BH&quot; &quot;plogr&quot; &quot;bit&quot; [11] &quot;utils&quot; &quot;stats&quot; &quot;tibble&quot; &quot;digest&quot; &quot;cli&quot; [16] &quot;crayon&quot; &quot;pillar&quot; &quot;rlang&quot; &quot;assertthat&quot; &quot;grDevices&quot; [21] &quot;utf8&quot; &quot;tools&quot; R__ Now we went from four to twenty-four, due to the twenty-two dependencies pulled in by RSQLite.
There, my dear friend, lies madness. The moment one of these packages breaks we get potential side effects. And this is no laughing matter. Here is a tweet from Kieran posted days before a book deadline of his when he was forced to roll a CRAN package back because it broke his entire setup. (The original tweet has by now been deleted; why people do that to their entire tweet histories is somewhat I fail to comprehened too; in any case the screenshot is from a private discussion I had with a few like-minded folks over slack.)
That illustrates the quote by Josh at the top. As I too have &quot;production code&quot; (well, CRANberries for one relies on it), I was interested to see if we could easily amend RSQLite. And yes, we can. A quick fork and few commits later, we have something we could call 'RSQLighter' as it reduces the dependencies quite a bit:
R__ IP tools::package_dependencies(package=c(&quot;DBI&quot;, &quot;RMySQL&quot;, &quot;RMariaDB&quot;), recursive=TRUE, db=AP)
$DBI
[1] &quot;methods&quot;
$RMySQL
[1] &quot;DBI&quot; &quot;methods&quot;
$RMariaDB
[1] &quot;bit64&quot; &quot;DBI&quot; &quot;hms&quot; &quot;methods&quot; &quot;Rcpp&quot; &quot;BH&quot; [7] &quot;plogr&quot; &quot;bit&quot; &quot;utils&quot; &quot;stats&quot; &quot;pkgconfig&quot; &quot;rlang&quot; R__ And to be clear, I do not believe in giving up and using everything via docker, or virtualenvs, or packrat, or ... A well-honed dependency system is wonderful and the right resource to get code deployed and updated. But it required buy-in from everyone involved, and an understanding of the possible trade-offs. I think we can, and will, do better going forward.
Or else, there will always be the tinyverse ...
This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.