---
title: "Create dependencies file"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Create dependencies file}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r}
library(attachment)
```

<!-- WARNING - This vignette is generated by {fusen} from dev/flat_create_dependencies_file.Rmd: do not edit by hand -->




  


# Write instructions to install all dependencies from a "DESCRIPTION" file

`create_dependencies_file()` creates "inst/dependencies.R" file with the instructions to install all dependencies listed in your "DESCRIPTION".
This accounts for the "Remotes" field and write instructions accordingly.   

Use `create_dependencies_file(to = NULL)` to only retrieve the output as a list of character and not save a "inst/dependencies.R" file in your project. 
This can be used in a `Readme.Rmd` file for instance, to get the full list of each dependency to install and how, from any "DESCRIPTION" file.


```{r examples-create_dependencies_file}
#| eval: yes

# Create a fake package
tmpdir <- tempfile(pattern = "depsfile")
dir.create(tmpdir)
file.copy(system.file("dummypackage",package = "attachment"), tmpdir,
          recursive = TRUE)
dummypackage <- file.path(tmpdir, "dummypackage")

# Create the dependencies commands but no file
create_dependencies_file(
  path = file.path(dummypackage,"DESCRIPTION"),
  to = NULL,
  open_file = FALSE)

# Create the dependencies files in the package
create_dependencies_file(
  path = file.path(dummypackage,"DESCRIPTION"),
  to = file.path(dummypackage, "inst/dependencies.R"),
  open_file = FALSE)
list.files(file.path(dummypackage, "inst"))
# browseURL(dummypackage)

# Clean temp files after this example
unlink(tmpdir, recursive = TRUE)
```




