Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish code and docs re: options for DESCRIPTION fields #367

Merged
merged 15 commits into from May 29, 2018
Merged
7 changes: 4 additions & 3 deletions DESCRIPTION
Expand Up @@ -33,6 +33,7 @@ Imports:
rprojroot,
rstudioapi,
spelling,
utils,
whisker
Suggests:
covr,
Expand All @@ -43,10 +44,10 @@ Suggests:
styler,
testthat (>= 2.0.0),
withr
Remotes:
ropensci/git2r
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.0.1.9000
Language: en-US
Remotes:
ropensci/git2r
4 changes: 2 additions & 2 deletions R/create.R
Expand Up @@ -26,7 +26,7 @@
#' in RStudio, working directory is set to the new project.
#' @export
create_package <- function(path,
fields = getOption("devtools.desc"),
fields = NULL,
rstudio = rstudioapi::isAvailable(),
open = interactive()) {
path <- normalizePath(path, mustWork = FALSE)
Expand All @@ -44,7 +44,7 @@ create_package <- function(path,

use_directory("R")
use_directory("man")
use_description(fields = fields)
use_description(fields)
use_namespace()

if (rstudio) {
Expand Down
51 changes: 27 additions & 24 deletions R/description.R
@@ -1,38 +1,48 @@
#' Create a default DESCRIPTION file for a package.
#' Create a DESCRIPTION file
#'
#' @description
#' If you create a lot of packages, you can override the defaults by setting
#' option `"usethis.description"` to a named list. Here's an example of code one
#' could include in `.Rprofile`:
#' usethis consults the following sources, in this order, to set DESCRIPTION
#' fields:
#' * `fields` argument of [create_package()] or [use_description()]
#' * `getOption("usethis.description")` or `getOption("devtools.desc")`. The
#' devtools option is consulted only for backwards compatibility and it's
#' recommended to switch to an option named "usethis.description".
#' * Defaults built into usethis
#'
#' If you create a lot of packages, consider storing personalized defaults as a
#' named list in an option named `"usethis.description"`. Here's an example of
#' code to include in `.Rprofile`:
#'
#' ```
#' options(
#' usethis.name = "Jane Doe",
#' usethis.description = list(
#' `Authors@R` = 'person("Jane", "Doe", email = "jane@example.com", role = c#' ("aut", "cre"))',
#' `Authors@R` = 'person("Jane", "Doe", email = "jane@example.com", role = c("aut", "cre"))',
#' License = "MIT + file LICENSE",
#' Version = "0.0.0.9000"
#' Language: es
#' )
#' )
#' ```
#'
#' @param fields A named list of fields to add to \file{DESCRIPTION},
#' potentially overriding the defaults. If `NULL`, retrieved from
#' `getOption("usethis.description")`, and (for backward compatibility) from
#' `getOption("devtools.desc")`.
#' @param fields A named list of fields to add to DESCRIPTION, potentially
#' overriding default values. See [use_description()] for how you can set
#' personalized defaults using package options
#' @export
#' @examples
#' \dontrun{
#' use_description()
#'
#' use_description(fields = list(Language = "es"))
#' }
use_description <- function(fields = NULL) {
name <- project_name()
check_package_name(name)

fields <- fields %||%
getOption("usethis.description") %||%
getOption("devtools.desc") %||%
list()
## the definitive source of user-supplied info: in this call or via options
fields <- utils::modifyList(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth doing some light type checking here - e.g. that it's a list with names?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should all this logic be moved into build_description()? I think that would make the tests simpler since you wouldn't need so many temporary projects

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to move things around.

Part of the reason I tested via use_description(), though, was to test that directly specified fields override options & defaults, but in a targetted manner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it would be better to move all that code out so you can test independently of the writing.

fields %||% list(),
getOption("usethis.description") %||% getOption("devtools.desc") %||% list()
)

desc <- build_description(name, fields)
write_over(proj_get(), "DESCRIPTION", desc)
Expand All @@ -48,22 +58,15 @@ build_description <- function(name, fields = list()) {
}

build_description_list <- function(name, fields = list()) {
author <- getOption("devtools.desc.author") %||%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're abandoning these individual options in favour of the omnibus usethis.description? If yes, need to call out in the NEWS (although it probably doesn't affect many people)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I failed to see that this wasn't just grabbing the "author" element of the "devtools.desc" list.

But it does seem like something we could probably drop. Or switch entirely to "devtools.desc.XYZ". Supporting usethis and devtools options, in individual and ombibus form seems unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm fine with dropping it.

'person("First", "Last", , "first.last@example.com", c("aut", "cre"))'
license <- getOption("devtools.desc.license") %||% "What license it uses"
suggests <- getOption("devtools.desc.suggests")

defaults <- list(
Package = name,
Version = "0.0.0.9000",
Title = "What the Package Does (One Line, Title Case)",
Description = "What the package does (one paragraph).",
"Authors@R" = author,
License = license,
Suggests = suggests,
"Authors@R" = 'person("First", "Last", , "first.last@example.com", c("aut", "cre"))',
License = "What license it uses",
Encoding = "UTF-8",
LazyData = "true",
ByteCompile = "true"
LazyData = "true"
)

# Override defaults with user supplied options
Expand Down
8 changes: 4 additions & 4 deletions R/license.R
Expand Up @@ -96,13 +96,13 @@ license_data <- function(name, base_path = proj_get()) {


find_name <- function() {
name <- getOption("devtools.name")
if (!is.null(name) && name != "Your name goes here") {
name <- getOption("usethis.full_name")
if (!is.null(name)) {
return(name)
}

name <- getOption("usethis.full_name")
if (!is.null(name)) {
name <- getOption("devtools.name")
if (!is.null(name) && name != "Your name goes here") {
return(name)
}

Expand Down
11 changes: 5 additions & 6 deletions docs/dev/reference/create_package.html

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

2 changes: 1 addition & 1 deletion docs/dev/reference/index.html

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

51 changes: 34 additions & 17 deletions docs/dev/reference/use_description.html

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

11 changes: 5 additions & 6 deletions man/create_package.Rd

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

31 changes: 21 additions & 10 deletions man/use_description.Rd

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

4 changes: 3 additions & 1 deletion tests/testthat/helper.R
Expand Up @@ -23,9 +23,11 @@ scoped_temporary_thing <- function(dir = tempfile(pattern = pattern),
# Can't schedule a deferred project reset if calling this from the R console,
# which is useful when developing tests
if (identical(env, globalenv())) {
## I use proj_get() here deliberately, because after load_all()
## proj$cur is typically NULL
todo(
"Switching to a temporary project! To restore current project:\n",
"proj_set(\"", old, "\")"
"proj_set(\"", proj_get(), "\")"
)
} else {
withr::defer(proj_set(old), envir = env)
Expand Down