When building your package, create a file called “devstuff_history.R” in the root directory. You will store all “manual” calls to devtools::xxx
and usethis::xxx
in this script.
Its first line should be :
You can then call {attachment} in this file to help you build your description file.
What you really want is to fill and update your description file along with the modifications of your documentation. Indeed, only this function will really be called in your “devstuff_history.R”.
Run attachment::att_amend_desc()
each time before devtools::check()
, this will save you some warnings and errors !
If you are running this inside a Rmd like here, you may need parameter inside_rmd = TRUE
.
# Copy package in a temporary directory
tmpdir <- tempdir()
file.copy(system.file("dummypackage",package = "attachment"), tmpdir, recursive = TRUE)
#> [1] TRUE
dummypackage <- file.path(tmpdir, "dummypackage")
# browseURL(dummypackage)
att_amend_desc(path = dummypackage, inside_rmd = TRUE)
#> Updating dummypackage documentation
#> Updating roxygen version in /tmp/RtmpwoWyGh/dummypackage/DESCRIPTION
#> Loading dummypackage
#> Writing NAMESPACE
#> Writing NAMESPACE
#> Package(s) Rcpp is(are) in category 'LinkingTo'. Check your Description file to be sure it is really what you want.
#> [-] 1 package(s) removed: utils.
#> [+] 2 package(s) added: stats, ggplot2.
You can use a similar approach for a {bookdown} description file using attachment::att_to_desc_from_is()
find_remotes()
checks if packages were installed from other source than CRAN. If so, it returns the content you can add to Remotes:
field in DESCRIPTION. For instance:
Remotes: thinkr-open/attachment
Remotes: gitlab::jimhester/covr
You probably want to combine it to att_from_description()
You can get the list of packages in your package with att_from_namespace()
pkg::function
or library/requireThis reads all files in directories of R scripts (default to R
directory of a package)
If you have vignette, you may want to list extra libraries, not listed in your “Depends” list. This function applies to any Rmd file, of course.
Once your package is finished. Well, is a package ever finished ? Let’s say, once you want to release a version of your package, you may want to deliver the list of dependencies your users will have to install. A little script like install.packages(c(...all dep...))
would be so nice :
This file will be placed in inst/dependencies.R
and contains :
# 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)
}
}
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()
.