Site icon R-bloggers

{attachment} v0.2.3: fill the Remotes field

[This article was first published on Rtask, 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.

You can read the original post in its original format on Rtask website by ThinkR here: {attachment} v0.2.3: fill the Remotes field

A new version of {attachment} is available on CRAN. Get dependencies installed from GitHub, GitLab, … and add the link to the ‘Remotes’ field in the DESCRIPTION file of your package.

install.packages("attachment")

{attachment} helps you deal with dependencies during your package development.
All packages used in your code needs to be declared in the DESCRIPTION file, so that other users can install your package with required dependencies. {attachment} will extract packages declared in your codes and list them in the correct place (‘Imports’, ‘Suggests’ and now ‘Remotes’) in your DESCRIPTION file.

Note that {attachment} can be used out of package development if you want to extract the list of dependencies used in your R scripts or Rmarkdown files, wherever they are stored.

TL;DR – NEWS

Major changes

Minor changes

Bug fixes

Reminder: during package development

The star function of {attachment} is attachment::att_amend_desc() to be run each time before devtools::check(). This will save you some warnings and errors !

att_amend_desc()

New in v0.2.3

Propose content for the “Remotes” field in DESCRIPTION

set_remotes_to_desc() adds packages that were installed on your computer from other sources than CRAN to Remotes: field in DESCRIPTION, according to the list in ‘Imports’ and ‘Suggests’.

For instance:

You may want to run it after att_amend_desc() in your package development.

att_amend_desc(dummypackage) %>%
  set_remotes_to_desc()

Let’s create a small DESCRIPTION file

desc_file <- tempfile(pattern = "desc")
cat("
Imports:
    attachment,
    glue
Suggests:
    desc
", file = desc_file) 

Let me install {attachment} from GitHub and run set_remotes_to_desc() on the exemple file.

# install from GitHub
remotes::install_github("ThinkR-open/attachment", 
                        upgrade = "never", quiet = TRUE)
# Add 'Remotes' field
set_remotes_to_desc(desc_file)
## Remotes for attachment were added to DESCRIPTION.
# Read the DESCRIPTION file
cat(readLines(desc_file), sep = "\n")
## Imports:
##     attachment,
##     glue
## Suggests:
##     desc
## Remotes:  
##     thinkr-open/attachment

The ‘Remotes’ field was correctly added!

Find remote installations on your computer

If you only want to find if packages were installed from other source than CRAN, without amending DESCRIPTION, you can use find_remotes().

You can use it on a vector of packages names

# install from GitHub
remotes::install_github("ThinkR-open/attachment",
                        upgrade = "never", quiet = TRUE)
find_remotes(pkg = c("attachment", "desc", "glue"))
## $attachment
## [1] "thinkr-open/attachment"
# install from CRAN
remotes::install_cran("attachment", 
                      upgrade = "never", quiet = TRUE)
find_remotes(pkg = c("attachment", "desc", "glue"))
## NULL

You may also want to combine it to att_from_description() or any other att_from_*()

att_from_description() %>%
  find_remotes()
att_from_rscripts(path = "R/") %>%
  find_remotes()
att_from_rmds(path = "vignettes/") %>%
  find_remotes()

To go further

Note that {attachment} is used in {fusen}, a package that reduces package development to a simple Rmarkdown file. Find out more in the dedicated documentation: https://thinkr-open.github.io/fusen/

This post is better presented on its original ThinkR website here: {attachment} v0.2.3: fill the Remotes field

To leave a comment for the author, please follow the link and comment on their blog: Rtask.

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.