Package installation

#| label: asciicast-setup
#| include: false
#| cache: false
dir.create(.lib <- tempfile())
.libPaths(c(.lib, .libPaths()))

How do I reinstall a package?

pak does not reinstall a package, if the same version is already installed. Sometimes you still want a reinstall, e.g. to fix a broken installation. In this case you can delete the package and then install it, or use the ?reinstall parameter:

#| label: faq-reinstall
pak::pkg_install("tibble")
#| label: faq-reinstall-2
pak::pkg_install("tibble?reinstall")

How do I install a dependency from a binary package

Sometimes it is sufficient to install the binary package of an older version of a dependency, instead of the newer source package that potentially needs compilers, system tools or libraries.

pkg_install() and lockfile_create() default to upgrade = FALSE, which always chooses binaries over source packages, so if you use pkg_install() you don't need to do anything extra.

The local_install_* functions default to upgrade = TRUE, as does pak() with pkg = NULL, so for these you need to explicitly use upgrade = FALSE.

How do I install a package from source?

To force the installation of a source package (instead of a binary package), use the ?source parameter:

#| label: faq-source
pak::pkg_install("tibble?source")

How do I install the latest version of a dependency?

If you want to always install a dependency from source, because you want the latest version or some other reason, you can use the source parameter with the <package>= form: <package>=?source. For example to install tibble, with its cli dependency installed from source you could write:

#| label: faq-source-dep
pak::pkg_install(c("tibble", "cli=?source"))

How do I ignore an optional dependency?

#| label: faq-ignore
pak::pkg_install(
  c("tibble", "DiagrammeR=?ignore", "formattable=?ignore"),
  dependencies = TRUE
)

The syntax is

<packagename>=?ignore

Note that you can only ignore optional dependencies, i.e. packages in Suggests and Enhances.

Others

How can I use pak with renv?

Since version 1.0.0 renv has official support for using pak. This needs to be enabled with the renv.config.pak.enabled option or the RENV_CONFIG_PAK_ENABLED environment variable set to TRUE. For more information see the renv documentation.



Try the pak package in your browser

Any scripts or data that you put into this service are public.

pak documentation built on June 8, 2025, 11:42 a.m.