knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

cranlift: Serve CRAN-like Repositories as RESTful APIs

CRAN status

Like the miniCRAN and drat packages, cranlift allows users to manage their own CRAN-like R package archives. However, cranlift does so by running a fully-featured API server that exposes packages as resources that can be added, deleted, and modified using HTTP requests, in line with RESTful design principles.

cranlift supports both source and binary packages, as well as CRAN's Archive layout for storing old versions of packages.

Installation

cranlift is not yet available on CRAN. For now, you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("atheriel/cranlift")

Usage

To serve an (empty) CRAN-like repository, call cranlift::serve():

dir.create(repo <- tempfile("repo"))
cranlift::serve(repo, port = 8000)
p <- callr::r_bg(function() {
  dir.create(repo <- tempfile("repo"))
  cranlift::serve(repo, port = 8000)
}, supervise = TRUE)
stopifnot(p$is_alive())

You can then verify that R sees it as a package repository (with zero packages at the moment):

nrow(available.packages(repos = "http://127.0.0.1:8000"))

Now let's add an example package to the repository, say miniCRAN. Because we're interacting with a server, we do this with an HTTP request:

path <- download.packages("miniCRAN", tempdir(), type = "source")[1,2]
httr::PUT(
  sprintf("127.0.0.1:8000/src/contrib/%s", basename(path)),
  body = list(file = httr::upload_file(path))
)

nrow(available.packages(
  repos = "http://127.0.0.1:8000", ignore_repo_cache = TRUE
))

Deleting a package (say, because a new version is available) works similarly:

httr::DELETE(
  sprintf("127.0.0.1:8000/src/contrib/%s", basename(path))
)

nrow(available.packages(
  repos = "http://127.0.0.1:8000", ignore_repo_cache = TRUE
))

By default, deleted packages will be moved to the archive:

httr::HEAD(sprintf(
  "127.0.0.1:8000/src/contrib/Archive/miniCRAN/%s", basename(path)
))

Usage with drat and miniCRAN

cranlift can serve repositories created with drat and miniCRAN (and has a strong emphasis on compatibility with the common repository layout they use), but be warned that it may modify the PACKAGES files these packages create.

License

cranlift is made available under the terms of the MIT license. See the LICENSE.md file for details.



atheriel/cranlift documentation built on Jan. 1, 2020, 10:11 p.m.