{attachment} is on CRAN !

[This article was first published on (en) The R Task Force, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:

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
# From github

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))

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.

The post {attachment} is on CRAN ! appeared first on (en) The R Task Force.

To leave a comment for the author, please follow the link and comment on their blog: (en) The R Task Force.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)