Local Package Repository Management
require("devtools")
devtools::install_github("Rappster/conditionr")
devtools::install_github("Rappster/reposr")
require("reposr")
We will use the following directory as our local CRAN-like package repoitory:
root <- file.path(tempdir(), "cran")
repo <- PackageRepository$new(root)
Note that, even though the package has not been specifically designed to express non-local repositories, remote repositories can also be handled. However, keep in mind that not all methods will work for remote repositories (e.g. $show()
)
repo_http <- PackageRepository$new("http://cran.rstudio.com")
repo_http
repo_http$scheme
repo_ftp <- PackageRepository$new("ftp://cran.at.r-project.org/")
repo_ftp
repo_ftp$scheme
repo$ensure()
Note that you could also ensure the repository without its index files by setting index = FALSE
.
The package offers a built-in way to create atomic, i.e. package-version based package repositories. This is important/can be helpful in two scenarios:
When developing, you typically follow the following cycle:
$buildInto()
While your repository will at some point thus contain multiple actual builds, be aware that only the latest build will be reflected in the repository index files. Thus, when you decide to "clean up" at some point, running $clean(archive = TRUE)
) will make sure that all the outdated builds are not lost but moved to the respective atomic package repository.
Method $atomize()
atomarizes the content of a repository in the sense that a own repository for each package's version is ensured below a root directory.
The actual directory structure of the collection of atomic repositories is as follows:
root
/pkg_a
/1.0
/1.1
/...
/x.y.z
/...
/x.y
/pkg_b
/1.0
/1.1
/...
/x.y.z
/...
/x.y
/...
Ideally, the actual files contained in atomic repostories would simply be soft symbolic links in order to avoid saving packages redundantly. However, so far I could not manage to realize this (see SO post)
repo$ensure(atomic = TRUE)
repo$exists()
repo$exists(atomic = TRUE)
Register:
getOption("repos")
repo$register()
getOption("repos")
See what's currently registered:
repo$showRegistered()
repo$showRegistered(custom_only = TRUE)
Unegister:
getOption("repos")
repo$register()
getOption("repos")
repo$unregister()
getOption("repos")
You can also reset the repos in the R options to its initial state:
tmp_1 <- PackageRepository$new("a/b/c")
tmp_2 <- PackageRepository$new("1/2/3")
tmp_1$register()
tmp_2$register()
getOption("repos")
tmp_1$unregister(reset = TRUE)
getOption("repos")
repo$browse()
You can also directly move into the subdirectories:
repo$browse("source")
repo$browse("mac.binary")
repo$browse("win.binary")
Build package directly into the repository
repo$buildInto()
Show content based on index file:
repo$show()
repo$show(type = "source")
repo$show(type = "mac.binary")
repo$show(type = "win.binary")
Check if specific package(s) exist(s):
repo$has()
repo$has(type = "source", atomic = FALSE)
repo$has(c("devtools", "dplyr"))
Remove outdated packages and refresh. If archive = TRUE
, outdated packages are moved to a special repository archive repo$root_atomic
.
Each outdated package build will be integrated into its own "package-version-specific" repository: file.path(repo$root_atomic, "<pkg_name>", "<pgk_version>")
repo$clean(archive = TRUE)
Remove current package from all subdirectories:
repo$remove()
Remove specific package:
repo$remove("<pkg_name>")
Reset entire repository:
repo$reset()
Pull all packages that your own package depens on from registered repositories:
repo$pull()
It is also possible to pull an arbitrary package from a repository (which can either be one of the registerd ones or a vector of explicit repositories specified via the repos
argument):
repo$pull(c("pkgKitten", "stringr")
Ensure that repository is atomized after pull (atomic package-version-specific repositories below repository archive (repo$browse(atomic = TRUE)
)):
repo$pull(atomize = TRUE)
Atomize repository content so each package version gets its version-specific repository in the repository archive:
repo$atomize()
Browse repository archive:
repo$browse(atomic = TRUE)
Push entire repository:
to <- file.path(tempdir(), "cran_2")
repo$push(to = to)
repo_2 <- PackageRepository$new(to)
repo_2$browse()
Push package(s):
to <- file.path(tempdir(), "cran_3")
repo$push(pkg = "reposr", to = to)
repo_2 <- PackageRepository$new(to)
repo_2$browse()
repo_2$delete(ask = FALSE)
repo$exists()
repo$delete()
repo$exists()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.