library("reposr")

Specifiy root directory

We will use the following directory as our local CRAN-like package repoitory:

root <- file.path(tempdir(), "cran")

Create instance

repo <- PackageRepository$new(root)

Object structure

As the most important feature that characterizes a (local) package repoitory is (arguably) its location, the print method for class PackageRepository only shows the value of field root instead of what is returned by the default method for R6 objects (print.R6). This value corresponds to the package repoitory's root directory:

repo

In order to get an idea about the actual object structure, you can call the print method explicitly and use full = TRUE:

print(repo, full = TRUE)

The most important subdirectories that are actively linked to $root (and the currently used minor version of R) are:

repo$win.binary
repo$mac.binary
repo$source

Typical workflow

As URL ($asUrl)

Often times, you need your local repoitory to be in an URL format with URL scheme file (also see ?url)

repo$asUrl()

Other URL scheme are also implement, but not really useful as this package focuses on repoitories on a local file system (as opposed to a true web-based ressource for which schemes http and ftp are normally used).

repo$asUrl("http")
repo$asUrl("ftp")

Create/ensure ($ensure())

Create/ensure a local package repoitory that complies with the structural conventions of CRAN:

repo$ensure()
repo$ensure(plain = TRUE)
## --> unnamed

Delete ($delete())

Delete root directory including all subdirectories.

As for all methods involving critical operations (in the sense that you wouldn't want to perform them accidentally), this method takes an ask argument that prompts the user for confirmation:

repo$delete()

Whenever user is prompted for input, the valid inputs are given at the end of the line (yes [or y], no [or n] and quit [or q] in this and most cases)

You can suppress this by setting ask = FALSE

repo$delete(ask = FALSE)
repo$delete(ask = FALSE, plain = TRUE)
## --> unnamed

What happens when you try to delete a repoitory that does not exist depends on the settings for strict. It defaults to 0 in which case no additional message (or condition is issued):

repo$delete()

Here is what happens when strict is > 0:

repo$delete(strict = 1)
repo$delete(strict = 2)
repo$delete(strict = 3)

Check existence ($exists())

repo$exists()
repo$exists(plain = TRUE)
repo$ensure()
repo$exists()
repo$delete(ask = FALSE)
repo$exists()

Build into ($buildInto())

You can seamlessly build your package directly into a local package repoitory using functions of package devtools.

First, we ensure the repoitory's existence:

repo$ensure()

Next, we use the browse method to display the current repoitory content via the OS's default files system browser:

repo$browse(getOption("pkgType"))

Before we build our package, let's see the current content of the repoitory's index file:

repo$show()

As we see, the index is still empty at this point.

Now we build our package into the local repoitory. Note that this step assumes that your working directory points to a valid R package project. By default, the source version of the package is always along with the binary version corresponding to getOption("pkgType") (if your OS is either Windows or Mac OS)

repo$buildInto()

Note that the repoitory directory's content has changed: the repoitory now contains the package build(s) and the respective index file(s) (PACKAGES) has/have changed.

The index has changed as well:

repo$show()

Check existence of specific package(s) ($has())

This step assumes that you built a package into the repoitory via $buildInto().

When your working directory points to a valid package project, then the method automatically identifies the package name based on the project's DESCRIPTION file when being called without an explicit value for pkg):

repo$has()

When the name can't be retrieved, an error is thrown:

wd <- setwd("man") 
## --> unexpected working directory
repo$has()

## Clean up //
setwd(wd)

Specify explicit values for pkg:

my_pkg <- "reposr" 
## Please change to your package's name

repo$has(my_pkg)

## To include the information about the package type,
## use `atomic = FALSE`:
repo$has(my_pkg, atomic = FALSE)

repo$has(my_pkg, type = "source", atomic = FALSE)
repo$has(my_pkg, type = "mac.binary", atomic = FALSE)

repo$has("devtools")
repo$has(c(my_pkg, "devtools"))

Second-order methods for users

Are there any packages at all ($hasAny())

Check if a repoitory contains any packages at all

repo$hasAny()
repo$hasAny(atomic = TRUE)

Show content ($show())

Show the content based on a repoitory's index file.

This step assumes that you built a package into the repoitory via $buildInto().

repo$ensure()
repo$show()
repo$show(type = "win.binary")
repo$show(type = "mac.binary")
repo$show(type = "source")

Refresh ($refresh())

Refresh a repoitory. This implies updating the index files according to the latest available package builds.

repo$ensure()
repo$refresh()

Remove packages ($remove)

This step assumes that you built a package into the repoitory via $buildInto().

Remove package associated to the current package project (across all package type subdirectories):

repo$browse(getOption("pkgType"))
## --> note the different status before and after removal

repo$remove()

With explicit value for pkg (multiple values are also possible):

my_pkg <- "reposr"
## Please change to your package's name

repo$remove(my_pkg)
repo$remove(my_pkg, ask = FALSE)
## --> already removed

Remove packages selectively (types/subdirectories). This requires a re-build of your package.

my_pkg <- "reposr"
## Please change to your package's name

repo$buildInto()
repo$browse(path = "source")

repo$remove(my_pkg, type = "source", ask = FALSE)
## --> only the source build is removed

repo$browse(path = getOption("pkgType"))
repo$remove(my_pkg, type = getOption("pkgType"), ask = FALSE)
## --> only the default package type is removed

Reset ($reset())

Resets a repoitory to the initial state (corresponds to the result of initially calling $ensure() or $ensure(overwrite = TRUE)).

repo$buildInto()
repo$browse(path = "source")
repo$reset()

Clean ($clean())

Cleans a repoitory in the sense that old package versions are either deleted or archived. By default, a repoitory is refreshed before the actual cleaning takes place (can be controlled via refresh = TRUE/FALSE).

repo$clean()

Old versions are archived to directory <repo-name>__atomic below the parent directory a repoitory's root directory

In our case, this would be the following directory

paste0(repo$root, "__atomic")

Note

You can delete repoitory archives by using the archive parameter:

repo$delete(archive = TRUE)


rappster/reposr documentation built on May 26, 2019, 11:57 p.m.