knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
This is a package to create a DESCRIPTION
file for your project that lists
specific dependencies and versions of packages needed for analysis. Yes,
packages like packrat exist, but I've found it to be a bit cumbersome. With a
DESCRIPTION
file, it's possible to list the packages you need for an analysis
and install them with devtools.
Update: Of course, the feature-rich package desc already exists for this purpose AND it can be installed without needing the user to install devtools. That being said, it assumes you have an R package and panicks if you don't.
To install diaper, you should use the devtools package:
if (!requireNamespace("devtools")) install.packages("devtools", repos = "https://cran.rstudio.com") devtools::install_github("zkamvar/diaper")
Here's an example of creating a DESCRIPTION file using the RClone and dplyr packages.
First, you use add()
to add dependiencies to your DESCRIPTION file. If
the file doesn't exist, it will simply be created.
tmp <- tempdir() # when using this for your own project, simply keep this as # your current directory diaper::add(c("RClone (>= 1.0.2)", "dplyr (>= 0.5.0)"), field = "Imports", file = file.path(tmp, "DESCRIPTION"), name = "RCanalysis")
By default, it will show us what WILL be created. To create/overwrite our new
DESCRIPTION file, use write = TRUE
.
diaper::add(c("RClone (>= 1.0.2)", "dplyr (>= 0.5.0)"), field = "Imports", file = file.path(tmp, "DESCRIPTION"), name = "RCanalysis", write = TRUE) # View the file that we just created write.dcf(read.dcf(file.path(tmp, "DESCRIPTION")))
Now with devtools, we can install the package!
devtools::install(tmp)
We can also update fields such as the default version of R. Note that we don't
need the name
parameter here, because the file already exists.
diaper::add("R (>= 3.2.0)", field = "Depends", file = file.path(tmp, "DESCRIPTION"), write = TRUE) write.dcf(read.dcf(file.path(tmp, "DESCRIPTION")))
This may be the only iteration of the package, but if there is interest, it could be made more user-friendly with the following:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.