{"id":20665675,"url":"https://github.com/thinkr-open/attachment","last_synced_at":"2025-04-07T11:06:47.486Z","repository":{"id":34858169,"uuid":"136533647","full_name":"ThinkR-open/attachment","owner":"ThinkR-open","description":"Tools to deal with dependencies in scripts, Rmd and packages","archived":false,"fork":false,"pushed_at":"2024-02-18T09:57:04.000Z","size":5685,"stargazers_count":107,"open_issues_count":8,"forks_count":13,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-05-09T22:18:54.029Z","etag":null,"topics":["hacktoberfest","r","r-package","rstats"],"latest_commit_sha":null,"homepage":"https://thinkr-open.github.io/attachment/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThinkR-open.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-07T21:37:04.000Z","updated_at":"2024-06-10T13:23:10.596Z","dependencies_parsed_at":"2023-02-12T15:31:41.535Z","dependency_job_id":"8c533a7f-96bf-4395-9171-bb44a421b1b6","html_url":"https://github.com/ThinkR-open/attachment","commit_stats":{"total_commits":280,"total_committers":15,"mean_commits":"18.666666666666668","dds":0.6928571428571428,"last_synced_commit":"a779a495a6c3cd75a08a68d66fd681bfb1ecca02"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThinkR-open%2Fattachment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThinkR-open%2Fattachment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThinkR-open%2Fattachment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThinkR-open%2Fattachment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThinkR-open","download_url":"https://codeload.github.com/ThinkR-open/attachment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640462,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","r","r-package","rstats"],"created_at":"2024-11-16T19:33:14.405Z","updated_at":"2025-04-07T11:06:47.420Z","avatar_url":"https://github.com/ThinkR-open.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\u003c!-- badges: start --\u003e\n[![Coverage status](https://codecov.io/gh/ThinkR-open/attachment/branch/main/graph/badge.svg)](https://app.codecov.io/github/ThinkR-open/attachment/tree/main)\n[![CRAN status](https://www.r-pkg.org/badges/version/attachment)](https://cran.r-project.org/package=attachment)\n![downloads](http://cranlogs.r-pkg.org/badges/attachment)\n[![R-CMD-check](https://github.com/ThinkR-open/attachment/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/attachment/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/ThinkR-open/attachment/graph/badge.svg)](https://app.codecov.io/gh/ThinkR-open/attachment)\n\u003c!-- badges: end --\u003e\n\n# attachment \u003cimg src=\"man/figures/logo.png\" align=\"right\" alt=\"\" width=\"120\" /\u003e\n\nThe 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.\n  \nWhen 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.  \n\nWhy do you have to repeat twice the same thing ?    \nAnd 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 ?    \n\nLet {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 ?\n\nSee full documentation realized using {pkgdown} at \u003chttps://thinkr-open.github.io/attachment/\u003e  \n\n## Installation\n\nCRAN version\n```r\ninstall.packages(\"attachment\")\n```\n\nDevelopment version\n``` r\ninstall.packages('attachment', repos = c('https://thinkr-open.r-universe.dev', 'https://cloud.r-project.org'))\n```\n\n## Declare all dependencies in DESCRIPTION during package development\n\nWhat 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 !\n\n```{r, eval=FALSE}\nattachment::att_amend_desc()\n```\n\n{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.\n\n### Declare extra dependencies for extra uses\n\nIf 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:\n```{r, eval=FALSE}\nattachment::att_amend_desc(extra.suggests = c(\"pkgdown\", \"covr\"), update.config = TRUE)\n```\n\nNote 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\".\n\nIf 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. \n\nIndeed, 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.\n\n### Automatically fill the \"Remotes\" field\n\nIf 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:\n\n```{r, eval=FALSE}\nattachment::set_remotes_to_desc()\n```\n\n\n## Example on a fake package\n\n```{r}\n# Copy example package in a temporary directory\ntmpdir \u003c- tempfile(pattern = \"fakepkg\")\ndir.create(tmpdir)\nfile.copy(system.file(\"dummypackage\",package = \"attachment\"), tmpdir, recursive = TRUE)\ndummypackage \u003c- file.path(tmpdir, \"dummypackage\")\n# browseURL(dummypackage)\n\n# Fill the DESCRIPTION file automatically\n# `inside_rmd` is specifically designed here to allow to run this command line in the \"Readme.Rmd\" file\ndesc_file \u003c- attachment::att_amend_desc(path = dummypackage, inside_rmd = TRUE, update.config = TRUE)\n\n# Add Remotes if you have some installed\nattachment::set_remotes_to_desc(path.d = desc_file)\n\n# Clean state\nunlink(tmpdir, recursive = TRUE)\n```\n\n## More on finding Remotes repositories (non installed from CRAN)\n\nFind packages installed out of CRAN. This helps fill the \"Remotes\" field in DESCRIPTION file with `set_remotes_to_desc()`.  \nBehind the scene, it uses `find_remotes()`.  \n\n- See the examples below if {fusen} is installed from GitHub\n  + Also works for GitLab, Bioconductor, Git, Local installations\n  \n```{r, eval=FALSE}\n# From GitHub\nremotes::install_github(\"ThinkR-open/fusen\",\n                        quiet = TRUE, upgrade = \"never\")\nattachment::find_remotes(\"fusen\")\n#\u003e $fusen\n#\u003e [1] \"ThinkR-open/fusen\"\n```\n\n\n## Find and install missing dependencies required for your R scripts\nTo quickly install missing packages from a DESCRIPTION file, use:\n\n```{r, eval=TRUE}\nattachment::install_from_description()\n```\n\nTo quickly install missing packages needed to compile Rmd files or run R scripts, use:\n\n```{r, eval=FALSE}\nattachment::att_from_rmds(path = \".\") %\u003e% attachment::install_if_missing()\n\nattachment::att_from_rscripts(path = \".\") %\u003e% attachment::install_if_missing()\n```\n\nFunction `attachment::create_dependencies_file()` will create a `dependencies.R` file in `inst/` directory. This R script contains the procedure to quickly install missing dependencies:\n\n```{r eval=FALSE}\n# Remotes ----\n# remotes::install_github(\"ThinkR-open/fcuk\")\n# Attachments ----\nto_install \u003c- c(\"covr\", \"desc\", \"devtools\", \"glue\", \"knitr\", \"magrittr\", \"rmarkdown\", \"stats\", \"stringr\", \"testthat\", \"utils\")\nfor (i in to_install) {\n  message(paste(\"looking for \", i))\n  if (!requireNamespace(i)) {\n    message(paste(\"     installing\", i))\n    install.packages(i)\n  }\n}\n```\n\n## Allow the CI to install all dependencies required for your bookdown, pagedown, quarto, ...\n\nIf 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()`.\n\n```{r, eval=FALSE}\nusethis::use_description()\n# bookdown Imports are in Rmds\nimports \u003c- c(\"bookdown\", attachment::att_from_rmds(\".\"))\nattachment::att_to_desc_from_is(path.d = \"DESCRIPTION\",\n                                imports = imports, suggests = NULL)\n```\n\nThen, install dependencies with\n```{r, eval=FALSE}\nremotes::install_deps()\n```\n\n\n## List packages required in any script or notebook\n\nOf 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()`.  \nIf you are running this inside a Rmd, you may need parameter `inside_rmd = TRUE`.  \n\n```{r, eval=TRUE}\nlibrary(attachment)\ndummypackage \u003c- system.file(\"dummypackage\", package = \"attachment\")\n\natt_from_rscripts(path = dummypackage)\natt_from_rmds(path = file.path(dummypackage, \"vignettes\"), inside_rmd = TRUE)\n```\n\n## Vignettes included\n\nPackage {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](https://github.com/ThinkR-open/attachment/blob/main/dev/dev_history.R) in the present package*)\n\n```{r, eval=FALSE}\nvignette(\"a-fill-pkg-description\", package = \"attachment\")\nvignette(\"b-bookdown-and-scripts\", package = \"attachment\")\nvignette(\"use_renv\", package = \"attachment\")\nvignette(\"create-dependencies-file\", package = \"attachment\")\n```\n\nThe vignettes are available on the {pkgdown} page, in the \"Articles\" menu: \u003chttps://thinkr-open.github.io/attachment/\u003e\n\n  \n## Code of Conduct\n\nPlease note that the attachment project is released with a [Contributor Code of Conduct](https://thinkr-open.github.io/attachment/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkr-open%2Fattachment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkr-open%2Fattachment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkr-open%2Fattachment/lists"}