Robert's Data Science Blog

Smarter {cranitor}

My {cranitor} package has been updated to make it simpler to use. The idea is that the user should not worry about the internals of a CRAN or how to handle a package archive – this is {cranitor}’s job.

To achieve this {cranitor} should be able to extract information from a package archive to determine if it is a valid archive and where it should be located in the CRAN.

To achieve this I essentially perform the same digging that R CMD INSTALL does when installing a package from an archive. The source code for this can be found in https://github.com/wch/r-source/blob/trunk/src/library/tools/R/install.R.

A source archive of a package is just the source packed into a tar.gz archive. A binary archive of a package is a compressed version of the installed package.

One significant difference is the DESCRIPTION file of the package. Consider the DESCRIPTION file of my example package arithmetic1:

Package: arithmetic1
Title: Arithmetic1
Version: 0.0.1
Authors@R: 
    person("Robert", "Dahl Jacobsen", role = c("aut", "cre"), email = "")
Description: Basic arithmetic.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://github.com/robertdj/arithmetic1
RoxygenNote: 7.1.0
Roxygen: list(markdown = TRUE)
Suggests: 
    testthat

After installing the package (in my case to ~/R/x86_64-pc-linux-gnu-library/4.0.0/arithmetic1) the DESCRIPTION file in the installed folder look like this:

Package: arithmetic1
Title: Arithmetic1
Version: 0.0.1
Authors@R:
    person("Robert", "Dahl Jacobsen", role = c("aut", "cre"), email = "")
Description: Basic arithmetic.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://github.com/robertdj/arithmetic1
RoxygenNote: 7.1.0
Roxygen: list(markdown = TRUE)
Suggests: testthat
NeedsCompilation: no
Packaged: 2020-08-06 19:01:07 UTC; robert
Author: Robert Dahl Jacobsen [aut, cre]
Maintainer: Robert Dahl Jacobsen <>
Built: R 4.0.0; ; 2020-08-06 19:01:07 UTC; unix

Some lines about the installation has been appended – in particular the platform and version of R used to compile the package.

The DESCRIPTION file is in Debian Control Format and we can read it with the function read.dcf.

The folder structure of the installed package is as follows:

├── DESCRIPTION
├── help
│   ├── aliases.rds
│   ├── AnIndex
│   ├── arithmetic1.rdb
│   ├── arithmetic1.rdx
│   └── paths.rds
├── html
│   ├── 00Index.html
│   └── R.css
├── INDEX
├── LICENSE
├── Meta
│   ├── features.rds
│   ├── hsearch.rds
│   ├── links.rds
│   ├── nsInfo.rds
│   ├── package.rds
│   └── Rd.rds
├── NAMESPACE
├── R
│   ├── arithmetic1
│   ├── arithmetic1.rdb
│   └── arithmetic1.rdx
└── tests
    ├── testthat
    │   └── test-arithmetic.R
    └── testthat.R

The file Meta/package.rds is a parsed version of DESCRIPTION, so by extracting and reading Meta/package.rds from the archive we have enough information to put the archive in the correct folder in a CRAN.