Giter Club home page Giter Club logo

cranlift's Introduction

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)

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"))
#> [1] 0

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))
)
#> Response [http://127.0.0.1:8000/src/contrib/miniCRAN_0.2.12.tar.gz]
#>   Date: 2019-12-20 18:27
#>   Status: 201
#>   Content-Type: text/plain; charset=utf-8
#> <EMPTY BODY>

nrow(available.packages(
  repos = "http://127.0.0.1:8000", ignore_repo_cache = TRUE
))
#> [1] 1

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))
)
#> Response [http://127.0.0.1:8000/src/contrib/miniCRAN_0.2.12.tar.gz]
#>   Date: 2019-12-20 18:27
#>   Status: 200
#>   Content-Type: text/plain; charset=utf-8
#> <EMPTY BODY>

nrow(available.packages(
  repos = "http://127.0.0.1:8000", ignore_repo_cache = TRUE
))
#> [1] 0

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)
))
#> Response [http://127.0.0.1:8000/src/contrib/Archive/miniCRAN/miniCRAN_0.2.12.tar.gz]
#>   Date: 2019-12-20 18:27
#>   Status: 200
#>   Content-Type: x-gzip
#> <EMPTY BODY>

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.

cranlift's People

Contributors

atheriel avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cranlift's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.