https://github.com/atheriel/cranlift
Serve CRAN-like Repositories as RESTful APIs
https://github.com/atheriel/cranlift
cran httpuv r
Last synced: 4 months ago
JSON representation
Serve CRAN-like Repositories as RESTful APIs
- Host: GitHub
- URL: https://github.com/atheriel/cranlift
- Owner: atheriel
- License: other
- Created: 2019-12-16T05:56:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-27T07:04:08.000Z (almost 6 years ago)
- Last Synced: 2024-12-04T07:36:33.080Z (12 months ago)
- Topics: cran, httpuv, r
- Language: R
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - atheriel/cranlift - Serve CRAN-like Repositories as RESTful APIs (R)
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# cranlift: Serve CRAN-like Repositories as RESTful APIs
[](https://cran.r-project.org/package=cranlift)
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](https://CRAN.R-project.org). For now,
you can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("atheriel/cranlift")
```
## Usage
To serve an (empty) CRAN-like repository, call `cranlift::serve()`:
```{r example-serve, eval = FALSE}
dir.create(repo <- tempfile("repo"))
cranlift::serve(repo, port = 8000)
```
```{r bg-serve, echo = FALSE}
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):
```{r example-available}
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:
```{r example-add}
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:
```{r example-delete}
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:
```{r example-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.