Deal with Dependencies

Tools to help manage dependencies during package development. This can retrieve all dependencies that are used in R files in the "R" directory, in Rmd files in "vignettes" directory and in 'roxygen2' documentation of functions. There is a function to update the Description file of your package and a function to create a file with the R commands to install all dependencies of your package. All functions to retrieve dependencies of R scripts and Rmd files can be used independently of a package development.

Travis buildstatus BuildstatusCoveragestatus

The goal of attachment is to help to deal with package dependencies during package development. It also gives useful tools to install or list missing packages used inside Rscripts or Rmds.

When building a package, we have to add @importFrom in our documentation or pkg::fun in the R code. The most important is not to forget to add the list of dependencies in the “Imports” or “Suggests” package lists in the DESCRIPTION file.

Why do you have to repeat twice the same thing ?
And what happens when you remove a dependency for one of your functions ? Do you really want to run a “Find in files” to verify that you do not need this package anymore ?

Let {attachment} help you ! This reads your NAMESPACE, your functions in R directory and your vignettes, then update the DESCRIPTION file accordingly. Are you ready to be lazy ?


# install.packages("devtools")

Use package {attachment}


What you really want is to fill and update your description file along with the modifications of your documentation. Indeed, only the following function will really be called. Use and abuse during the development of your package !


As {pkgdown} and {covr} are not listed in any script in your package, a common call for your development packages would be:

attachment::att_to_description(extra.suggests = c("pkgdown", "covr"))
#> Updating attachment documentation
#> Writing NAMESPACE
#> Loading attachment
#> Writing NAMESPACE
#> Writing att_to_description.Rd

To quickly install missing packages from a DESCRIPTION file, use:


To quickly install missing packages needed to compile Rmd files or run Rscripts, use:

attachment::att_from_rmds(path = ".") %>% attachment::install_if_missing()
attachment::att_from_rscripts(path = ".") %>% attachment::install_if_missing()

Function attachment::create_dependencies_file() will create a dependencies.R file in inst/ directory. This R script contains the procedure to quickly install missing dependencies:

# No Remotes ----
# remotes::install_github("ThinkR-open/fcuk")
# Attachments ----
to_install <- c("covr", "desc", "devtools", "glue", "knitr", "magrittr", "rmarkdown", "stats", "stringr", "testthat", "utils")
for (i in to_install) {
  message(paste("looking for ", i))
  if (!requireNamespace(i)) {
    message(paste("     installing", i))

Of course, you can also use {attachment} out of a package to list all package dependencies of R scripts using att_from_rscripts or Rmd files using att_from_rmds.

dummypackage <- system.file("dummypackage", package = "attachment")
att_from_rscripts(path = dummypackage)
att_from_rmds(path = file.path(dummypackage,"vignettes"))


Package {attachment} has a vignette to present the different functions available. There is also a recommandation to have a devstuff_history.R in the root directory of your package. (Have a look at devstuff_history.R in the present package)

vignette("fill-pkg-description", package = "attachment")

The vignette is available on the {pkgdown} page:

See full documentation realized using {pkgdown} at

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


attachment 0.0.9

  • att_from_rmd adds a temporary encoding parameter as knitr::purl will only deal with UTF-8 in the future. Parameter not added in att_from_rmds.
  • att_to_description if {covr} is needed, should be added in parameter extra.suggests
  • att_to_description has a parameter 'dir.t' to extract suggests dependencies from test directory Available by default

attachment 0.0.8

  • att_to_description allows for 'LinkingTo' field in DESCRIPTION with a message
  • att_from_rmd now reads yaml header
  • att_from_rmd use purl to extract R code in an other R session using system("Rscript -e ''")
  • att_from_rmd: add warn option to allow hide messages from purl()

attachment 0.0.7

  • att_to_description accept parameter path for package not being the current project
  • att_to_description no error if NAMESPACE is empty
  • create_dependencies_file filters base packages that cannot be installed

attachment 0.0.6

  • Prepare examples for CRAN

attachment 0.0.5

  • att_to_description deals with Remote dependencies
  • att_to_description deals with Depends dependencies
  • att_to_description keeps versions of packages previously added
  • att_to_description removes option for automatic pkg version
  • create_dependencies_file deals with github Remotes
  • att_from_rmds now accept a vector of Rmd filenames

attachment 0.0.4

  • Add examples in functions

attachment 0.0.3

  • att_to_description(add_version = TRUE) adds version of package in DESCRIPTION
  • att_to_description(pkg_ignore) adds possibility to ignore some packages

attachment 0.0.3

  • Get ready for CRAN
  • Add tests.

attachment 0.0.2

  • New function install_from_description to install all missing packages listed in the description file
  • Add an hex by @statnmap !
  • Allow for absence of vignette folder in att_to_description
  • Add create_dependencies_file to create a file listing all packages dependencies to install before your package
  • Allow for pkg::fun calls in R scripts with att_from_functions
  • Add option to run devtools::document() before att_from_description


  • Added a file to track changes to the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.2.4 by Sébastien Rochette, 2 months ago,

Report a bug at

Browse source code at

Authors: Sébastien Rochette [cre, aut] , Vincent Guyader [aut] , previous maintainer) , ThinkR [cph, fnd]

Documentation:   PDF Manual  

GPL-3 license

Imports desc, glue, knitr, magrittr, rmarkdown, roxygen2, stats, stringr, utils

Suggests testthat

Imported by fusen.

See at CRAN