Title: | Hosting an Independent CRAN Repository |
---|---|
Description: | Stand-alone HTTP capable R-package repository, that fully supports R's install.packages() and available.packages(). It also contains API endpoints for end-users to add/update packages. This package can supplement 'miniCRAN', which has functions for maintaining a local (partial) copy of 'CRAN'. Current version is bare-minimum without any access-control or much security. |
Authors: | Stefan McKinnon Edwards [aut, cre, cph]
|
Maintainer: | Stefan McKinnon Edwards <[email protected]> |
License: | GPL-3 |
Version: | 0.9.0-1 |
Built: | 2025-02-26 03:29:45 UTC |
Source: | https://github.com/cran/microCRAN |
Stand-alone HTTP capable R-package repository, that fully supports R's install.packages() and available.packages(). It also contains API endpoints for end-users to add/update packages. This package can supplement 'miniCRAN', which has functions for maintaining a local (partial) copy of 'CRAN'. Current version is bare-minimum without any access-control or much security.
/root /---/src/contrib/ /---/src/contrib/PACKAGES(?.rds|.gz) /---/src/contrib/microCRAN_v1.0.0.tar.gz /---/src/contrib/4.0/PACKAGES /---/src/contrib/4.1/PACKAGES /---/src/contrib/4.2/PACKAGES /---/src/contrib/4.3/PACKAGES /---/bin/windows/contrib/4.0/PACKAGES /---/bin/windows/contrib/4.0/microCRAN_v1.0.0.zip /---/bin/windows/contrib/4.1/PACKAGES /---/bin/windows/contrib/4.2/PACKAGES /---/bin/windows/contrib/4.3/PACKAGES /---/bin/macosx/contrib/4.0/PACKAGES /---/bin/macosx/contrib/4.0/microCRAN_v1.0.0.tgz /---/bin/macosx/contrib/4.1/PACKAGES /---/bin/macosx/contrib/4.2/PACKAGES /---/bin/macosx/contrib/4.3/PACKAGES
Maintainer: Stefan McKinnon Edwards [email protected] (ORCID) [copyright holder]
Other contributors:
Kamstrup A/S [copyright holder]
Methods for taking a file (".tar.gz", ".zip", ".tgz") and placing it in the repository, all locally.
addPackage( fn, type = c("source", "mac.binary", "win.binary"), repo_dir, is.new = TRUE )
addPackage( fn, type = c("source", "mac.binary", "win.binary"), repo_dir, is.new = TRUE )
fn |
Path to package |
type |
Type of package, see explanation in section
"Binary packages" in |
repo_dir |
Path to local directory, where the root of the repository is.
The (source) packages will be stored locally at
|
is.new |
Logical, if |
Invisibly returns the number of packages described in the resulting
'PACKAGES'
, 'PACKAGES.gz'
and 'PACKAGES.rds'
files.
If 0
, no packages were found and no files were written.
miniCRAN::addLocalPackage()
, tools::write_PACKAGES()
f <- system.file('extdata/microCRAN_0.1.0.zip', package = 'microCRAN', mustWork = TRUE) root <- tempdir() addPackage(f, type = 'win.binary', repo_dir = root)
f <- system.file('extdata/microCRAN_0.1.0.zip', package = 'microCRAN', mustWork = TRUE) root <- tempdir() addPackage(f, type = 'win.binary', repo_dir = root)
build
creates the Plumber-router and
run
starts the service.
build( repo_dir, url_path, redirect_url, title, description, contact, license, tos ) run(pr, host = "127.0.0.1", port = 1881, url_path, ...)
build( repo_dir, url_path, redirect_url, title, description, contact, license, tos ) run(pr, host = "127.0.0.1", port = 1881, url_path, ...)
repo_dir |
Path to local directory, where the root of the repository is.
The (source) packages will be stored locally at
|
url_path |
Optional prefix to endpoint. The CRAN repository will be
available at e.g. |
redirect_url |
Url, if supplied, requests to static assets (package files, etc.) are redirected to another service instead of being handled by cran_static_path_handler. It can be beneficial to let e.g. an Apache httpd service handle those. |
title , description , contact , license , tos
|
Descriptions of the API. Some defaults are used, see section below or https://www.rplumber.io/articles/annotations.html. |
pr |
A Plumber-router, e.g. as returned from
|
host |
A string that is a valid IPv4 or IPv6 address that is owned by this server, which the application will listen on. "0.0.0.0" represents all IPv4 addresses and "::/0" represents all IPv6 addresses. |
port |
A number or integer that indicates the server port that should be listened on. Note that on most Unix-like systems including Linux and Mac OS X, port numbers smaller than 1025 require root privileges. |
... |
Additional arguments passed on to |
run |
Logical, should the method run the site immediately? |
Point repo_dir
to you local filesystem. If the (sub-)directory does not
exist, it will be created when an R-package is added through the corresponding
endpoint.
A new Plumber-router object.
The fields title
, description
, contact
, license
, and tos
are used for describing the API in the resulting Swagger-documents.
These follow the OpenAPI type descriptions, see
https://spec.openapis.org/oas/v3.0.3#info-object.
Field name | Type | Description |
title | string | The title of the API. |
description | string | A short description of the API. |
tos | string | A URL to the Terms of Service for the API. |
contact | list | A "Contact Object", i.e., list-object with fields "name", "url" and "email". |
license | list | A "License Object", i.e., list-object with fields "name" and "url". |
version | string | The version of the API. |
Creates handler for handling access to static files in the repository,
i.e., the src/contrib
, bin/windows/contrib
, and bin/macosx/contrib
subdirectories.
Use cran_static_redirect_handler to let another process (e.g. an Apache httpd or nginx server) handle the request, by redirecting it.
cran_static_path_handler(repo_dir, path_prefix = NULL) cran_static_redirect_handler(dest_url)
cran_static_path_handler(repo_dir, path_prefix = NULL) cran_static_redirect_handler(dest_url)
repo_dir |
Path to local directory, where the root of the repository is.
The (source) packages will be stored locally at
|
path_prefix |
Optional URL-component, if the repository exists at a
subdirectory of the host (see run's |
dest_url |
The url requests are forwarded to, after being appened with the request; it should contain all path-components up to the '/src' or '/bin' parts. |
A handler (function) for use in a Plumber router "filter" .
require(plumber) pr() |> pr_filter('static', cran_static_path_handler(repo_dir, path_prefix = 'cran')) pr() |> pr_filter('redirect', cran_static_redirect_handler("http://my.local.cran:80/cran"))
require(plumber) pr() |> pr_filter('static', cran_static_path_handler(repo_dir, path_prefix = 'cran')) pr() |> pr_filter('redirect', cran_static_redirect_handler("http://my.local.cran:80/cran"))
Creates a simple HTML page with table of all files and subdirectories. May throw a 403 or 404 code.
directory_listing(req, res, path, path_prefix) directory_listing_html(path, url_path, add_dir = TRUE)
directory_listing(req, res, path, path_prefix) directory_listing_html(path, url_path, add_dir = TRUE)
req , res
|
A "request"- and "response"-object, respectively |
path |
Path to directory to list |
path_prefix |
Optional URL-component, if the repository exists at a
subdirectory of the host (see run's |
url_path |
The entire, relative path, that is displayed to end user in the URL. |
add_dir |
Logical, if the requested URL does not end with a '/', set this to TRUE, else all links will point to the parent directory. |
directory_listing
returns the response-object.
directory_listing_html
returns a HTML-string with the entire page.
A Dockerfile
with an init
-script is installed with this package, which
can be used for running a Docker container with this package.
The path to the directory with the file can be found by running
system.file('docker/', package = 'microCRAN', mustWork = TRUE)
To run, place microCRAN's source-tarball in the build directory with the Dockerfile
.
Enable BuildKit and build the image:
DOCKER_BUILDKIT=1 docker build .
The build-process will automatically install any source-tarballed R-package
that is located in the build-context (i.e. directory with the Dockerfile
).
Start the container. Remember to map the port and the directory for the repository, else the repository is lost if the container is restarted. See the list below for variables to use.
docker run -d -v /data/my_local_cran:/var/cran -p 1881:1881 -e CRAN_DIR=/var/cran <microcran-image>
CRAN_HOST
Host for the service to listen to. See also plumber::pr_run.
CRAN_PORT
Port to listen on. Defaults to 1881.
CRAN_DIR
Path to root of local directory where the repository's files are stored.
CRAN_URL_PATH
Absolute path to the repository, as seen from the client.
CRAN_REDIRECT_URL
If static files should be served by something else.
Creates a Plumber route that handles an incoming
R-package.
Use rather build()
to build the entire API.
pr_add_package(pr, path = "/add", repo_dir)
pr_add_package(pr, path = "/add", repo_dir)
pr |
A Plumber router-object |
path |
The path to the endpoint |
repo_dir |
Path to local directory, where the root of the repository is.
The (source) packages will be stored locally at
|
NULL
invisibly; called to modify the response.
Read DESCRIPTION file from package
read_DESCRIPTION_zip(fn) read_DESCRIPTION_tar(fn)
read_DESCRIPTION_zip(fn) read_DESCRIPTION_tar(fn)
fn |
Path to either zip, tar.gz or tgz file. |
List-object with contents of DESCRIPTION file.
package <- system.file('extdata/microCRAN_0.1.0.zip', package='microCRAN', mustWork=TRUE) read_DESCRIPTION_zip(package)
package <- system.file('extdata/microCRAN_0.1.0.zip', package='microCRAN', mustWork=TRUE) read_DESCRIPTION_zip(package)