forked from cole-brokamp/automagic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first draft of a update_description_file() function cole-brokamp#12
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ RoxygenNote: 6.1.1 | |
Depends: | ||
R (>= 3.1.0) | ||
Imports: | ||
desc, | ||
dplyr, | ||
formatR, | ||
knitr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' add missing packages to package DESCRIPTION file | ||
#' | ||
#' @details uses \code{get_dependent_packages()} to find dependencies and | ||
#' adds them to the description file with the desc package | ||
#' | ||
#' @param directory folder to search for R and Rmd files. | ||
#' The DESCRIPTION file is expected to be in this directory. | ||
#' | ||
#' @export | ||
update_description_file <- function(directory = getwd()) { | ||
description_file_path <- file.path(directory, "DESCRIPTION") | ||
# check if a descripton file is available | ||
if (!file.exists(description_file_path)) { | ||
stop("There is no DESCRIPTION file in this directory.") | ||
} | ||
# get dependent packages | ||
dependent_packages <- get_dependent_packages(directory) | ||
# get description object | ||
desc <- desc::description$new(description_file_path) | ||
# add packages to description object | ||
purrr::walk( | ||
.x = dependent_packages, | ||
.f = function(x, y) { | ||
y$set_dep(x) | ||
}, | ||
desc | ||
) | ||
# write description object to file system | ||
desc$write(description_file_path) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.