Package Dependencies When Installing from Source in R

Package dependencies when installing from source in R

You could make your own repository and set repos to be a vector of the places to look for packages, where it would start with your own repository and then include a link to a CRAN mirror. This is what I do and it works quite nicely, as then I can easily share my packages with others and update them from whatever computer I happen to be on.

Adding dependencies properly to an r package, so that they install automatically

A good strategy when it comes to developing your first packages is, in my experience, checking the work of others. The easiest way to do that is to check some of your favorite packages on Github. Here is, for example, a part of one of my DESCRIPTION files:

Depends: 
R (>= 3.3.0)
License: GPL-3
Imports:
stringi (>= 1.1.7),
data.table (>= 1.10.4.3),
methods (>= 3.3.0),
quanteda (>= 1.1.0),
scales (>= 0.5.0),
stats (>= 3.3.0),
utils (>= 3.3.0)

As you can see, every package has a minimal version (most of them are simply the versions I use but for some, I tested if older versions work). And I use Imports to mark packages and Depends only to indicate the oldest R version which I successfully tested. You should almost always use Imports or Suggests instead of Depends for packages.

Once you have set this up, you can run:

# This should point to the folder of your DESCRIPTION file    
setwd("/path/to/your/package/")
roxygen2::roxygenise(clean = TRUE)

Do not alter the NAMESPACE directly! This should be enough to install your package or put it on GitHub.

However, this is just the tip of the iceberg and it would probably be a good idea to check this post out and then read up on the details in this book.

Update: Given the comment from @Benjamin, I see that I have missed one part of your question. repos = NULL, type = "source" suppresses the installation of dependencies. A better way would be to use devtools. I'm not sure if this is the correct way, but when I already have a tarball and need to install it I use something like:

# In Windows use copy and paste directly on the file to get a link  
devtools::install_url("C:/custom_packages/my_package_0.0.0.9000.tar.gz")

Install dependencies of custom package

Figured it out.

The problem was a misunderstanding on my part regarding roxygen, which I've been using for my documentation. I assumed it handled the Imports: section of the DESCRIPTION file, which it doesn't ((1), (2)). So while the NAMESPACE file has all the necessary importFrom(pool, ...) calls, pool wasn't actually on my DESCRIPTION.

After fixing that oversight, using remote::install_local("path/to/pkg") (or devtools::install()) ((3)) worked: it installed my package and pulled its dependencies from CRAN.



Related Topics



Leave a reply



Submit