Skip to content

Commit

Permalink
first draft of a update_description_file() function cole-brokamp#12
Browse files Browse the repository at this point in the history
  • Loading branch information
nevrome committed Aug 31, 2019
1 parent 51dd446 commit 3eb7906
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RoxygenNote: 6.1.1
Depends:
R (>= 3.1.0)
Imports:
desc,
dplyr,
formatR,
knitr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export(install_deps_file)
export(install_package_guess)
export(make_deps_file)
export(parse_packages)
export(update_description_file)
importFrom(magrittr,"%>%")
importFrom(utils,packageDescription)
30 changes: 30 additions & 0 deletions R/update_description_file.R
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)
}
19 changes: 19 additions & 0 deletions man/update_description_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3eb7906

Please sign in to comment.