{attachment} is on CRAN !

We are pleased to announce that our package {attachment} is now available on CRAN. 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.

Deal with dependencies during package development

If you ever had the following error when checking your package, {attachment} is for you:

R CMD check results 1 error | 0 warnings | 0 notes checking package dependencies … ERROR Namespace dependency not required: ‘collateral’

With this error, Colin would answer you:

namespace-dependency-not-required

Have you listed the package in the DESCRIPTION and in the NAMESPACE?

Indeed, the steps to deal with dependencies in your R functions when creating a package are:

  • Use package::function directly in the code or list the function in the {roxygen2} header with @importFrom package function
  • Run devtools::document() so that functionappears in the NAMESPACE file
  • Add the {package} in the list of Depends in the DESCRIPTION file

Also as you create a vignette and tests in your package, you need to remember to list packages in the Suggestssection of your DESCRIPTION file

{attachment} is here to help

Package {attachment} will do all the above steps for you.
Install the package from CRAN or from Github:

# From CRAN
install.packages("attachment")
# From github
remotes::install_github("ThinkR-open/attachment")

If you correctly called the package dependencies in the {roxygen2} skeleton, in your functions, in your Rmarkdown vignettes and in your tests, you only need to run attachment::att_to_description()just before devtools::check(). And that’s it, there is nothing else to remember !

Use {attachment} out of package development

{attachment} parses code of R scripts and Rmd. It lists all packages required to run that code. If you want to install all packages before trying to run the code of somebody else, you can use:

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

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

Also, if you build packages or Shiny Apps in packages for your delivery to your customers, or if you have to install your R product on customers’ servers, you will need to install all required packages before installation. A good start is to use a R script that lists all packages required. With function attachment::create_dependencies_file(), you can build this kind of script:

# 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))
    install.packages(i)
  }
}

Documentation and participation

To read the full documentation of package {attachment}, you can follow this link to the {pkgodwn} site.

If you want to participate to the development, report bugs or propose pull requests, you will find the github page here.

Find our other contributions to open-source and the R community here.


About the author

Sébastien Rochette

Sébastien Rochette

Modélisateur, formateur R, joueur de cartographies



Also read