Create your own R Archive Network
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
data-raw
inst
man
.Rbuildignore
.gitignore
CODE_OF_CONDUCT.md
DESCRIPTION
LICENSE
LICENSE.md
NAMESPACE
NEWS.md
README.Rmd
README.md
craneur.Rproj

README.md

lifecycle

Disclaimer: this is experimental, use deliberately and with caution.

craneur

The goal of craneur is to provide an easy way to Create your own “R Archive Network”, to be deployed anywhere.

Install {craneur}

remotes::install_github("ColinFay/craneur")

Why would you use {craneur}?

Creating your own R archive repository can be useful for:

  • Not depending on GitHub for your dev packages
  • Deploying apps with custom packages on RConnect
  • Internal uses in your company, lab, university…
  • Because you’re a nerd and find it cool

How does it work?

A R archive repo is a location where you can download R packages with the install.packages function.

This location is composed of, roughly:

  • a PACKAGES file
  • the tar.gz of your packages

These elements should be put inside a src/contrib folder.

Once you’ve installed that, you can do :

install.packages("pkg", repos = "../craneur", type = "source")

For example :

install.packages("attempt", repos = "https://colinfay.me", type = "source")

Here comes {craneur}

craneur provides a user-friendly API for creating this skeleton : PACKAGES file, tar.gz, and a minimal index.html.

library(craneur)
colin <- Craneur$new("Colin")
colin$add_package("../attempt_0.3.0.9000.tar.gz")
colin$add_package("../shinipsum_0.0.0.9000.tar.gz")
colin

Create it:

colin$write(path = "inst")

This creates a “src/contrib” folder, and copies all the tar.gz into this folder.

For a bulk import, you can :

colin <- Craneur$new("Colin")
lapply(list.files("../", pattern = "tar.gz", full.names = TRUE), function(x) colin$add_package(x))

Put on your sever

You can now put the full “src/contrib” folder onto your server.

For example, if I put “src/contrib” at the root of “https://colinfay.me”, here the index: https://colinfay.me/src/contrib/

You can now install with :

install.packages("attempt", repos = "https://colinfay.me", type = "source")
install.packages("shinipsum", repos = "https://colinfay.me", type = "source")

As a plumber API

The function to_plumber() takes a src directory, and creates a plumber file. Once launched, this plumber API can be used as a RAN.

# Suppose you have your src built in inst/src
to_plumber(from = "inst/src/", to = "inst/plumb")
oldwd <- setwd("inst/plumb")
library(plumber)
p <- plumber$new("plumber.R")
p$run()
setwd(oldwd)

If you open a new session, you can go do:

install.packages("shinipsum", repo = "http://127.0.0.1:6091", type = "source")

Why would you want to do that?

You can deploy this “plumber-ran” on RStudio Connect, or on any other server (in a Docker, for example).

This, for example, allows to use a local package for deploying a shiny app in RConnect, in two steps:

  • Launch the API:
library(craneur)
colin <- Craneur$new("Colin")
colin$add_package("../attempt_0.3.0.9000.tar.gz")
colin$add_package("../shinipsum_0.0.0.9000.tar.gz")
colin$write()
to_plumber(from = "inst/src/", to = "inst/plumb")
rsconnect::deployAPI("inst/plumb")
  • Use the API:
# Then, in your app 
adress_of_api <- "XXX"
withr::with_options(
  list(
    pkgType = "source", 
    repos = c( adress_of_api, oldRepos)
  ), 
  rsconnect::deployApp(appDir = "inst/app")
)

Deploy an app contained in a package

Your package contains an ui.R & server.R in inst/app, and everything else is in a classical package format.

Run this script from your package root :

where <- devtools::build()
devtools::install()

withr::with_dir("inst/app",{
  library(craneur)
  repo <- Craneur$new("myapp")
  repo$add_package(where)
  repo$write()
  plumb <- to_plumber(from = "src/", to = "plumb")
  rsconnect::deployAPI( "plumb", launch.browser = FALSE, appName = "apipouetpouet")
})

# Be sure to catch the output of `rsconnect::deployAPI`
adress_of_api <- "XXX"
oldRepos <- getOption("repos")

withr::with_options(
  list(
    pkgType = "source",
    repos = c( adress_of_api, oldRepos)
  ),
  rsconnect::deployApp(appDir = "inst/app", appName = "pouetpouet")
)

Personnalise home page

You can rewrite your index.html by reknitting the index.Rmd you’ll find in the directory.

Prior work

See also:

CoC

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.