• Stars
    star
    104
  • Rank 319,143 (Top 7 %)
  • Language
    R
  • License
    Other
  • Created almost 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tools to deal with dependencies in scripts, Rmd and packages

R-CMD-check Coverage status CRAN status downloads

attachment

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 ?

See full documentation realized using {pkgdown} at https://thinkr-open.github.io/attachment/

Installation

CRAN version

install.packages("attachment")

Development version

install.packages('attachment', repos = c('https://thinkr-open.r-universe.dev', 'https://cloud.r-project.org'))

Declare all dependencies in DESCRIPTION during package development

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 !

attachment::att_amend_desc()

{attachment} detects all calls to library(pkg), @importFrom pkg fun, pkg::fun() in the different classical directories of your R package, then list them in the correct β€œImports” or β€œSuggests” category in the DESCRIPTION file, according to their position in the package.

Declare extra dependencies for extra uses

If you want to add extra packages like {pkgdown} or {covr} that are not listed in any script in your package, a call for your development packages would be:

attachment::att_amend_desc(extra.suggests = c("pkgdown", "covr"), update.config = TRUE)

Note the update.config = TRUE parameter that will save the parameters used in the call of att_amend_desc() to the package configuration file: β€œdev/config_attachment.yaml”.

If you run att_amend_desc() a second time afterwards, directly from the console, it will use the last set of parameters extracted from the configuration file.

Indeed, we recommend to store the complete command line in a β€œdev/dev_history.R” file to update and run it when needed. If the parameters do not change, you can run attachment::att_amend_desc() directly in the console, wherever you are, it will use the configuration file.

Automatically fill the β€œRemotes” field

If you would like to detect the sources of your installations so that you can add dependencies in the β€œRemotes” field of your DESCRIPTION file, to mimic your local installation, you will use:

attachment::set_remotes_to_desc()

Example on a fake package

# Copy example package in a temporary directory
tmpdir <- tempfile(pattern = "fakepkg")
dir.create(tmpdir)
file.copy(system.file("dummypackage",package = "attachment"), tmpdir, recursive = TRUE)
#> [1] TRUE
dummypackage <- file.path(tmpdir, "dummypackage")
# browseURL(dummypackage)

# Fill the DESCRIPTION file automatically
# `inside_rmd` is specifically designed here to allow to run this command line in the "Readme.Rmd" file
desc_file <- attachment::att_amend_desc(path = dummypackage, inside_rmd = TRUE, update.config = TRUE)
#> 'update.config' was set to TRUE, hence, 'use.config' was forced to FALSE
#> Saving attachment parameters to yaml config file
#> Updating dummypackage documentation
#> ────────────────────────────────────────────────────────────────────────────────
#> Changes in roxygen2 7.0.0:
#> * `%` is now escaped automatically in Markdown mode.
#> Please carefully check .Rd files for changes
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> Setting `RoxygenNote` to "7.2.2"
#> β„Ή Loading dummypackage
#> Writing 'οΏ½]8;;file:///tmp/Rtmp3Dpn4h/fakepkg3538450e5c49/dummypackage/NAMESPACEοΏ½NAMESPACEοΏ½]8;;οΏ½'
#> Writing 'οΏ½]8;;file:///tmp/Rtmp3Dpn4h/fakepkg3538450e5c49/dummypackage/NAMESPACEοΏ½NAMESPACEοΏ½]8;;οΏ½'
#> β„Ή Loading dummypackage
#> 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, glue.

# Add Remotes if you have some installed
attachment::set_remotes_to_desc(path.d = desc_file)
#> There are no remote packages installed on your computer to add to description
#> NULL

# Clean state
unlink(tmpdir, recursive = TRUE)

More on finding Remotes repositories (non installed from CRAN)

Find packages installed out of CRAN. This helps fill the β€œRemotes” field in DESCRIPTION file with set_remotes_to_desc().
Behind the scene, it uses find_remotes().

  • See the examples below if {fusen} is installed from GitHub
    • Also works for GitLab, Bioconductor, Git, Local installations
# From GitHub
remotes::install_github("ThinkR-open/fusen",
                        quiet = TRUE, upgrade = "never")
attachment::find_remotes("fusen")
#> $fusen
#> [1] "ThinkR-open/fusen"

Find and install missing dependencies required for your R scripts

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

attachment::install_from_description()
#> All required packages are installed

To quickly install missing packages needed to compile Rmd files or run R scripts, 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:

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

Allow the CI to install all dependencies required for your bookdown, pagedown, quarto, …

If you write a {bookdown} and want to publish it on Github using GitHub Actions or GitLab CI for instance, you will need a DESCRIPTION file with list of dependencies just like for a package. In this case, you can use the function to description from import/suggest: att_to_desc_from_is().

usethis::use_description()
# bookdown Imports are in Rmds
imports <- c("bookdown", attachment::att_from_rmds("."))
attachment::att_to_desc_from_is(path.d = "DESCRIPTION",
                                imports = imports, suggests = NULL)

Then, install dependencies with

remotes::install_deps()

List packages required in any script or notebook

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/qmd files using att_from_rmds().
If you are running this inside a Rmd, you may need parameter inside_rmd = TRUE.

library(attachment)
dummypackage <- system.file("dummypackage", package = "attachment")

att_from_rscripts(path = dummypackage)
#> [1] "stats"        "testthat"     "dummypackage"
att_from_rmds(path = file.path(dummypackage, "vignettes"), inside_rmd = TRUE)
#> [1] "knitr"     "rmarkdown" "glue"

Vignettes included

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

vignette("a-fill-pkg-description", package = "attachment")
vignette("b-bookdown-and-scripts", package = "attachment")
vignette("use_renv", package = "attachment")
vignette("create-dependencies-file", package = "attachment")

The vignettes are available on the {pkgdown} page, in the β€œArticles” menu: https://thinkr-open.github.io/attachment/

Code of Conduct

Please note that the attachment project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms

More Repositories

1

golem

A Framework for Building Robust Shiny Apps
R
868
star
2

remedy

RStudio Addins to Simplify Markdown Writing
R
448
star
3

companies-using-r

A Curated list of R uses in entreprise
247
star
4

prepare-for-cran

A Collaborative list of things to know before submitting to CRAN
232
star
5

engineering-shiny-book

Engineering Production-Grade Shiny Apps β€” Published in the R Series
TeX
217
star
6

dockerfiler

Easy Dockerfile Creation from R
R
159
star
7

fusen

Inflate your package from a simple flat Rmd
R
148
star
8

fakir

Create Fake Data in R for tutorials
R
128
star
9

shinipsum

Lorem-Ipsum-like Helpers for fast Shiny Prototyping
R
115
star
10

shinysnippets

A series of shiny related RStudio Snippets
R
101
star
11

fcuk

A R package designed to help people with clumsy fingers.
R
89
star
12

wedding

Shiny app with custom css to prepare and manage a wedding
R
51
star
13

togglr

an R and Rstudio wrapper for toggl Api
R
46
star
14

devindocker

Development in a Docker container
R
37
star
15

gitlabr

An R client for the GitLab API
R
37
star
16

mariobox

A Framework For Packaging {plumber} APIs
R
37
star
17

seven31

R πŸ“¦ for R FAQ 7.31
R
36
star
18

checkhelper

A package to help deal with devtools::check outputs
R
34
star
19

gitdown

Document each modification of your software by turning your git commits into a gitbook
R
34
star
20

littleboxes

Rstudio Addin - create boxed title in an Rscript
R
33
star
21

licensing-r

A Bookdown about R & licenses
HTML
32
star
22

thinkr

Some tools for cleaning up messy 'Excel' files to be suitable for R
R
29
star
23

prompt

Dynamic prompt
R
28
star
24

testdown

Turn your 'testthat' results into a Bookdown.
R
26
star
25

prenoms

French Baby Names 1900-2020
R
23
star
26

ztype

How fast can you type R functions on your keyboard ?
R
23
star
27

tagsinput

Bootstrap tags input for shiny
R
20
star
28

tweetstorm

tweetstorm
R
19
star
29

utf8splain

Explain utf-8 encoded strings
R
18
star
30

js4shinyfieldnotes

Field Notes on JavaScript for Shiny Users
HTML
13
star
31

brighter

A toolbox of functions for easier shiny development.
R
12
star
32

who

Data from the World Health Organisation
R
12
star
33

rtodoist

Package to call the todoist API. Manage your ToDo lists with todoist from R.
R
11
star
34

papillon

Build And Highlight Package Documentation With Customized Templates
R
11
star
35

isc-proposal

RConsortium ISC Proposal β€” "Rebooting and Extending R for Neo4J"
9
star
36

bank

Alternative caching backends for `{memoise}` & `{shiny}`.
R
9
star
37

stopwords

stop words in several languages
R
9
star
38

prenomsapp

A Web App for French Baby Names
R
8
star
39

uni

unicode tibble
R
8
star
40

timer

A dead simple timer page written in JavaScript
TypeScript
8
star
41

shinidraw

R
7
star
42

arpr

Advanced R Pipes
R
7
star
43

datasets

Various datasets, free to use
R
6
star
44

elvis

'Shiny' renderers and observers made safer
R
6
star
45

spongecake

Transform a Movie into a Synthetic Picture.
R
6
star
46

golem-workshop

Repo for the Golem Workshop during ThinkR & RStudio Roadshow 2019
6
star
47

purrple

some html widgets
JavaScript
6
star
48

inca3

Jeux de donnΓ©es issu de l’étude de consommation alimentaire des franΓ§ais inca3 de l'ANSES
R
5
star
49

ghooks

'Golem' Hooks for Standard 'Shiny' Apps
R
5
star
50

rusk

Multiplication Tables On a Modular Circle
R
5
star
51

isc-proposal-licence

Licensing R - Guidelines and tools
5
star
52

prague

Where golems come to life
R
5
star
53

shinytodocx

POC permettant de montrer comment construire un rapport .docx Γ  partir d 'une application shiny
HTML
4
star
54

legislatives2017

RΓ©sultat des elections legislatives 2017
R
4
star
55

mongooser

A port of MongooseJS to R
R
4
star
56

signature

πŸ–ŠοΈ Fill in your email signature from a template
R
4
star
57

lozen

The objective of {lozen} is to centralize project management tools for Devs and Lead Devs.
R
4
star
58

tutor

R
4
star
59

thinkrdashboard

State of ThinkR open-source projects
R
4
star
60

w3css

[WIP] Implementation of W3.CSS for {shiny}
R
4
star
61

googlefonts

using google fonts in shiny applications
R
3
star
62

clientapp

Showcase of Shiny App for client database and after-sales calls exploration
R
3
star
63

installR

script d'installation de configuration de R
R
3
star
64

rstudioconf2019

An e-poster given during the rstudio::conf(2019).
3
star
65

docker4dev

Repository with DockerFiles for tutorials
R
2
star
66

architekter

A tool to extract a {ggplot2} theme from a Figma file
R
2
star
67

golemverse.org

golemverse
JavaScript
2
star
68

golemstream

Streams by the {golem} team
HTML
2
star
69

bookshiny

R
2
star
70

ipsum

dummy text generator
R
2
star
71

fa

font awesome R tools
R
2
star
72

gemstones

Make Your 'golem' App Shine
R
2
star
73

rfrance

Aggregation de blog sur #rstats en πŸ‡«πŸ‡·
CSS
2
star
74

activecollabr

Access the active collab API from R.
R
2
star
75

abcdR

1
star
76

thinkr-hex-stickers

HQ hex and visuals for ThinkR projects
1
star
77

thinkrtemplate

A pkgdown template for ThinkR packages
CSS
1
star
78

axonaut

axonaut API for R
R
1
star
79

golem-paper

Repo for a paper about golem
1
star
80

cranology

R
1
star
81

tetraclasse

Satisfaction analysis - LLosa matrix - Tetraclasse model
R
1
star
82

emojitsu

Emoji Grammar
R
1
star
83

example.auto

Repository for automatic repo management tests
R
1
star
84

thinkr-open.r-universe.dev

Packages for the ThinkR Universe
1
star
85

quakr

🌈 Quakr formats for revealjs
SCSS
1
star
86

blogs-comments

Comments on our blog posts with Utterances
1
star
87

iframe.illustrations

Some iframe for our blog posts on thinkr.fr
HTML
1
star
88

slack

slack API for R
R
1
star
89

meetup-r

Meetup "R, vous avez dit R ?"
1
star