Disclaimer: this is experimental, use deliberately and with caution.
The goal of craneur is to provide an easy way to Create your own “R Archive Network”, to be deployed anywhere.
remotes::install_github("ColinFay/craneur")
{craneur}
?Creating your own R archive repository can be useful for:
A R archive repo is a location where you can download R packages with
the install.packages
function.
This location is composed of, roughly:
PACKAGES
filetar.gz
of your packagesThese 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")
{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))
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")
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:
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")
# 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")
)
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")
)
You can rewrite your index.html by reknitting the index.Rmd you’ll find in the directory.
See also:
{drat}
: https://github.com/eddelbuettel/drat{cranlike}
: https://github.com/r-hub/cranlike{packrat}
: https://github.com/rstudio/packratPlease note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.