Adds packages to _webrarian.yml. Prebuilt packages are WebAssembly
binaries from repo.r-wasm.org (and packages.repos). bind() copies them
into the site (the default build.bundle-engine, and always for an offline
site) or has the page install them when it opens. GitHub and
local packages are compiled to WebAssembly by bind(), in Docker. Whether
dependencies are bundled too is the collection-wide packages.dependencies
setting (see settings_set()), which this function never changes.
A prebuilt name that no repository has (repo.r-wasm.org, then
packages.repos) is added with a warning. Without a network connection
the names are not looked up.
Usage
acquire_package(
packages,
path = ".",
source = c("prebuilt", "local", "github")
)Examples
# Prebuilt names are looked up in the package repositories, and nothing is
# said without a network connection. The index is cached under tempdir()
# here.
old <- Sys.getenv("R_USER_CACHE_DIR", unset = NA)
Sys.setenv(R_USER_CACHE_DIR = file.path(tempdir(), "webrarian-example-cache"))
collection <- file.path(tempdir(), "webrarian-acquire-packages")
catalog(collection)
#> ✔ Created directory /tmp/RtmpQU25pJ/webrarian-acquire-packages
#> ✔ Created _webrarian.yml
#> ✔ Added "_site/" and ".webrarian/" to .gitignore
#> ✔ Cataloged webrarian collection: "webrarian-acquire-packages"
#>
#> Next steps:
#> Move into the collection:
#> `setwd("/tmp/RtmpQU25pJ/webrarian-acquire-packages")`
#> Acquire packages: `webrarian::acquire_package("dplyr")`
#> Acquire files: `webrarian::acquire_file("data/")`
#> Bind: `webrarian::bind()`
#> Reading room: `webrarian::reading_room()`
#> ℹ Or pass `path` to each call, e.g. `webrarian::bind(path =
#> "/tmp/RtmpQU25pJ/webrarian-acquire-packages")`
# Add pre-built packages
acquire_package(c("dplyr", "ggplot2"), path = collection)
#> ✔ Added 2 packages from "prebuilt": dplyr and ggplot2
# Add a GitHub package (compiled to WebAssembly later, by bind())
acquire_package("tidyverse/ggplot2", source = "github", path = collection)
#> ✔ Added 1 package from "github": tidyverse/ggplot2
# Add a local package directory
pkg <- file.path(collection, "mypackage")
dir.create(pkg)
writeLines(c("Package: mypackage", "Version: 0.1.0"), file.path(pkg, "DESCRIPTION"))
acquire_package("mypackage", source = "local", path = collection)
#> ✔ Added 1 package from "local": mypackage
collection_packages(collection)
#>
#> ── Webrarian Packages ──────────────────────────────────────────────────────────
#>
#> ── prebuilt ──
#>
#> • dplyr
#> • ggplot2
#>
#> ── github ──
#>
#> • tidyverse/ggplot2
#>
#> ── local ──
#>
#> • mypackage
unlink(collection, recursive = TRUE)
if (is.na(old)) Sys.unsetenv("R_USER_CACHE_DIR") else Sys.setenv(R_USER_CACHE_DIR = old)