library("reposr")
We will use the following directory as our local CRAN-like package repoitory:
root <- file.path(tempdir(), "cran")
repo <- PackageRepository$new(root)
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
$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")
$ensure()
)Create/ensure a local package repoitory that complies with the structural conventions of CRAN:
repo$ensure() repo$ensure(plain = TRUE) ## --> unnamed
$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)
$exists()
)repo$exists() repo$exists(plain = TRUE) repo$ensure() repo$exists() repo$delete(ask = FALSE) repo$exists()
$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()
$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"))
$hasAny()
)Check if a repoitory contains any packages at all
repo$hasAny() repo$hasAny(atomic = TRUE)
$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 a repoitory. This implies updating the index files according to the latest available package builds.
repo$ensure() repo$refresh()
$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()
)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()
)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")
You can delete repoitory archives by using the archive
parameter:
repo$delete(archive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.