From a926870bc6a2616e64f0446c2ec09c5f3dafd668 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 26 Jun 2024 12:01:09 -0700 Subject: [PATCH 01/22] .fun seems better than .help, if you don't need custom text --- R/badge.R | 2 +- R/proj.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/badge.R b/R/badge.R index 23868bc3c..cba764169 100644 --- a/R/badge.R +++ b/R/badge.R @@ -45,7 +45,7 @@ use_badge <- function(badge_name, href, src) { if (is.null(path)) { ui_bullets(c( "!" = "Can't find a README for the current project.", - "i" = "See {.help usethis::use_readme_rmd} for help creating this file.", + "i" = "See {.fun usethis::use_readme_rmd} for help creating this file.", "i" = "Badge link will only be printed to screen." )) path <- "README" diff --git a/R/proj.R b/R/proj.R index 0eca24320..ce646d317 100644 --- a/R/proj.R +++ b/R/proj.R @@ -90,7 +90,7 @@ proj_set <- function(path = ".", force = FALSE) { if (is.null(new_project)) { ui_abort(c( "Path {.path {pth(path)}} does not appear to be inside a project or package.", - "Read more in the help for {.help usethis::proj_get}." + "Read more in the help for {.fun usethis::proj_get}." )) } proj_set(path = new_project, force = TRUE) @@ -227,7 +227,7 @@ check_is_project <- function() { if (!possibly_in_proj()) { ui_abort(c( "We do not appear to be inside a valid project or package.", - "Read more in the help for {.help usethis::proj_get}." + "Read more in the help for {.fun usethis::proj_get}." )) } } From be5e7f0fa3699b94d4b802d6ef2b8b07ccdef325 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 26 Jun 2024 12:14:44 -0700 Subject: [PATCH 02/22] Make this runnable --- R/badge.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/badge.R b/R/badge.R index cba764169..b97bf08d1 100644 --- a/R/badge.R +++ b/R/badge.R @@ -60,7 +60,7 @@ use_badge <- function(badge_name, href, src) { if (changed && path_ext(path) == "Rmd") { ui_bullets(c( - "_" = "Re-knit {.path {pth(path)}} with {.fun devtools::build_readme}." + "_" = "Re-knit {.path {pth(path)}} with {.run devtools::build_readme()}." )) } invisible(changed) From 90dc39338046117a661de3c62dc272ae2956e0fe Mon Sep 17 00:00:00 2001 From: "Jennifer (Jenny) Bryan" Date: Wed, 26 Jun 2024 14:33:15 -0700 Subject: [PATCH 03/22] Update URLs related to a codecov badge (#2008) * Update URLs related to a codecov badge Fixes #1991 Closes #1876 * Add a NEWS bullet --- NEWS.md | 3 +++ R/coverage.R | 5 ++--- README.Rmd | 2 +- README.md | 4 ++-- tests/testthat/_snaps/coverage.md | 13 +++++++++++++ tests/testthat/test-coverage.R | 5 +++++ 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/_snaps/coverage.md create mode 100644 tests/testthat/test-coverage.R diff --git a/NEWS.md b/NEWS.md index d7f3a70a0..e6a73b19e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # usethis (development version) +* The URLs baked into the badge generated by `use_coverage(type = "codecov")` + no longer specify a branch (#2008). + * The `ui_*()` functions have been marked as [superseded](https://lifecycle.r-lib.org/articles/stages.html#superseded). External users of these functions are encouraged to use the diff --git a/R/coverage.R b/R/coverage.R index dc9dd5f2a..2406cd8bd 100644 --- a/R/coverage.R +++ b/R/coverage.R @@ -44,9 +44,8 @@ use_covr_ignore <- function(files) { } use_codecov_badge <- function(repo_spec) { - default_branch <- git_default_branch() - url <- glue("https://app.codecov.io/gh/{repo_spec}?branch={default_branch}") - img <- glue("https://codecov.io/gh/{repo_spec}/branch/{default_branch}/graph/badge.svg") + url <- glue("https://codecov.io/gh/{repo_spec}") + img <- glue("https://codecov.io/gh/{repo_spec}/graph/badge.svg") use_badge("Codecov test coverage", url, img) } diff --git a/README.Rmd b/README.Rmd index 0fbb3d006..ed3b4ac0a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,10 +17,10 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml) -[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main) [![CRAN status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) [![.github/workflows/R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis) usethis is a workflow package: it automates repetitive tasks that arise during project setup and development, both for R packages and non-package projects. diff --git a/README.md b/README.md index a68a2b255..b865cb055 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ [![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml) -[![Codecov test -coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main) [![CRAN status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) [![.github/workflows/R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/r-lib/usethis/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis) usethis is a workflow package: it automates repetitive tasks that arise diff --git a/tests/testthat/_snaps/coverage.md b/tests/testthat/_snaps/coverage.md new file mode 100644 index 000000000..c849622be --- /dev/null +++ b/tests/testthat/_snaps/coverage.md @@ -0,0 +1,13 @@ +# we use specific URLs in a codecov badge + + Code + use_codecov_badge("OWNER/REPO") + Message + ! Can't find a README for the current project. + i See `usethis::use_readme_rmd()` for help creating this file. + i Badge link will only be printed to screen. + [ ] Copy and paste the following lines into 'README': + + [![Codecov test coverage](https://codecov.io/gh/OWNER/REPO/graph/badge.svg)](https://codecov.io/gh/OWNER/REPO) + + diff --git a/tests/testthat/test-coverage.R b/tests/testthat/test-coverage.R new file mode 100644 index 000000000..954938c49 --- /dev/null +++ b/tests/testthat/test-coverage.R @@ -0,0 +1,5 @@ +test_that("we use specific URLs in a codecov badge", { + create_local_package() + withr::local_options(usethis.quiet = FALSE) + expect_snapshot(use_codecov_badge("OWNER/REPO")) +}) From 1398d7b4492d7a444c029c3a3518eff65026b3cd Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Thu, 27 Jun 2024 07:32:55 +0800 Subject: [PATCH 04/22] tolerate empty lines at start of news file (#1977) * tolerate empty lines at start of news file * Tweak search for first non-whitespace line --------- Co-authored-by: Jenny Bryan --- NEWS.md | 3 +++ R/news.R | 13 +++++++++---- tests/testthat/test-news.R | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index e6a73b19e..550ba4a90 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,9 @@ usethis no longer uses the `ui_*()` functions internally, in favor of new cli-based helpers that are not exported. +* `usethis::use_version()` now tolerates empty / blank lines preceding the + first section title in the package NEWS file. (#1976) + # usethis 2.2.3 * Patch release with changes to `.Rd` files requested by CRAN. diff --git a/R/news.R b/R/news.R index 548377c4a..706c63e9c 100644 --- a/R/news.R +++ b/R/news.R @@ -40,15 +40,20 @@ use_news_heading <- function(version) { } news <- read_utf8(news_path) - title <- glue("# {project_name()} {version}") + idx <- match(TRUE, grepl("[^[:space:]]", news)) + + if (is.na(idx)) { + return(news) + } - if (title == news[[1]]) { + title <- glue("# {project_name()} {version}") + if (title == news[[idx]]) { return(invisible()) } development_title <- glue("# {project_name()} (development version)") - if (development_title == news[[1]]) { - news[[1]] <- title + if (development_title == news[[idx]]) { + news[[idx]] <- title ui_bullets(c("v" = "Replacing development heading in {.path NEWS.md}.")) return(write_utf8(news_path, news)) diff --git a/tests/testthat/test-news.R b/tests/testthat/test-news.R index 73f1f73f0..469d70ff2 100644 --- a/tests/testthat/test-news.R +++ b/tests/testthat/test-news.R @@ -32,3 +32,16 @@ test_that("use_news_md() sets version number when 'production version'", { expect_snapshot(writeLines(read_utf8(proj_path("NEWS.md"))), transform = scrub_testpkg) }) + +test_that("use_news_heading() tolerates blank lines at start", { + create_local_package() + + header <- sprintf("# %s (development version)", project_name()) + writeLines(c("", header, "", "* Fixed the bugs."), con = "NEWS.md") + + use_news_heading(version = "1.0.0") + contents <- read_utf8("NEWS.md") + + expected <- sprintf("# %s 1.0.0", project_name()) + expect_equal(contents[[2L]], expected) +}) From 2663877de3f6600109132ae05bef8c381802c18b Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:14:26 -0400 Subject: [PATCH 05/22] tweak `compute_name()` to recognize snapshot files (#1990) --- NEWS.md | 2 ++ R/r.R | 4 ++-- tests/testthat/_snaps/r.md | 2 +- tests/testthat/test-r.R | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 550ba4a90..5ef77276c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `use_test()` and `use_r()` now work when you are in `tests/testthat/_snaps/{foo}.md` (@olivroy, #1988). + * The URLs baked into the badge generated by `use_coverage(type = "codecov")` no longer specify a branch (#2008). diff --git a/R/r.R b/R/r.R index 40b7ffa77..f6df25696 100644 --- a/R/r.R +++ b/R/r.R @@ -116,8 +116,8 @@ compute_active_name <- function(path, ext, error_call = caller_env()) { path <- proj_path_prep(path_expand_r(path)) dir <- path_dir(proj_rel_path(path)) - if (!dir %in% c("R", "src", "tests/testthat")) { - cli::cli_abort("Open file must be a code or test file.", call = error_call) + if (!dir %in% c("R", "src", "tests/testthat", "tests/testthat/_snaps")) { + cli::cli_abort("Open file must be code, test, or snapshot.", call = error_call) } file <- path_file(path) diff --git a/tests/testthat/_snaps/r.md b/tests/testthat/_snaps/r.md index dcb127a28..464dbb06f 100644 --- a/tests/testthat/_snaps/r.md +++ b/tests/testthat/_snaps/r.md @@ -50,5 +50,5 @@ compute_active_name("foo/bar.R") Condition Error: - ! Open file must be a code or test file. + ! Open file must be code, test, or snapshot. diff --git a/tests/testthat/test-r.R b/tests/testthat/test-r.R index b24bbaca3..003dfe9af 100644 --- a/tests/testthat/test-r.R +++ b/tests/testthat/test-r.R @@ -60,6 +60,10 @@ test_that("compute_active_name() standardises name", { "bar.R" ) + expect_equal( + compute_active_name(path(dir, "tests/testthat/_snaps/bar.md"), "R"), + "bar.R" + ) # https://github.com/r-lib/usethis/issues/1690 expect_equal( compute_active_name(path(dir, "R/data.frame.R"), "R"), From a45ef96210afeb5d179233e2bd4a5af91b092902 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 28 Jun 2024 17:34:50 -0500 Subject: [PATCH 06/22] Positron doesn't need restart for git pane (#2011) Co-authored-by: Jennifer (Jenny) Bryan --- NEWS.md | 2 ++ R/git.R | 2 +- R/positron.R | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 R/positron.R diff --git a/NEWS.md b/NEWS.md index 5ef77276c..a8444a635 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `use_git()` no longer asks if you want to restart RStudio when using Positron. + * `use_test()` and `use_r()` now work when you are in `tests/testthat/_snaps/{foo}.md` (@olivroy, #1988). * The URLs baked into the badge generated by `use_coverage(type = "codecov")` diff --git a/R/git.R b/R/git.R index 6596a6449..d4be332e0 100644 --- a/R/git.R +++ b/R/git.R @@ -22,7 +22,7 @@ use_git <- function(message = "Initial commit") { git_ask_commit(message, untracked = TRUE) } - if (needs_init) { + if (needs_init && !is_positron()) { restart_rstudio("A restart of RStudio is required to activate the Git pane.") } diff --git a/R/positron.R b/R/positron.R new file mode 100644 index 000000000..7bf221fd1 --- /dev/null +++ b/R/positron.R @@ -0,0 +1,3 @@ +is_positron <- function() { + Sys.getenv("POSITRON") == "1" +} From 2a8bf4b5eeb59d28077190d41fee1cf40aee013e Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 28 Jun 2024 15:43:24 -0700 Subject: [PATCH 07/22] Work on use_r() / use_test() docs --- R/r.R | 20 +++++++++++++++++--- man/use_r.Rd | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/R/r.R b/R/r.R index f6df25696..0d87ff688 100644 --- a/R/r.R +++ b/R/r.R @@ -4,8 +4,10 @@ #' using the convention that the tests for `R/foofy.R` should live #' in `tests/testthat/test-foofy.R`. You can use them to create new files #' from scratch by supplying `name`, or if you use RStudio, you can call -#' to create (or navigate to) the paired file based on the currently open -#' script. +#' to create (or navigate to) the companion file based on the currently open +#' file. This also works when a test snapshot file is active, i.e. if you're +#' looking at `tests/testthat/_snaps/foofy.md`, `use_r()` or `use_test()` take +#' you to `R/foofy.R` or `tests/testthat/test-foofy.R`, respectively. #' #' @section Renaming files in an existing package: #' @@ -45,6 +47,19 @@ #' [R code](https://r-pkgs.org/code.html) chapters of #' [R Packages](https://r-pkgs.org). #' @export +#' +#' @examples +#' \dontrun{ +#' # create a new .R file below R/ +#' use_r("coolstuff") +#' +#' # if `R/coolstuff.R` is active in a supported IDE, you can now do: +#' use_test() +#' +#' # if `tests/testthat/test-coolstuff.R` is active in a supported IDE, you can +#' # return to `R/coolstuff.R` with: +#' use_r() +#' } use_r <- function(name = NULL, open = rlang::is_interactive()) { use_directory("R") @@ -157,4 +172,3 @@ check_file_name <- function(name, call = caller_env()) { valid_file_name <- function(x) { grepl("^[a-zA-Z0-9._-]+$", x) } - diff --git a/man/use_r.Rd b/man/use_r.Rd index 81135c845..24f11959e 100644 --- a/man/use_r.Rd +++ b/man/use_r.Rd @@ -20,8 +20,10 @@ This pair of functions makes it easy to create paired R and test files, using the convention that the tests for \code{R/foofy.R} should live in \code{tests/testthat/test-foofy.R}. You can use them to create new files from scratch by supplying \code{name}, or if you use RStudio, you can call -to create (or navigate to) the paired file based on the currently open -script. +to create (or navigate to) the companion file based on the currently open +file. This also works when a test snapshot file is active, i.e. if you're +looking at \verb{tests/testthat/_snaps/foofy.md}, \code{use_r()} or \code{use_test()} take +you to \code{R/foofy.R} or \code{tests/testthat/test-foofy.R}, respectively. } \section{Renaming files in an existing package}{ @@ -55,6 +57,19 @@ bind_rows( The \code{\link[=rename_files]{rename_files()}} function can also be helpful. } +\examples{ +\dontrun{ +# create a new .R file below R/ +use_r("coolstuff") + +# if `R/coolstuff.R` is active in a supported IDE, you can now do: +use_test() + +# if `tests/testthat/test-coolstuff.R` is active in a supported IDE, you can +# return to `R/coolstuff.R` with: +use_r() +} +} \seealso{ The \href{https://r-pkgs.org/testing-basics.html}{testing} and \href{https://r-pkgs.org/code.html}{R code} chapters of From f102c479e1e22a88f09f0077131d73e1f0a4f148 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 28 Jun 2024 16:49:55 -0700 Subject: [PATCH 08/22] Put a few more guard rails around some git operations Related to https://github.com/r-lib/usethis/pull/2011#issue-2380380721 and https://github.com/posit-dev/positron/issues/2697 --- R/git.R | 7 +++++++ R/rstudio.R | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/R/git.R b/R/git.R index d4be332e0..b821b2a80 100644 --- a/R/git.R +++ b/R/git.R @@ -15,6 +15,13 @@ use_git <- function(message = "Initial commit") { if (needs_init) { ui_bullets(c("v" = "Initialising Git repo.")) git_init() + # hacky but helps prevent a pop-up in Positron, where early attempts to + # interact with a newly created repo lead to: + # Git: There are no available repositories + # https://github.com/r-lib/usethis/pull/2011#issue-2380380721 + if (is_positron()) { + Sys.sleep(1) + } } use_git_ignore(git_ignore_lines) diff --git a/R/rstudio.R b/R/rstudio.R index 10f43c910..551e93cf1 100644 --- a/R/rstudio.R +++ b/R/rstudio.R @@ -182,7 +182,7 @@ restart_rstudio <- function(message = NULL) { } rstudio_git_tickle <- function() { - if (rstudioapi::hasFun("executeCommand")) { + if (uses_git() && rstudioapi::hasFun("executeCommand")) { rstudioapi::executeCommand("vcsRefresh") } invisible() From 73b4e97b4f76d8c9b4b11761eb8e32a86bb2ceca Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Mon, 1 Jul 2024 10:17:58 -0700 Subject: [PATCH 09/22] Add missing backticks to end this YAML chunk --- R/use_standalone.R | 1 + man/use_standalone.Rd | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/R/use_standalone.R b/R/use_standalone.R index 73e845ae5..cae24075b 100644 --- a/R/use_standalone.R +++ b/R/use_standalone.R @@ -24,6 +24,7 @@ #' dependencies: standalone-obj-type.R #' imports: rlang (>= 1.1.0) #' --- +#' ``` #' #' Two of these fields are consulted by `use_standalone()`: #' diff --git a/man/use_standalone.Rd b/man/use_standalone.Rd index 54ee6090e..db56e40f5 100644 --- a/man/use_standalone.Rd +++ b/man/use_standalone.Rd @@ -57,26 +57,22 @@ license: https://unlicense.org dependencies: standalone-obj-type.R imports: rlang (>= 1.1.0) --- +}\if{html}{\out{}} -Two of these fields are consulted by `use_standalone()`: - -- `dependencies`: A file or a list of files in the same repo that - the standalone file depends on. These files are retrieved - automatically by `use_standalone()`. - -- `imports`: A package or list of packages that the standalone file - depends on. A minimal version may be specified in parentheses, - e.g. `rlang (>= 1.0.0)`. These dependencies are passed to - [use_package()] to ensure they are included in the `Imports:` - field of the `DESCRIPTION` file. +Two of these fields are consulted by \code{use_standalone()}: +\itemize{ +\item \code{dependencies}: A file or a list of files in the same repo that +the standalone file depends on. These files are retrieved +automatically by \code{use_standalone()}. +\item \code{imports}: A package or list of packages that the standalone file +depends on. A minimal version may be specified in parentheses, +e.g. \verb{rlang (>= 1.0.0)}. These dependencies are passed to +\code{\link[=use_package]{use_package()}} to ensure they are included in the \verb{Imports:} +field of the \code{DESCRIPTION} file. +} Note that lists are specified with standard YAML syntax, using -square brackets, for example: `imports: [rlang (>= 1.0.0), purrr]`. - - -[use_package()]: R:use_package() -[rlang (>= 1.0.0), purrr]: R:rlang\%20(\%3E=\%201.0.0),\%20purrr -}\if{html}{\out{}} +square brackets, for example: \verb{imports: [rlang (>= 1.0.0), purrr]}. } \examples{ From 83283d7cf108d4e1e1077cc16189ef091f299f8c Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:11:04 -0400 Subject: [PATCH 10/22] Avoid mentioning a specific site in release issue (#2017) * Avoid "tweet" * Update snapshots --- R/release.R | 2 +- tests/testthat/_snaps/release.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/release.R b/R/release.R index 02a122594..f43675fea 100644 --- a/R/release.R +++ b/R/release.R @@ -140,7 +140,7 @@ release_checklist <- function(version, on_cran) { todo("`usethis::use_github_release()`"), todo("`usethis::use_dev_version(push = TRUE)`"), todo("`usethis::use_news_md()`", !has_news), - todo("Tweet", type != "patch") + todo("Share on social media", type != "patch") ) } diff --git a/tests/testthat/_snaps/release.md b/tests/testthat/_snaps/release.md index e526f3d0b..97a62bea8 100644 --- a/tests/testthat/_snaps/release.md +++ b/tests/testthat/_snaps/release.md @@ -38,7 +38,7 @@ * [ ] `usethis::use_github_release()` * [ ] `usethis::use_dev_version(push = TRUE)` * [ ] `usethis::use_news_md()` - * [ ] Tweet + * [ ] Share on social media --- @@ -106,7 +106,7 @@ * [ ] `usethis::use_github_release()` * [ ] `usethis::use_dev_version(push = TRUE)` * [ ] `usethis::use_news_md()` - * [ ] Tweet + * [ ] Share on social media # construct correct revdep bullet @@ -162,5 +162,5 @@ * [ ] `usethis::use_github_release()` * [ ] `usethis::use_dev_version(push = TRUE)` * [ ] `usethis::use_news_md()` - * [ ] Tweet + * [ ] Share on social media From ae2e7449196e96138d22eac57ca5717bef7050fe Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Tue, 23 Jul 2024 12:01:27 -0700 Subject: [PATCH 11/22] `use_github()` - allow repo creation when repo is a redirect (#1894) * Allow repo creation when repo is a redirect * Check name of repo against provided spec, if they are different assume it's a redirect and allow repo creation. * Tweaks from playing with this locally --------- Co-authored-by: Jenny Bryan --- R/github.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/R/github.R b/R/github.R index f1f2a615c..b28336766 100644 --- a/R/github.R +++ b/R/github.R @@ -269,21 +269,23 @@ check_no_origin <- function() { } check_no_github_repo <- function(owner, repo, host) { + spec <- glue("{owner}/{repo}") repo_found <- tryCatch( { - repo_info <- gh::gh( - "/repos/{owner}/{repo}", - owner = owner, repo = repo, - .api_url = host - ) - TRUE + repo_info <- gh::gh("/repos/{spec}", spec = spec, .api_url = host) + # when does repo_info$full_name != the spec we sent? + # this happens if you reuse the original name of a repo that has since + # been renamed + # there's no 404, because of the automatic redirect, but you CAN create + # a new repo with this name + # https://github.com/r-lib/usethis/issues/1893 + repo_info$full_name == spec }, "http_error_404" = function(err) FALSE ) if (!repo_found) { return(invisible()) } - spec <- glue("{owner}/{repo}") empirical_host <- parse_github_remotes(repo_info$html_url)$host ui_abort("Repo {.val {spec}} already exists on {.val {empirical_host}}.") } From 9a4a026c54df5b679ea50ef3e9918e42e25f6b25 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 23 Jul 2024 12:05:22 -0700 Subject: [PATCH 12/22] Add NEWS bullet --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index a8444a635..ef784818c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # usethis (development version) +* `use_github()` now knows that you can reuse the name of an earlier repo that + has since been renamed (@ateucher, #1893). + * `use_git()` no longer asks if you want to restart RStudio when using Positron. * `use_test()` and `use_r()` now work when you are in `tests/testthat/_snaps/{foo}.md` (@olivroy, #1988). From cee770e52342aff162f6d1bdb0eaad8e0ec76795 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 23 Jul 2024 12:05:55 -0700 Subject: [PATCH 13/22] Whitespace changes --- NEWS.md | 366 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 183 insertions(+), 183 deletions(-) diff --git a/NEWS.md b/NEWS.md index ef784818c..5ef8375e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,7 +19,7 @@ superior option. There is a cli vignette about how to make this transition: `vignette("usethis-ui", package = "cli")`. - + usethis no longer uses the `ui_*()` functions internally, in favor of new cli-based helpers that are not exported. @@ -41,7 +41,7 @@ * Internal helper `cran_version()`, used in functions such as `use_release_checklist()` and `use_news_md()`, is more resilient to situations where no CRAN mirror has been set (#1857). - + * Internal usage of `numeric_version()` now always provides character input, rather than relying on implicit `as.character()` coercion. This is in response to a request from CRAN to anticipate future solutions to @@ -56,53 +56,53 @@ * `use_rstudio_preferences()` lets you set RStudio preferences programmatically (#1518) - -* `use_standalone()` is a new function that makes it easier to use standalone + +* `use_standalone()` is a new function that makes it easier to use standalone files provided by various low-level tidyverse packages, like rlang (#1654). - -* `use_upkeep_issue()` is a new function to facilitate regular maintenance of - your package. Similar to `use_release_issue()`, it opens an issue in your repo - with a checklist of maintenance tasks. It will include additional bullets - if your package includes an `upkeep_bullets()` function that returns a + +* `use_upkeep_issue()` is a new function to facilitate regular maintenance of + your package. Similar to `use_release_issue()`, it opens an issue in your repo + with a checklist of maintenance tasks. It will include additional bullets + if your package includes an `upkeep_bullets()` function that returns a character vector (#1794). ## Package development -* Although nested projects are discouraged, they can be useful in development - contexts. `create_package()` now sets the correct package name and returns +* Although nested projects are discouraged, they can be useful in development + contexts. `create_package()` now sets the correct package name and returns the correct package path for a package nested inside a project (#1647). * `use_article()` no longer adds the rmarkdown package to `Suggests`. Instead, if rmarkdown is not already a dependency, it's added to `Config/Needs/website`. This means that a package that only uses articles (vs. vignettes) won't gain an unnecessary dependency on rmarkdown (#1700). - -* `use_data()` now sets the appropriate minimal R version in `DESCRIPTION`, + +* `use_data()` now sets the appropriate minimal R version in `DESCRIPTION`, depending on which serialization format `version` you choose (@dpprdan, #1672). - + * `use_github_links()` by default now appends the GitHub url to existing urls in in the `URL` field of DESCRIPTION, rather than replacing existing urls (#1805). * `use_latest_dependencies()` no longer affects `Suggests` since those dependencies are not enforced (#1749). - + * `use_news_md()` now places "(development version)" in the header of `NEWS.md` - if there is a development version number in `DESCRIPTION`. It also sets the + if there is a development version number in `DESCRIPTION`. It also sets the first bullet to "Initial CRAN submission" when it looks like a "new" package (#1708). - + * `use_coverage()` no longer adds covr to `Suggests`, since the `test-coverage` GitHub Actions workflow takes care of installing covr (@Bisaloo, #1851). ## Package release -* `use_release_issue()` will now remind you to run `use_github_links()` if +* `use_release_issue()` will now remind you to run `use_github_links()` if necessary (@Bisaloo, #1754) * `use_release_issue()` now encourages the creation of `NEWS.md` prior to submission, instead of after (#1755). - -* `use_github_release()` now automatically pushes to GitHub (if safe) and + +* `use_github_release()` now automatically pushes to GitHub (if safe) and automatically publishes the release, rather than requiring you to edit and publish the draft (#1385). @@ -110,11 +110,11 @@ * `use_release_issue()` will now remind you to check/close the milestone corresponding to the release, if it exists (#1642). - + * `use_version()` and `use_dev_version()` gain a `push` argument to optionally push the result after committing. This is used to eliminate a manual step from the `use_release_issue()` checklist (#1385). - + * `use_revdep()` no longer places an email template, because these days we are more likely to communicate with other maintainers about breaking changes via GitHub issues and pull requests (#1769). @@ -123,7 +123,7 @@ * `rename_files()` now also affects files in `src/` (#1585). -* `use_r()` and `use_test()` now work with all active files in `R/`, `src/`, +* `use_r()` and `use_test()` now work with all active files in `R/`, `src/`, and `tests/testthat/` (#1566). * `use_r()` and `use_test()` now work with files containing `.` (#1690). @@ -138,16 +138,16 @@ anywhere in the repo, not just the root directory. This is useful if you're working with repos that contain tools for multiple languages (#1680). -* `git_sitrep()` gains two arguments: `tool` and `scope`, which enables +* `git_sitrep()` gains two arguments: `tool` and `scope`, which enables you to limit the report to, for example, `tool = "git"` or `scope = "user"`. The default remains to provide a full report. Also, provides more feedback if git user's information is not set, and checks global git-email against user-level GitHub PAT (@ijlyttle, #1732, #1714, #1706). - -* `git_vaccinated()` now treats a path configured as `core.excludesFile` like - other user-supplied paths; in particular, any use of the `~/` home directory - shortcut is expanded via - [`fs::path_expand()`](https://fs.r-lib.org/reference/path_expand.html) + +* `git_vaccinated()` now treats a path configured as `core.excludesFile` like + other user-supplied paths; in particular, any use of the `~/` home directory + shortcut is expanded via + [`fs::path_expand()`](https://fs.r-lib.org/reference/path_expand.html) (@dpprdan, #1560). * `use_github_action()` now suggests possible actions when called without @@ -162,26 +162,26 @@ * Links to the R Packages book have been updated to the second edition of the book (#1689). - -* The SVG badges placed by `use_lifecycle()` have improved accessibility - features, i.e. they advertise the lifecycle stage via the `aria-label` + +* The SVG badges placed by `use_lifecycle()` have improved accessibility + features, i.e. they advertise the lifecycle stage via the `aria-label` attribute (#1554, https://github.com/r-lib/lifecycle/issues/117). - -* `use_rscloud_badge()` has been deprecated in favour of - `use_posit_cloud_badge()`, and both functions now accept the updated url + +* `use_rscloud_badge()` has been deprecated in favour of + `use_posit_cloud_badge()`, and both functions now accept the updated url format of Posit Cloud projects (#1670). -* `use_rstudio()` gains a `reformat` argument which omits `.Rproj` settings - that enforce file formatting conventions, e.g. around whitespace. - `create_from_github()` uses this option when it introduces an `.Rproj` to a - project that lacks one, making it easier to follow the project's existing +* `use_rstudio()` gains a `reformat` argument which omits `.Rproj` settings + that enforce file formatting conventions, e.g. around whitespace. + `create_from_github()` uses this option when it introduces an `.Rproj` to a + project that lacks one, making it easier to follow the project's existing conventions (#1679). * `write_over()` and `use_github_file()` gain an overwrite argument (#1748). - + ## Tidyverse-related -* `use_release_issue()` now uses internal `release_extra_revdeps()` to +* `use_release_issue()` now uses internal `release_extra_revdeps()` to add extra revdep sources. Currently only use for internal Posit tooling, but we hope to extend to all users in the future (#1610). @@ -195,68 +195,68 @@ evaluation (#1656). * `use_travis()`, `use_pkgdown_travis()`, `browse_travis()`, and `use_appveyor()` - are now defunct because we no longer recommend Travis or Appveyor. We + are now defunct because we no longer recommend Travis or Appveyor. We recommend GitHub actions instead (#1517). # usethis 2.1.6 ### GitHub-related -* `use_github_action()` and friends gain a `ref` argument, which defaults to +* `use_github_action()` and friends gain a `ref` argument, which defaults to the tag of the latest release in (#1541). -* `use_github_actions_badge()` now uses the same URLs as GitHub does via the - "Create status badge" helper in the browser (#1525). This changes the - significance of the `name` argument; now it really must be the name of the +* `use_github_actions_badge()` now uses the same URLs as GitHub does via the + "Create status badge" helper in the browser (#1525). This changes the + significance of the `name` argument; now it really must be the name of the workflow configuration file. -* All functions error more clearly when the requested operation is not +* All functions error more clearly when the requested operation is not supported for the "theirs" remote configuration (#1588). ### Other changes * `use_roxygen_md()` gains an `overwrite` argument (#1599). -* `use_rscloud_badge()` is a new function that creates a README badge - indicating the repository can be launched in an +* `use_rscloud_badge()` is a new function that creates a README badge + indicating the repository can be launched in an [RStudio Cloud](https://rstudio.cloud) project (@gvelasq, #1584). * `use_data()` gains an `ascii` argument, which is passed along to `save()` (@JosiahParry, #1625). -* `use_code_of_conduct()` has been updated to version 2.1 of the Contributor +* `use_code_of_conduct()` has been updated to version 2.1 of the Contributor Covenant (@batpigandme, #1591). # usethis 2.1.5 -* pkgdown-related functions no longer automatically strip a trailing slash from - the pkgdown site URL, in order to play more nicely with CRAN's URL checks +* pkgdown-related functions no longer automatically strip a trailing slash from + the pkgdown site URL, in order to play more nicely with CRAN's URL checks (#1526). -* `edit_pkgdown_config()` is a new function that opens the pkgdown YAML +* `edit_pkgdown_config()` is a new function that opens the pkgdown YAML configuration file for the current Project, if such a file exists. -* The error thrown when reporting an unsupported GitHub configuration has been +* The error thrown when reporting an unsupported GitHub configuration has been fixed for forward compatibility with a future version of rlang, i.e. what is anticipated to be rlang v1.0.0. -* Version 2.1.4 was never released. Version was advanced from 2.1.4 to 2.1.5 +* Version 2.1.4 was never released. Version was advanced from 2.1.4 to 2.1.5 strictly for CRAN (re-)submission purposes. # usethis 2.1.3 -* Modified a test to ensure that intermittent GitHub rate limiting does not - lead to ungraceful failure on CRAN. +* Modified a test to ensure that intermittent GitHub rate limiting does not + lead to ungraceful failure on CRAN. # usethis 2.1.2 -* `git_default_branch_rename()` no longer errors on repos where README exists, +* `git_default_branch_rename()` no longer errors on repos where README exists, but has no badge block. -* `git_default_branch_rediscover()` prunes the defunct remote ref to the old +* `git_default_branch_rediscover()` prunes the defunct remote ref to the old default branch, e.g. `origin/master`. -* Version 2.1.1 was never released. Version was advanced from 2.1.1 to 2.1.2 +* Version 2.1.1 was never released. Version was advanced from 2.1.1 to 2.1.2 strictly for CRAN (re-)submission purposes. # usethis 2.1.0 @@ -300,20 +300,20 @@ usethis has a more sophisticated understanding of the default branch and gains s arbitrary file on GitHub that the user has permission to read. It supports targeting a specific branch, tag, or commit and can follow a symlink (#1407). `use_github_file()` now powers `use_github_action()` and friends. - + * `use_github_release()` is much more diligent about using any information left behind by `devtools::submit_cran()` or `devtools::release()`. Specifically, this applies to determining which SHA is to be tagged in the release. And this SHA, in turn, determines the consulted versions of DESCRIPTION (for package version) and NEWS.md (for release notes) (#1380). -* `use_release_issue()` also takes bullets from `release_questions()`, +* `use_release_issue()` also takes bullets from `release_questions()`, for compatibility with `devtools::release()`. * `git_vaccinate()`, `edit_git_ignore()`, and `git_sitrep()` are more careful to consult, reveal, and set the `core.excludesFile` setting in user's Git configuration (#1461). - + * `use_github_action_check_full()` has been removed. It's overkill for the majority of R packages, which are better off with `use_github_actions()` or `use_github_action_check_standard()` (#1490). @@ -322,7 +322,7 @@ usethis has a more sophisticated understanding of the default branch and gains s creating an empty, orphan `gh-pages` branch. This is necessary due to new GitHub behaviour, where it has become essentially impossible to refer to the empty tree (#1472). - + * `use_github()` can create repositories with `"internal"` visibility, a feature that exists within GitHub Enterprise products (#1505). @@ -336,7 +336,7 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_import_from()` is a new function that puts `@importFrom pkg fun` directives into a package in a consistent location (@malcolmbarrett, #1377). -* `DESCRIPTION` files generated by usethis no longer include `LazyData` by +* `DESCRIPTION` files generated by usethis no longer include `LazyData` by default, as per new CRAN checks; instead, `LazyData` is now added the first time you use `use_data()` (@malcolmbarrett, #1404). @@ -351,9 +351,9 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_code_of_conduct()` now requires a `contact` argument to supply contact details for reporting CoC violations (#1269). -* `use_package()` no longer guides the user on how to use a dependency when no +* `use_package()` no longer guides the user on how to use a dependency when no change was made (@malcolmbarrett, #1384). - + ### Aimed at the tidyverse team These functions are exported for anyone to use, but are aimed primarily at the maintainers of tidyverse, r-lib, and tidymodels packages. @@ -361,7 +361,7 @@ These functions are exported for anyone to use, but are aimed primarily at the m * `use_tidy_dependencies()` is a new function that sets up standard dependencies used by all tidyverse packages, except those that are designed to be dependency free (#1423). - + * `use_tidy_upkeep_issue()` is a new function similar to `use_release_issue()` that creates a checklist-style issue to prompt various updates (#1416). @@ -381,11 +381,11 @@ These functions are exported for anyone to use, but are aimed primarily at the m a Git repo. The normal Git workflow makes it easy to see and selectively accept/discard any proposed changes. This behaviour is strictly opt-in (#1424). - + * Functions that provide code to load packages in your `.Rprofile` now use `rlang::check_installed()` to make sure the package is installed locally (@malcolmbarrett, #1398). - + * `edit_rstudio_prefs()` and `edit_rstudio_snippets()` should work now on case-sensitive OSes, due to a path fix re: the location of RStudio's config files (@charliejhadley, #1420). @@ -394,24 +394,24 @@ These functions are exported for anyone to use, but are aimed primarily at the m * All functions that require a package now ask you if you'd like to install it. -* Added `edit_template()` for opening and creating files in `inst/templates` +* Added `edit_template()` for opening and creating files in `inst/templates` (for use with `use_template()`) (@malcolmbarrett, #1319). * `use_article()` now creates the file in the `vignettes/articles/` (#548). -* `use_lifecycle()` has been updated for changes in our lifecycle workflow +* `use_lifecycle()` has been updated for changes in our lifecycle workflow (#1323). * `use_tidy_pkgdown()` has been renamed to `use_pkgdown_github_pages()` since the function is useful for anyone who wants to automatically publish to GitHub pages, not just the tidyverse team (#1308). -* `use_release_issue()` includes a bunch of minor improvements. Most +* `use_release_issue()` includes a bunch of minor improvements. Most importantly, for initial CRAN release we now include a number of common things that CRAN checks for that aren't in `R CMD check`. -* `use_readme_rmd()`, `use_readme_md()`, `use_tidy_contributing()`, and - `use_tidy_support()` use updated logic for determining the `OWNER/REPO` spec +* `use_readme_rmd()`, `use_readme_md()`, `use_tidy_contributing()`, and + `use_tidy_support()` use updated logic for determining the `OWNER/REPO` spec of the target repo (#1312). # usethis 2.0.0 @@ -424,7 +424,7 @@ Usethis has various functions that help with Git-related tasks, which break down command line Git. 1. GitHub tasks, such as fork, release, and open an issue or pull request. These are things you could do in the browser or with the GitHub API. - + We've switched from git2r to the gert package for Git operations (). We continue to use the gh package for GitHub API work (). The big news in this area is that these lower-level dependencies are getting better at finding Git credentials, finding the same credentials as command line Git (and, therefore, the same as RStudio), and finding the same credentials as each other. This allows usethis to shed some of the workarounds we have needed in the past, to serve as a remedial "credential valet". @@ -436,7 +436,7 @@ Under the hood, both gert and gh are now consulting your local Git credential st Even now, gert and gh should discover the same credentials, at least for github.com. In the future, these two packages may merge into one. -Git/GitHub credential management is covered in a new article: +Git/GitHub credential management is covered in a new article: [Managing Git(Hub) Credentials](https://usethis.r-lib.org/articles/articles/git-credentials.html) The main user-facing changes in usethis are: @@ -455,7 +455,7 @@ As a result, several functions are deprecated and several other functions have s - `use_github()` (`auth_token`, `credentials`) - `use_github_links()` (`host`, `auth_token`) - `use_github_labels()` (`repo_spec`, `host`, `auth_token`) - - `use_tidy_labels()` (`repo_spec`, `host`, `auth_token`) + - `use_tidy_labels()` (`repo_spec`, `host`, `auth_token`) - `use_github_release()` (`host`, `auth_token`) The switch to gert + credentials should eliminate most credential-finding fiascos. Gert also takes a different approach to wrapping libgit2, the underlying C library that does Git operations. The result is more consistent support for SSH and TLS, across all operating systems, without requiring special effort at install time. More users should enjoy Git remote operations that "just work", for both SSH and HTTPS remotes. There should be fewer "unsupported protocol" errors. @@ -467,7 +467,7 @@ Usethis gains a more formal framework for characterizing a GitHub remote configu * Which GitHub repositories `origin` and `upstream` point to * Whether you can push to them * How they relate to each other, e.g. fork-parent relationship - + This is an internal matter, but users will notice that usethis is more clear about which configurations are supported by various functions and which are not. The most common configurations are reviewed in a [section of Happy Git](https://happygitwithr.com/common-remote-setups.html). When working in a fork, there is sometimes a question whether to target the fork or its parent repository. For example, `use_github_links()` adds GitHub links to the URL and BugReports fields of DESCRIPTION. If someone calls `use_github_links()` when working in a fork, they probably want those links to refer to the *parent* or *source* repo, not to their fork, because the user is probably preparing a pull request. Usethis should now have better default behaviour in these situations and, in some cases, will present an interactive choice. @@ -520,17 +520,17 @@ GitHub Actions is the preferred platform for continuous integration, because tha All `use_*_license()` functions now work for projects, not just packages. `use_apl2_license()` (not `use_apache_license()`) and `use_gpl3_license()` no longer modify the license text (#1198). - + `use_mit_license()` now sets the default copyright holder to "{package} authors". This makes it more clear that the copyright holders are the contributors to the package; unless you are using a CLA there is no one copyright holder of a package (#1207). - + New `use_gpl_license()` and `use_agpl_license()` make it easier to pick specific versions of the GPL and AGPL licenses, and to choose whether or not you include future versions of the license. Both default to version 3 (and above). New `use_proprietary_license()` allows your package to pass R CMD check while making it clear that your code is not open source (#1163). Thanks to @atheriel for the blog post suggesting the wording: https://unconj.ca/blog/copyright-in-closed-source-r-packages-the-right-way.html `use_lgpl_license()` now uses version 3 (and above), and gains new `version` and `include_future` argument to control which version is used. - + `use_gpl3_license()`, `use_agpl3_license()` and `use_apl2_license()` have been deprecated in favour of the new `version` argument to `use_gpl_license()`, `use_agpl_license()` and `use_apache_license()`. - + The `name` argument to `use_mit_license()` has been changed to `copyright_holder` to make the purpose more clear. The `name` argument has been removed from all other license functions because it is not needed; no other license makes an assertion about who the copyright holder is. ## RStudio preferences @@ -557,13 +557,13 @@ The legacy `"devtools.desc"` option is no longer consulted when populating a new `create_package()`, `create_project()`, `create_from_github()`, and `proj_activate()` work better with relative paths, inside and outside of RStudio (#1122, #954). -`use_testthat()` gains an edition argument to support testthat v3.0.0 +`use_testthat()` gains an edition argument to support testthat v3.0.0 (#1185) `use_version()` now updates `src/version.c` if it exists and contains a line matching `PKG_version = "x.y.z";`. -usethis has been re-licensed as MIT (#1252, #1253). - +usethis has been re-licensed as MIT (#1252, #1253). + ## Dependency changes New Imports: gert, jsonlite (was already an indirect dependency), lifecycle, rappdirs @@ -586,14 +586,14 @@ Patch release to align some path handling internals with an update coming in the destination directory to the config file if it departs from the default (which is `docs/`). -* `use_tidy_ci()` is now deprecated in favour of `use_tidy_github_actions()` +* `use_tidy_ci()` is now deprecated in favour of `use_tidy_github_actions()` (#1098). * `use_github_action_check_standard()` is a new intermediate workflow that checks on more platforms than `_release`, but is less exhaustive than `_full` (@jimhester). -* `create_tidy_package()` now uses an MIT license (@topepo, #1096). +* `create_tidy_package()` now uses an MIT license (@topepo, #1096). # usethis 1.6.0 @@ -611,55 +611,55 @@ Patch release to align some path handling internals with an update coming in the ## Package creation -* `create_package()` gains a `roxygen` argument. If `TRUE` (the default), +* `create_package()` gains a `roxygen` argument. If `TRUE` (the default), it adds a `RoxygenNote` field to the `DESCRIPTION` (which means the first run - of `devtools::check()` will re-document the package, #963), and creates an - empty `NAMESPACE` (which means you'll always need an explicit `@export` - if you want to export functions, #927). It also turns markdown processing + of `devtools::check()` will re-document the package, #963), and creates an + empty `NAMESPACE` (which means you'll always need an explicit `@export` + if you want to export functions, #927). It also turns markdown processing on by default (#911). * `use_rstudio()` now sets the `LineEndingConversion` to `Posix` so that - packages created using usethis always use LF line endings, regardless of + packages created using usethis always use LF line endings, regardless of who contributes to them (#1002). -* In the `usethis.description` option, you can now set `Authors@R = person()` - directly, without having to wrap in additional layer of quotes. If setting - this in your `.Rprofile`, you'll need to use `utils::person()` since the utils +* In the `usethis.description` option, you can now set `Authors@R = person()` + directly, without having to wrap in additional layer of quotes. If setting + this in your `.Rprofile`, you'll need to use `utils::person()` since the utils package isn't loaded until after your profile is executed. ## PR helpers -* A new article [Pull request helpers](https://usethis.r-lib.org/articles/articles/pr-functions.html) +* A new article [Pull request helpers](https://usethis.r-lib.org/articles/articles/pr-functions.html) demonstrates how to use the `pr_*()` functions (@mine-cetinkaya-rundel, #802). -* `pr_finish()` checks that you don't have any local changes (#805), and can +* `pr_finish()` checks that you don't have any local changes (#805), and can optionally finish any PR, not just the current (#1040). -* `pr_pause()` and `pr_fetch()` now automatically pull to get latest changes +* `pr_pause()` and `pr_fetch()` now automatically pull to get latest changes (#959, #960) and refresh RStudio's git pane (#706). -* `pr_push()` now works for a repository with no open pull requests +* `pr_push()` now works for a repository with no open pull requests (@maurolepore, #990). -* `pr_pull()` gives more information about which files have merge conflicts +* `pr_pull()` gives more information about which files have merge conflicts and automatically opens conflicted files for editing (#1056). ## Other new features -* New `rename_files()` makes it easy to rename paired `R/` and `test/` files +* New `rename_files()` makes it easy to rename paired `R/` and `test/` files (#784). * New `ui_silence()` makes it easier to selectively silence some UI output. * New `use_agpl3_license()` (@pachamaltese, #870). -* New `use_data_table()` to set up a package for Import-ing `data.table` +* New `use_data_table()` to set up a package for Import-ing `data.table` (@michaelchirico, #897). * `use_latest_dependencies()` replaces `use_tidy_version()` as the new name better reflect its usage (#771). -* New `use_lifecycle()` helper to import the lifecycle badges for functions and +* New `use_lifecycle()` helper to import the lifecycle badges for functions and arguments in your package. Learn more at . * `use_release_issue()` will include additional bullets if your package @@ -668,20 +668,20 @@ Patch release to align some path handling internals with an update coming in the ## Minor improvements and bug fixes -* When writing files, usethis now respects line endings. Default line endings +* When writing files, usethis now respects line endings. Default line endings are taken from the `.Rproj` file (if available), otherwise the `DESCRIPTION`, - otherwise the first file found in `R/`, then all else failing to your - platform default (#767). It should do a better job of preserving UTF-8 files + otherwise the first file found in `R/`, then all else failing to your + platform default (#767). It should do a better job of preserving UTF-8 files on windows (#969). -* `browse_github()` now always goes to the canonical GitHub site: - `https://github.com/user/repo`. This is slightly worse than the current - behaviour but makes the function more consistent across packages, and +* `browse_github()` now always goes to the canonical GitHub site: + `https://github.com/user/repo`. This is slightly worse than the current + behaviour but makes the function more consistent across packages, and considerably simplifies the implementation. * `browse_circle()` opens the project dashboard on Circle CI. -* `create_download_url()` is a new helper for making "ZIP file download" +* `create_download_url()` is a new helper for making "ZIP file download" URLs suitable for use with `use_course()` and `use_zip()`, starting with the URLs that mere mortals can usually get their hands on in a browser (@fmichonneau, #406). @@ -689,19 +689,19 @@ Patch release to align some path handling internals with an update coming in the * `create_package()` no longer fails partway through if you have a malformed `usethis.description` option (#961). -* `create_package()` will now create a package in a symlink to a directory +* `create_package()` will now create a package in a symlink to a directory (#794). -* `create_package()` and `use_description()` gain a `check_name` argument to +* `create_package()` and `use_description()` gain a `check_name` argument to control whether to check for package names invalid for CRAN (@noamross, #883). * `edit_file()` and `use_test()` gain an `open` parameter that allows you to control whether or not the function is opened for editing by the user (#817). -* `edit_rstudio_snippets()` makes it more clear which snippet types are +* `edit_rstudio_snippets()` makes it more clear which snippet types are allowed and that user's snippets mask the built-in snippets (@GegznaV, #885). -* `git_sitrep()` now reports project-specific user name and email, if set +* `git_sitrep()` now reports project-specific user name and email, if set (#837), and email(s) associated with your GitHub account (@dragosmg, #724). * `ui_yeah()` and `ui_nope()` allow you to override the default "yes" and @@ -711,16 +711,16 @@ Patch release to align some path handling internals with an update coming in the * `use_circleci_badge()` is now exported (@pat-s, #920). -* `use_code_of_conduct()` now generates an absolute link to code of conduct on +* `use_code_of_conduct()` now generates an absolute link to code of conduct on pkgdown website or original source to avoid R CMD check issues (#772). - + * `use_course()` and `use_zip()` are now equipped with some retry capability, to cope with intermittent failure or the need for a longer connect timeout (#988). * `use_data()` automatically bumps R dependency to 2.10 (#962). -* `use_data_raw()` template quotes the dataset name correctly +* `use_data_raw()` template quotes the dataset name correctly (#736, @mitchelloharawild). * `use_description_defaults()` now shows the default fields combined with @@ -733,14 +733,14 @@ Patch release to align some path handling internals with an update coming in the * `use_github_release()` no longer fails if you have no news bullets (#1048). -* `use_github_release()` now tags the latest local commit instead of the latest +* `use_github_release()` now tags the latest local commit instead of the latest remote commit on the default branch (@davidchall, #1029). -* `use_gpl3_license()` now completes the license by providing additional - information in a file named LICENSE, just like `use_mit_license()` and +* `use_gpl3_license()` now completes the license by providing additional + information in a file named LICENSE, just like `use_mit_license()` and friends (@Cervangirard, #683). -* `use_logo()` now generates the correct href if the pkgdown `url` is set +* `use_logo()` now generates the correct href if the pkgdown `url` is set (@mitchelloharawild, #986). * `use_make()` gains missing closing parenthesis (@ryapric, #804). @@ -748,7 +748,7 @@ Patch release to align some path handling internals with an update coming in the * `use_markdown_template()` no longer uses an unexported function in its default arguments (@fmichonneau, #761). -* `use_testthat()` and `use_test()` now work in projects, not just packages +* `use_testthat()` and `use_test()` now work in projects, not just packages (#1017). * `use_test()` works on Windows when called without arguments (#901). @@ -756,18 +756,18 @@ Patch release to align some path handling internals with an update coming in the * `use_tidy_issue_template()` uses current github format (@Maschette, #756). * `use_travis()`, `use_travis_badge()`, and `browse_travis()`, now default - to `ext = "com"` since travis-ci.com is now recommended it over travis-ci.org + to `ext = "com"` since travis-ci.com is now recommended it over travis-ci.org (@riccardoporreca, #1038). * `use_release_issue()` reminds you to re-generate `README.md`, if needed (#767). -* `use_r()` and `use_test()` throw a clear error if multiple names are provided +* `use_r()` and `use_test()` throw a clear error if multiple names are provided (@strboul, #862). * `use_rcpp()` and `use_c()` now ensure `src/` contains at least one `.cpp` or `.c` placeholder file, so that the package can be built (@coatless, #720). - + * `usethis.destdir` is a new option that is consulted when deciding where to put a new folder created by `use_course()` or `create_from_github()` (@malcolmbarrett, #1015). @@ -802,7 +802,7 @@ This is a patch release with various small features and bug fixes. ## Git, GitHub, and pull requests -* `use_github()` removes newline `\n` characters from the description that +* `use_github()` removes newline `\n` characters from the description that can cause the initial push to fail (#493, @muschellij2). * `git_sitrep()` gives better feedback if we can't validate the GitHub PAT @@ -812,7 +812,7 @@ This is a patch release with various small features and bug fixes. `upstream/master`, when it creates (and clones) a fork (#792). * `pr_pause()` can switch back to master even if there is no remote tracking - branch (#715, @cderv). + branch (#715, @cderv). ## Build tools and continuous integration @@ -821,7 +821,7 @@ This is a patch release with various small features and bug fixes. * `use_make()` and `use_jenkins()` add a Makefile and Jenkinsfile, respectively (#501, @ryapric). - + * `use_circleci()` creates a `.circleci/config.yaml` config file for CircleCI (#703, @jdblischak). @@ -851,7 +851,7 @@ usethis gains several functions to inspect and manipulate the Git situation for into git2r's workings, especially around credentials (usethis uses git2r for all Git operations). -* `git_sitrep()` lets you know what's up with your Git, git2r and GitHub +* `git_sitrep()` lets you know what's up with your Git, git2r and GitHub config (#328). * `git_vaccinate()` vaccinates your global (i.e. user-level) git ignore file. @@ -861,7 +861,7 @@ Git operations). * `git_remotes()` and `use_git_remote()` are new helpers to inspect or modify Git remote URLs for the repo associated with the active project (#649). - + * `git_protocol()` + `use_git_protocol()` and `git_credentials()` + `use_git_credentials()` are new helpers to summon or set Git transport protocol (SSH or HTTPS) or git2r credentials, respectively. These functions @@ -874,10 +874,10 @@ Other improvements and bug fixes: * `use_github()` tries harder but also fails earlier, with more informative messages, making it less likely to leave the repo partially configured (#221). - + * `use_github()` and `create_from_github()` gain a `protocol` argument (#494, @cderv). - + * `create_from_github()` pulls from upstream master in a fork (#695, @ijlyttle). * `use_release_issue()` creates a GitHub issue containing a release checklist, @@ -895,8 +895,8 @@ Other improvements and bug fixes: * `use_github_labels()` has been rewritten be more flexible. You can now supply a repo name, and `descriptions`, and you can set colours/descriptions independently of creating labels. You can also `rename` existing labels - (#290). - + (#290). + ## GitHub pull requests We've added **experimental** functions to work with GitHub pull requests. They @@ -916,15 +916,15 @@ requests) and a contributor (who may make or explore pull requests). usethis gains tooling to manage part of a file. This is currently used for managing badges in your README and roxygen import tags: -* `use_badge()` and friends now automatically add badges if your README +* `use_badge()` and friends now automatically add badges if your README contains a specially formatted badge block (#497): ``` <-- badge:start --> <-- badge:end --> ``` - -* `use_tibble()` and `use_rcpp()` automatically add roxygen tags to + +* `use_tibble()` and `use_rcpp()` automatically add roxygen tags to to `{package}-package.R` if it contains a specially formatted namespace block (#517): @@ -933,19 +933,19 @@ managing badges in your README and roxygen import tags: ## usethis namespace: end NULL ``` - + Unfortunately this means that `use_rcpp()` no longer supports non-roxygen2 - workflows, but I suspect the set of people who use usethis and Rcpp but + workflows, but I suspect the set of people who use usethis and Rcpp but not roxygen2 is very small. ## Extending and wrapping usethis -* New `proj_activate()` lets you activate a project, either opening a new - RStudio session (if you use RStudio) or changing the working directory +* New `proj_activate()` lets you activate a project, either opening a new + RStudio session (if you use RStudio) or changing the working directory (#511). -* `proj_get()` and `proj_set()` no longer have a `quiet` argument. The - user-facing message about setting a project is now under the same control +* `proj_get()` and `proj_set()` no longer have a `quiet` argument. The + user-facing message about setting a project is now under the same control as other messages, i.e. `getOption("usethis.quiet", default = FALSE)` (#441). * A new set of `ui_*()` functions makes it possible to give your own code @@ -959,8 +959,8 @@ managing badges in your README and roxygen import tags: * questions: `ui_yeah()`, `ui_nope()`. * inline styles: `ui_field()`, `ui_value()`, `ui_path()`, `ui_code()`. -* `with_project()` and `local_project()` are new withr-style functions to - temporarily set an active usethis project. They make usethis functions easier +* `with_project()` and `local_project()` are new withr-style functions to + temporarily set an active usethis project. They make usethis functions easier to use in an *ad hoc* fashion or from another package (#441). ## Tidyverse standards @@ -968,8 +968,8 @@ managing badges in your README and roxygen import tags: These standards are (aspirationally) used by all tidyverse packages; you are welcome to use them if you find them helpful. -* Call `use_tidy_labels()` to update GitHub labels. Colours are less - saturated, docs is now documentation, we use some emoji, and performance is +* Call `use_tidy_labels()` to update GitHub labels. Colours are less + saturated, docs is now documentation, we use some emoji, and performance is no longer automatically added to all repos (#519). Repo specific issues should be given colour `#eeeeee` and have an emoji. @@ -980,21 +980,21 @@ welcome to use them if you find them helpful. pkgdown site if available (#536). * When creating a new package, use `create_tidy_package()` to start with a - package following the tidyverse standards (#461). + package following the tidyverse standards (#461). -* `NEWS.md` for the development version should use "(development version)" +* `NEWS.md` for the development version should use "(development version)" rather than the specific version (#440). * pkgdown sites should now be built by travis and deployed automatically to GitHub pages. `use_pkgdown_travis()` will help you set that up. -* When starting the release process, call `use_release_issue()` to create a +* When starting the release process, call `use_release_issue()` to create a release checklist issue (#338). -* Prior to CRAN submission call `use_tidy_release_test_env()` to update the +* Prior to CRAN submission call `use_tidy_release_test_env()` to update the test environment section in `cran-comments()` (#496). -* After acceptance, try `use_github_release()` to automatically create a +* After acceptance, try `use_github_release()` to automatically create a release. It's created as a draft so you have a chance to look over before publishing. @@ -1010,7 +1010,7 @@ welcome to use them if you find them helpful. * `use_partial_warnings()` helps the user add a standard warning block to `.Rprofile` (#64). -* `edit_r_buildignore()` opens `.Rbuildignore` for manual editing +* `edit_r_buildignore()` opens `.Rbuildignore` for manual editing (#462, @bfgray3). * `use_lgpl_license()` automates set up of the LGL license (#448, @krlmlr). @@ -1021,7 +1021,7 @@ welcome to use them if you find them helpful. RcppArmadillo or RcppEigen, respectively (#421, @coatless, @duckmayr). * `use_c("foo")` sets up `src/` and creates `src/foo.c` (#117). - + * `use_covr_ignore()` makes it easy to ignore files in test coverage (#434). * `use_pkgdown_travis()` helps you set up pkgdown for automatic build-and-deploy @@ -1037,7 +1037,7 @@ welcome to use them if you find them helpful. `.Rbuildignore`. These appear on pkgdown sites, but are not included with the package itself (#281). -* `use_citation()` creates a basic `CITATION` template and puts it in the +* `use_citation()` creates a basic `CITATION` template and puts it in the right place (#100). ## Other minor bug fixes and improvements @@ -1053,10 +1053,10 @@ welcome to use them if you find them helpful. * `use_data_raw()` accepts a name for the to-be-prepared dataset and opens a templated R script (#646). -* `browse_github()` now falls back to CRAN organisation (with a warning) if +* `browse_github()` now falls back to CRAN organisation (with a warning) if package doesn't have its own GitHub repo (#186). -* `create_*()` restore the active project if they error part way through, +* `create_*()` restore the active project if they error part way through, and use `proj_activate()` (#453, #511). * `edit_r_profile()` and `edit_r_environ()` now respect environment variables @@ -1069,14 +1069,14 @@ welcome to use them if you find them helpful. spread over multiple lines (#439). * `use_logo()` can override existing logo if user gives permission (#454). - It also produces retina appropriate logos by default, and matches the + It also produces retina appropriate logos by default, and matches the aspect ratio to the specification (#499). * `use_news_md()` will optionally commit. * `use_package()` gains a `min_version` argument to specify a minimum - version requirement (#498). Set to `TRUE` to use the currently installed - version (#386). This is used by `use_tidy_eval()` in order to require version + version requirement (#498). Set to `TRUE` to use the currently installed + version (#386). This is used by `use_tidy_eval()` in order to require version 0.1.2 or greater of rlang (#484). * `use_pkgdown()` is now configurable with site options (@jayhesselberth, #467), @@ -1084,12 +1084,12 @@ welcome to use them if you find them helpful. * `use_test()` no longer forces the filename to be lowercase (#613, @stufield). -* `use_test()` will not include a `context()` in the generated file if used +* `use_test()` will not include a `context()` in the generated file if used with testthat 2.1.0 and above (the future release of testthat) (#325). -* `use_tidy_description()` sets the `Encoding` field in `DESCRIPTION` +* `use_tidy_description()` sets the `Encoding` field in `DESCRIPTION` (#502, @krlmlr). - + * `use_tidy_eval()` re-exports `:=` (#595, @jonthegeek). * `use_tidy_versions()` has source argument so that you can choose to use @@ -1109,11 +1109,11 @@ welcome to use them if you find them helpful. in `NEWS.md` (#440). * `use_vignette()` now checks if the vignette name is valid (starts with letter - and consists of letters, numbers, hyphen, and underscore) and throws an error + and consists of letters, numbers, hyphen, and underscore) and throws an error if not (@akgold, #555). - + * `restart_rstudio()` now returns `FALSE` in RStudio if no project is open, - fixing an issue that caused errors in helpers that suggest restarting + fixing an issue that caused errors in helpers that suggest restarting RStudio (@gadenbuie, #571). ## Dependency changes @@ -1189,7 +1189,7 @@ No longer in Imports: backports, httr, rematch2, rmarkdown (moved to Suggests), * `use_github_labels()` can create or update the colour of arbitrary GitHub issue labels, defaulting to a set of labels and colours used by the tidyverse packages, which are now exposed via `tidy_labels()`. That set now includes the labels "good first issue" and "help wanted" (#168, #249). -* `appveyor_info()` no longer reverses the repo's URL and image link. Corrects the markdown produced by `use_appveyor_badge()` (#240, @llrs). +* `appveyor_info()` no longer reverses the repo's URL and image link. Corrects the markdown produced by `use_appveyor_badge()` (#240, @llrs). * `use_cran_badge()` uses an HTTPS URL for the CRAN badge image (#235, @jdblischak). @@ -1247,13 +1247,13 @@ templating functions using this framework (@ijlyttle #120). * `create_from_github()` creates a project from an existing GitHub repository, forking if needed (#109). -* `use_cc0_license()` applies a CC0 license, particularly appropriate for data +* `use_cc0_license()` applies a CC0 license, particularly appropriate for data packages (#94) -* `use_lifecycle_badge()` creates a badge describing current stage in +* `use_lifecycle_badge()` creates a badge describing current stage in project lifecycle (#48). -* `use_pkgdown()` creates the basics needed for a +* `use_pkgdown()` creates the basics needed for a [pkgdown](https://github.com/r-lib/pkgdown) website (#88). * `use_r("foo")` creates and edit `R/foo.R` file. If you have a test file open, @@ -1263,7 +1263,7 @@ templating functions using this framework (@ijlyttle #120). ## Bug fixes and improvements -* `use_dev_version()` now correctly updates the `Version` field in a package +* `use_dev_version()` now correctly updates the `Version` field in a package description file. (@tjmahr, #104) * `use_revdep()` now also git-ignores the SQLite database (#107). @@ -1290,7 +1290,7 @@ The output from all usethis commands has been reviewed to be informative but not * `use_depsy_badge()` allows including a Depsy badge (@gvegayon, #68). -* `use_dev_package()` works like `use_package()` but also adds the +* `use_dev_package()` works like `use_package()` but also adds the repo to the `Remotes` field (#32). * `use_github_labels()` will automatically set up a standard set of labels, @@ -1304,7 +1304,7 @@ The output from all usethis commands has been reviewed to be informative but not * `use_tidy_description()` puts description fields in a standard order and alphabetises dependencies. -* `use_tidy_eval()` imports and re-exports the recommend set of tidy eval +* `use_tidy_eval()` imports and re-exports the recommend set of tidy eval helpers if your package uses tidy eval (#46). * `use_usethis()` opens your `.Rprofile` and gives you the code to copy @@ -1323,16 +1323,16 @@ A new class of functions make it easy to edit common config files: ## Updates -* `use_coverage("codecov")` now sets a default threshold of 1% to try and +* `use_coverage("codecov")` now sets a default threshold of 1% to try and reduce false positives (#8). * `use_description()` now sets `ByteCompile: true` so you can benefit from the byte compiler (#29) -* The license functions (`use_mit_license()`, `use_apl2_license()`, and - `use_gpl3_license()`) save a copy of the standard license text in +* The license functions (`use_mit_license()`, `use_apl2_license()`, and + `use_gpl3_license()`) save a copy of the standard license text in `LICENSE.md`, which is then added to `.Rbuildignore`. This allows you - to follow standard licensing best practices while adhering to CRANs + to follow standard licensing best practices while adhering to CRANs requirements (#10). * `use_package_doc()` uses more a modern roxygen2 template that requires @@ -1351,17 +1351,17 @@ A new class of functions make it easy to edit common config files: ## Building blocks -* New `use_badge()` for adding any badge to a README. Now only prints a +* New `use_badge()` for adding any badge to a README. Now only prints a todo message if the badge does not already exist. -* `use_directory()` is now exported (#27). +* `use_directory()` is now exported (#27). ## Bug fixes and minor improvements * Functions which require code to be copied now automatically put the code on the clipboard if it is available (#52). -* `create_package()` no longer creates a dependency on the current version of +* `create_package()` no longer creates a dependency on the current version of R. * `use_build_ignore()` now strips trailing `/` @@ -1377,5 +1377,5 @@ A new class of functions make it easy to edit common config files: * `use_vignette()` now adds `*.html` and `*.R` to your `.gitgnore` so you don't accidentally add in compiled vignette products (#35). -* `use_travis_badge()` and `use_appveyor_badge()` are now exported functions, - so they can be used even if ci was separately set up (#765, @smwindecker). +* `use_travis_badge()` and `use_appveyor_badge()` are now exported functions, + so they can be used even if ci was separately set up (#765, @smwindecker). From eaf28b9d33ccc447b2a93187f9a9bda7d89ae608 Mon Sep 17 00:00:00 2001 From: Joe Roe Date: Tue, 23 Jul 2024 21:32:21 +0200 Subject: [PATCH 14/22] Remove self-reference from use_description() documentation #1881 (#1882) --- R/create.R | 3 +++ R/description.R | 7 ++++--- man/use_description.Rd | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/R/create.R b/R/create.R index 5b264ad0c..c1b1281e0 100644 --- a/R/create.R +++ b/R/create.R @@ -10,6 +10,9 @@ #' any existing files are changed. #' #' @inheritParams use_description +#' @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. #' @param path A path. If it exists, it is used. If it does not exist, it is #' created, provided that the parent path exists. #' @param roxygen Do you plan to use roxygen2 to document your package? diff --git a/R/description.R b/R/description.R index 6c11d860d..4e15ef633 100644 --- a/R/description.R +++ b/R/description.R @@ -13,7 +13,7 @@ #' usethis consults the following sources, in this order, to set `DESCRIPTION` #' fields: -#' * `fields` argument of [create_package()] or [use_description()] +#' * `fields` argument of [create_package()] or `use_description()` #' * `getOption("usethis.description")` #' * Defaults built into usethis #' @@ -44,8 +44,9 @@ #' supported. #' #' @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. +#' overriding default values. Default values are taken from the +#' `"usethis.description"` option or the usethis package (in that order), and +#' can be viewed with `use_description_defaults()`. #' @param check_name Whether to check if the name is valid for CRAN and throw an #' error if not. #' @param roxygen If `TRUE`, sets `RoxygenNote` to current roxygen2 version diff --git a/man/use_description.Rd b/man/use_description.Rd index 6fbbf0495..fa274e0f4 100644 --- a/man/use_description.Rd +++ b/man/use_description.Rd @@ -11,8 +11,9 @@ use_description_defaults(package = NULL, roxygen = TRUE, fields = list()) } \arguments{ \item{fields}{A named list of fields to add to \code{DESCRIPTION}, potentially -overriding default values. See \code{\link[=use_description]{use_description()}} for how you can set -personalized defaults using package options.} +overriding default values. Default values are taken from the +\code{"usethis.description"} option or the usethis package (in that order), and +can be viewed with \code{use_description_defaults()}.} \item{check_name}{Whether to check if the name is valid for CRAN and throw an error if not.} @@ -32,7 +33,7 @@ CRAN-compliant package name. You can turn this off with \code{check_name = FALSE usethis consults the following sources, in this order, to set \code{DESCRIPTION} fields: \itemize{ -\item \code{fields} argument of \code{\link[=create_package]{create_package()}} or \code{\link[=use_description]{use_description()}} +\item \code{fields} argument of \code{\link[=create_package]{create_package()}} or \code{use_description()} \item \code{getOption("usethis.description")} \item Defaults built into usethis } From 3a5664c17c556db8cb2aebc2256d00c2ee38e9f5 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Tue, 23 Jul 2024 17:13:18 -0400 Subject: [PATCH 15/22] Mention pak instead of devtools in README template (#2016) * Mention pak instead of devtools in README template * Update snapshot * Update snapshot * Update usethis-setup.Rmd to mention pak * Update NEWS.md --- NEWS.md | 3 +++ inst/templates/package-README | 4 ++-- tests/testthat/_snaps/readme.md | 8 ++++---- vignettes/articles/usethis-setup.Rmd | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5ef8375e4..fd84846ec 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # usethis (development version) +* The README templates now recommend [pak](https://pak.r-lib.org) instead of + devtools for package installation (@olivroy, #1723). + * `use_github()` now knows that you can reuse the name of an earlier repo that has since been renamed (@ateucher, #1893). diff --git a/inst/templates/package-README b/inst/templates/package-README index 19b78b019..cde93f606 100644 --- a/inst/templates/package-README +++ b/inst/templates/package-README @@ -28,8 +28,8 @@ The goal of {{{ Package }}} is to ... You can install the development version of {{{ Package }}} from [GitHub](https://github.com/) with: ``` r -# install.packages("devtools") -devtools::install_github("{{{ github_spec }}}") +# install.packages("pak") +pak::pak("{{{ github_spec }}}") ``` {{/on_github}} {{^on_github}} diff --git a/tests/testthat/_snaps/readme.md b/tests/testthat/_snaps/readme.md index 5cb1f2556..631898991 100644 --- a/tests/testthat/_snaps/readme.md +++ b/tests/testthat/_snaps/readme.md @@ -47,8 +47,8 @@ You can install the development version of {TESTPKG} from [GitHub](https://github.com/) with: ``` r - # install.packages("devtools") - devtools::install_github("OWNER/TESTPKG") + # install.packages("pak") + pak::pak("OWNER/TESTPKG") ``` ## Example @@ -153,8 +153,8 @@ You can install the development version of {TESTPKG} from [GitHub](https://github.com/) with: ``` r - # install.packages("devtools") - devtools::install_github("OWNER/TESTPKG") + # install.packages("pak") + pak::pak("OWNER/TESTPKG") ``` ## Example diff --git a/vignettes/articles/usethis-setup.Rmd b/vignettes/articles/usethis-setup.Rmd index e1256c8b0..367ed8f34 100644 --- a/vignettes/articles/usethis-setup.Rmd +++ b/vignettes/articles/usethis-setup.Rmd @@ -184,7 +184,7 @@ Git/GitHub credential management is detailed in a separate article: ## Prepare your system to build packages from source -As you participate more in R development, you will inevitably want to run development versions of other people's packages, i.e. not the version available from CRAN. A typical way to do this is to install a package from GitHub with `devtools::install_github("OWNER/REPO")`. +As you participate more in R development, you will inevitably want to run development versions of other people's packages, i.e. not the version available from CRAN. A typical way to do this is to install a package from GitHub with `pak::pak("OWNER/REPO")`. But, unlike using `install.packages()` and CRAN, you will be downloading and installing a *source* package, not a *binary* package. This means your system needs to be set up for building R packages. And, before long, you will need to build an R package with compiled code in it. From 120b872a13442ef7570a92cdb7a7a7a4ebbbfd0e Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 23 Jul 2024 12:33:05 -0700 Subject: [PATCH 16/22] Re-document() --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6fe4d0c5..1b915cec1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -60,4 +60,4 @@ Config/testthat/start-first: github-actions, release Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 From 1257a3286c80897155da39ebeaacf2897fc3ef54 Mon Sep 17 00:00:00 2001 From: "Jennifer (Jenny) Bryan" Date: Tue, 23 Jul 2024 15:18:29 -0700 Subject: [PATCH 17/22] Stop repeating "which repo?" question in use_release_issue() (#2024) * Pass the target repo to release_checklist() * Add some tests * Give `upkeep_checklist()` the same treatment * Rely on the tryCatch() to handle "no internet" * Add a test and move a test * Add NEWS bullet --- NEWS.md | 4 +++ R/github.R | 5 ++-- R/release.R | 29 +++++++------------- R/upkeep.R | 8 ++++-- R/utils-github.R | 19 +++++++++---- tests/testthat/test-github.R | 14 ++++++++++ tests/testthat/test-release.R | 44 +++++++++++++++++++++--------- tests/testthat/test-utils-github.R | 6 ++++ 8 files changed, 87 insertions(+), 42 deletions(-) diff --git a/NEWS.md b/NEWS.md index fd84846ec..ac43cca6a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # usethis (development version) +* `use_release_issue()` and `use_upkeep()` behave better when the user has a + fork. The user is asked just once to choose between `origin` and `upstream` as + the target repo (#2023). + * The README templates now recommend [pak](https://pak.r-lib.org) instead of devtools for package installation (@olivroy, #1723). diff --git a/R/github.R b/R/github.R index b28336766..2ee06f7ea 100644 --- a/R/github.R +++ b/R/github.R @@ -239,8 +239,9 @@ use_github_links <- function(auth_token = deprecated(), invisible() } -has_github_links <- function() { - github_url <- github_url_from_git_remotes() +has_github_links <- function(target_repo = NULL) { + url <- if (is.null(target_repo)) NULL else target_repo$url + github_url <- github_url_from_git_remotes(url) if (is.null(github_url)) { return(FALSE) } diff --git a/R/release.R b/R/release.R index f43675fea..1773766ae 100644 --- a/R/release.R +++ b/R/release.R @@ -56,7 +56,7 @@ use_release_issue <- function(version = NULL) { } on_cran <- !is.null(cran_version()) - checklist <- release_checklist(version, on_cran) + checklist <- release_checklist(version, on_cran, tr) gh <- gh_tr(tr) issue <- gh( @@ -69,23 +69,16 @@ use_release_issue <- function(version = NULL) { view_url(issue$html_url) } -release_checklist <- function(version, on_cran) { +release_checklist <- function(version, on_cran, target_repo = NULL) { type <- release_type(version) cran_results <- cran_results_url() has_news <- file_exists(proj_path("NEWS.md")) has_pkgdown <- uses_pkgdown() has_lifecycle <- proj_desc()$has_dep("lifecycle") has_readme <- file_exists(proj_path("README.Rmd")) - has_github_links <- has_github_links() + has_github_links <- has_github_links(target_repo) is_posit_pkg <- is_posit_pkg() - - milestone_num <- NA # for testing (and general fallback) - if (uses_git() && curl::has_internet()) { - milestone_num <- tryCatch( - gh_milestone_number(target_repo_spec(), version), - error = function(e) NA - ) - } + milestone_num <- gh_milestone_number(target_repo, version) c( if (!on_cran) c( @@ -104,9 +97,7 @@ release_checklist <- function(version, on_cran) { "Prepare for release:", "", todo("`git pull`"), - if (!is.na(milestone_num)) { - todo("[Close v{version} milestone](../milestone/{milestone_num})") - }, + todo("[Close v{version} milestone](../milestone/{milestone_num})", !is.na(milestone_num)), todo("Check [current CRAN check results]({cran_results})", on_cran), todo(" Check if any deprecation processes should be advanced, as described in \\ @@ -144,11 +135,11 @@ release_checklist <- function(version, on_cran) { ) } -gh_milestone_number <- function(repo_spec, version, state = "open") { - milestones <- gh::gh( - "/repos/{repo_spec}/milestones", - repo_spec = repo_spec, - state = state +gh_milestone_number <- function(target_repo, version, state = "open") { + gh <- gh_tr(target_repo) + milestones <- tryCatch( + gh("/repos/{owner}/{repo}/milestones", state = state), + error = function(e) list() ) titles <- map_chr(milestones, "title") numbers <- map_int(milestones, "number") diff --git a/R/upkeep.R b/R/upkeep.R index a24ba0993..0de6d48fb 100644 --- a/R/upkeep.R +++ b/R/upkeep.R @@ -43,7 +43,7 @@ make_upkeep_issue <- function(year, tidy) { if (tidy) { checklist <- tidy_upkeep_checklist(year, repo_spec = tr$repo_spec) } else { - checklist <- upkeep_checklist() + checklist <- upkeep_checklist(tr) } title_year <- year %||% format(Sys.Date(), "%Y") @@ -58,11 +58,13 @@ make_upkeep_issue <- function(year, tidy) { view_url(issue$html_url) } -upkeep_checklist <- function() { +upkeep_checklist <- function(target_repo = NULL) { + has_github_links <- has_github_links(target_repo) + bullets <- c( todo("`usethis::use_readme_rmd()`", !file_exists(proj_path("README.Rmd"))), todo("`usethis::use_roxygen_md()`", !is_true(uses_roxygen_md())), - todo("`usethis::use_github_links()`", !has_github_links()), + todo("`usethis::use_github_links()`", !has_github_links), todo("`usethis::use_pkgdown_github_pages()`", !uses_pkgdown()), todo("`usethis::use_tidy_description()`"), todo( diff --git a/R/utils-github.R b/R/utils-github.R index 4630448e5..66fca74bd 100644 --- a/R/utils-github.R +++ b/R/utils-github.R @@ -86,12 +86,21 @@ parse_repo_url <- function(x) { } } -github_url_from_git_remotes <- function() { - tr <- tryCatch(target_repo(github_get = NA), error = function(e) NULL) - if (is.null(tr)) { - return() +# Can be called in contexts where we have already asked user to choose between +# origin and upstsream and, therefore, we know the remote URL. We parse it +# regardless, because: +# (1) Could be SSH not HTTPS +# (2) Could be hosted on GHE not github.com +github_url_from_git_remotes <- function(url = NULL) { + if (is.null(url)) { + tr <- tryCatch(target_repo(github_get = NA), error = function(e) NULL) + if (is.null(tr)) { + return() + } + url <- tr$url } - parsed <- parse_github_remotes(tr$url) + + parsed <- parse_github_remotes(url) glue_data_chr(parsed, "https://{host}/{repo_owner}/{repo_name}") } diff --git a/tests/testthat/test-github.R b/tests/testthat/test-github.R index 0a85425d2..941e70486 100644 --- a/tests/testthat/test-github.R +++ b/tests/testthat/test-github.R @@ -1,3 +1,17 @@ +test_that("has_github_links() uses the target_repo, if provided", { + skip_if_no_git_user() + create_local_package() + local_interactive(FALSE) + use_git() + + desc::desc_set_urls("https://github.com/OWNER/REPO") + desc::desc_set("BugReports", "https://github.com/OWNER/REPO/issues") + + tr <- list(url = "git@github.com:OWNER/REPO.git") + + expect_true(has_github_links(tr)) +}) + test_that("use_github_links populates empty URL field", { skip_if_no_git_user() local_interactive(FALSE) diff --git a/tests/testthat/test-release.R b/tests/testthat/test-release.R index d9644ada1..675017902 100644 --- a/tests/testthat/test-release.R +++ b/tests/testthat/test-release.R @@ -87,6 +87,37 @@ test_that("RStudio-ness detection works", { ) }) +test_that("can find milestone numbers", { + skip_if_offline("github.com") + + tr <- list( + repo_owner = "r-lib", + repo_name = "usethis", + api_url = "https://api.github.com" + ) + + expect_equal( + gh_milestone_number(tr, "2.1.6", state = "all"), + 8 + ) + expect_equal( + gh_milestone_number(tr, "0.0.0", state = "all"), + NA_integer_ + ) +}) + +test_that("gh_milestone_number() returns NA when gh() errors", { + local_mocked_bindings( + gh_tr = function(tr) { function(endpoint, ...) { ui_abort("nope!") } } + ) + tr <- list( + repo_owner = "r-lib", + repo_name = "usethis", + api_url = "https://api.github.com" + ) + expect_true(is.na(gh_milestone_number(tr, "1.1.1"))) +}) + # news -------------------------------------------------------------------- test_that("must have at least one heading", { @@ -127,19 +158,6 @@ test_that("returns empty string if no bullets", { expect_equal(news_latest(lines), "") }) -test_that("can find milestone numbers", { - skip_if_offline("github.com") - - expect_equal( - gh_milestone_number("r-lib/usethis", "2.1.6", state = "all"), - 8 - ) - expect_equal( - gh_milestone_number("r-lib/usethis", "0.0.0", state = "all"), - NA_integer_ - ) -}) - # draft release ---------------------------------------------------------------- test_that("get_release_data() works if no file found", { skip_if_no_git_user() diff --git a/tests/testthat/test-utils-github.R b/tests/testthat/test-utils-github.R index 5875e40a8..e37314336 100644 --- a/tests/testthat/test-utils-github.R +++ b/tests/testthat/test-utils-github.R @@ -150,6 +150,12 @@ test_that("github_remotes() works", { expect_true(is.na(grl$is_fork)) }) +test_that("github_url_from_git_remotes() is idempotent", { + url <- "https://github.com/r-lib/usethis.git" + out <- github_url_from_git_remotes(url) + expect_equal(out, github_url_from_git_remotes(out)) +}) + # GitHub remote configuration -------------------------------------------------- test_that("we understand the list of all possible configs", { From bd37993bfb2faf786edf31a024ca2fb53cd95595 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 23 Jul 2024 15:52:22 -0700 Subject: [PATCH 18/22] Pass along the error *message*, not the whole error condition Closes #2014 --- R/github_token.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/github_token.R b/R/github_token.R index 4cb02e7a4..3e5840bbc 100644 --- a/R/github_token.R +++ b/R/github_token.R @@ -166,7 +166,7 @@ pat_sitrep <- function(host = "https://github.com", } message <- c( message, - "i" = maybe_who$error + "i" = maybe_who$error$message ) ui_bullets(message) return(invisible(FALSE)) From 2dab4c2facd43aea2e5884709aa591f45732b47a Mon Sep 17 00:00:00 2001 From: Rebecca Butler Date: Tue, 23 Jul 2024 16:43:58 -0700 Subject: [PATCH 19/22] Update github_token.R to point Linux users to article (#1875) * Update github_token.R to point Linux users to article `usethis::create_github_token()` returns code for calling `gitcreds::gitcreds_set()` to set credentials. This may not (does not?) work as a user would likely expect on Linux systems, as documented in the Managing Git(Hub) Credentials article as well as various issues. However, `gitcreds::gitcreds_set()` does not give any such indication, and I think a simple addition to the `create_github_token()` output would be valuable git can be overwhelming, silent errors are extra challenging, the straightforward "Call `gitcreds::gitcreds_set() to register this token" sounds authoritative (leading to extra confusion when things don't work as expected), and {usethis} is such an excellent resource for getting people up and running with git. Thus, explicitly telling Linux users that they may need to reference additional documentation would likely be valuable thanks for considering! * Re-introduce, conditionally, the Linux-specific tip --------- Co-authored-by: Jenny Bryan --- R/github_token.R | 17 ++++++++++++++--- R/utils.R | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/R/github_token.R b/R/github_token.R index 3e5840bbc..819b72194 100644 --- a/R/github_token.R +++ b/R/github_token.R @@ -67,12 +67,23 @@ create_github_token <- function(scopes = c("repo", "user", "gist", "workflow"), withr::defer(view_url(url)) hint <- code_hint_with_host("gitcreds::gitcreds_set", host) - ui_bullets(c( + message <- c( "_" = "Call {.code {hint}} to register this token in the local Git - credential store.", + credential store." + ) + if (is_linux()) { + message <- c( + message, + "!" = "On Linux, it can be tricky to store credentials persistently.", + "i" = "Read more in the {.href ['Managing Git(Hub) Credentials' article](https://usethis.r-lib.org/articles/articles/git-credentials.html)}." + ) + } + message <- c( + message, "i" = "It is also a great idea to store this token in any password-management software that you use." - )) + ) + ui_bullets(message) invisible() } diff --git a/R/utils.R b/R/utils.R index 50c9846a2..fcba6e889 100644 --- a/R/utils.R +++ b/R/utils.R @@ -95,6 +95,10 @@ is_windows <- function() { .Platform$OS.type == "windows" } +is_linux <- function() { + identical(tolower(Sys.info()[["sysname"]]), "linux") +} + # For stability of `stringsAsFactors` across versions data.frame <- function(..., stringsAsFactors = FALSE) { base::data.frame(..., stringsAsFactors = stringsAsFactors) From acac3f9052de116af911f088f5a7da277337a902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 24 Jul 2024 07:55:44 +0200 Subject: [PATCH 20/22] Improvements to standalone header (#1903) * Add ref and host to standalone header * Add code to generate the standalone * Make some more changes * Dogfood it * Add NEWS bullet * Use fs * Update a snapshot --------- Co-authored-by: Jenny Bryan --- NEWS.md | 3 + R/import-standalone-obj-type.R | 29 +++++++--- R/import-standalone-types-check.R | 3 +- R/use_standalone.R | 18 +++++- tests/testthat/_snaps/use_standalone.md | 76 +++++++++++++++++++++---- tests/testthat/test-use_standalone.R | 35 ++++++++++-- 6 files changed, 139 insertions(+), 25 deletions(-) diff --git a/NEWS.md b/NEWS.md index ac43cca6a..7b5a0b3a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # usethis (development version) +* `use_standalone()` inserts an improved header that includes the code needed to + update the standalone file (@krlmlr, #1903). + * `use_release_issue()` and `use_upkeep()` behave better when the user has a fork. The user is asked just once to choose between `origin` and `upstream` as the target repo (#2023). diff --git a/R/import-standalone-obj-type.R b/R/import-standalone-obj-type.R index 72cfe37dc..47268d620 100644 --- a/R/import-standalone-obj-type.R +++ b/R/import-standalone-obj-type.R @@ -1,17 +1,27 @@ # Standalone file: do not edit by hand -# Source: +# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-obj-type.R +# Generated by: usethis::use_standalone("r-lib/rlang", "obj-type") # ---------------------------------------------------------------------- # # --- # repo: r-lib/rlang # file: standalone-obj-type.R -# last-updated: 2022-10-04 +# last-updated: 2024-02-14 # license: https://unlicense.org # imports: rlang (>= 1.1.0) # --- # # ## Changelog # +# 2024-02-14: +# - `obj_type_friendly()` now works for S7 objects. +# +# 2023-05-01: +# - `obj_type_friendly()` now only displays the first class of S3 objects. +# +# 2023-03-30: +# - `stop_input_type()` now handles `I()` input literally in `arg`. +# # 2022-10-04: # - `obj_type_friendly(value = TRUE)` now shows numeric scalars # literally. @@ -65,7 +75,7 @@ obj_type_friendly <- function(x, value = TRUE) { if (inherits(x, "quosure")) { type <- "quosure" } else { - type <- paste(class(x), collapse = "/") + type <- class(x)[[1L]] } return(sprintf("a <%s> object", type)) } @@ -261,19 +271,19 @@ vec_type_friendly <- function(x, length = FALSE) { #' Return OO type #' @param x Any R object. #' @return One of `"bare"` (for non-OO objects), `"S3"`, `"S4"`, -#' `"R6"`, or `"R7"`. +#' `"R6"`, or `"S7"`. #' @noRd obj_type_oo <- function(x) { if (!is.object(x)) { return("bare") } - class <- inherits(x, c("R6", "R7_object"), which = TRUE) + class <- inherits(x, c("R6", "S7_object"), which = TRUE) if (class[[1]]) { "R6" } else if (class[[2]]) { - "R7" + "S7" } else if (isS4(x)) { "S4" } else { @@ -315,10 +325,15 @@ stop_input_type <- function(x, if (length(what)) { what <- oxford_comma(what) } + if (inherits(arg, "AsIs")) { + format_arg <- identity + } else { + format_arg <- cli$format_arg + } message <- sprintf( "%s must be %s, not %s.", - cli$format_arg(arg), + format_arg(arg), what, obj_type_friendly(x, value = show_value) ) diff --git a/R/import-standalone-types-check.R b/R/import-standalone-types-check.R index 6782d69b1..0943a8d58 100644 --- a/R/import-standalone-types-check.R +++ b/R/import-standalone-types-check.R @@ -1,5 +1,6 @@ # Standalone file: do not edit by hand -# Source: +# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-types-check.R +# Generated by: usethis::use_standalone("r-lib/rlang", "types-check") # ---------------------------------------------------------------------- # # --- diff --git a/R/use_standalone.R b/R/use_standalone.R index cae24075b..e23d1cba7 100644 --- a/R/use_standalone.R +++ b/R/use_standalone.R @@ -74,7 +74,7 @@ use_standalone <- function(repo_spec, file = NULL, ref = NULL, host = NULL) { dest_path <- path("R", as_standalone_dest_file(file)) lines <- read_github_file(repo_spec, path = src_path, ref = ref, host = host) - lines <- c(standalone_header(repo_spec, src_path), lines) + lines <- c(standalone_header(repo_spec, src_path, ref, host), lines) write_over(proj_path(dest_path), lines, overwrite = TRUE) dependencies <- standalone_dependencies(lines, path) @@ -156,10 +156,22 @@ as_standalone_dest_file <- function(file) { gsub("standalone-", "import-standalone-", file) } -standalone_header <- function(repo_spec, path) { +standalone_header <- function(repo_spec, path, ref = NULL, host = NULL) { + ref_string <- ref %||% "HEAD" + host_string <- host %||% "https://github.com" + source_comment <- + glue("# Source: {host_string}/{repo_spec}/blob/{ref_string}/{path}") + + path_string <- path_ext_remove(sub("^standalone-", "", path_file(path))) + ref_string <- if (is.null(ref)) "" else glue(', ref = "{ref}"') + host_string <- if (is.null(host) || host == "https://github.com") "" else glue(', host = "{host}"') + code_hint <- glue('usethis::use_standalone("{repo_spec}", "{path_string}"{ref_string}{host_string})') + generated_comment <- glue('# Generated by: {code_hint}') + c( "# Standalone file: do not edit by hand", - glue("# Source: "), + source_comment, + generated_comment, paste0("# ", strrep("-", 72 - 2)), "#" ) diff --git a/tests/testthat/_snaps/use_standalone.md b/tests/testthat/_snaps/use_standalone.md index 9b1e3532e..1b1a447b6 100644 --- a/tests/testthat/_snaps/use_standalone.md +++ b/tests/testthat/_snaps/use_standalone.md @@ -1,3 +1,69 @@ +# standalone_header() works with various inputs + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.com/OWNER/REPO/blob/HEAD/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + +--- + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R", ref = "blah") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.com/OWNER/REPO/blob/blah/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\", ref = \"blah\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + +--- + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R", host = "https://github.com") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.com/OWNER/REPO/blob/HEAD/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + +--- + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R", host = "https://github.acme.com") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.acme.com/OWNER/REPO/blob/HEAD/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\", host = \"https://github.acme.com\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + +--- + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R", ref = "blah", host = "https://github.com") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.com/OWNER/REPO/blob/blah/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\", ref = \"blah\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + +--- + + Code + standalone_header("OWNER/REPO", "R/standalone-foo.R", ref = "blah", host = "https://github.acme.com") + Output + [1] "# Standalone file: do not edit by hand" + [2] "# Source: https://github.acme.com/OWNER/REPO/blob/blah/R/standalone-foo.R" + [3] "# Generated by: usethis::use_standalone(\"OWNER/REPO\", \"foo\", ref = \"blah\", host = \"https://github.acme.com\")" + [4] "# ----------------------------------------------------------------------" + [5] "#" + # can offer choices Code @@ -12,16 +78,6 @@ ! `file` is absent, but must be supplied. i Possible options are cli, downstream-deps, lazyeval, lifecycle, linked-version, obj-type, purrr, rlang, s3-register, sizes, types-check, vctrs, or zeallot. -# header provides useful summary - - Code - standalone_header("r-lib/usethis", "R/standalone-test.R") - Output - [1] "# Standalone file: do not edit by hand" - [2] "# Source: " - [3] "# ----------------------------------------------------------------------" - [4] "#" - # can extract imports Code diff --git a/tests/testthat/test-use_standalone.R b/tests/testthat/test-use_standalone.R index 638411c27..41d9337e7 100644 --- a/tests/testthat/test-use_standalone.R +++ b/tests/testthat/test-use_standalone.R @@ -1,3 +1,34 @@ +test_that("standalone_header() works with various inputs", { + expect_snapshot( + standalone_header("OWNER/REPO", "R/standalone-foo.R") + ) + expect_snapshot( + standalone_header("OWNER/REPO", "R/standalone-foo.R", ref = "blah") + ) + expect_snapshot( + standalone_header( + "OWNER/REPO", "R/standalone-foo.R", host = "https://github.com" + ) + ) + expect_snapshot( + standalone_header( + "OWNER/REPO", "R/standalone-foo.R", host = "https://github.acme.com" + ) + ) + expect_snapshot( + standalone_header( + "OWNER/REPO", "R/standalone-foo.R", + ref = "blah", host = "https://github.com" + ) + ) + expect_snapshot( + standalone_header( + "OWNER/REPO", "R/standalone-foo.R", + ref = "blah", host = "https://github.acme.com" + ) + ) +}) + test_that("can import standalone file with dependencies", { skip_if_offline("github.com") create_local_package() @@ -40,10 +71,6 @@ test_that("can offer choices", { }) }) -test_that("header provides useful summary", { - expect_snapshot(standalone_header("r-lib/usethis", "R/standalone-test.R")) -}) - test_that("can extract dependencies", { extract_deps <- function(deps) { out <- standalone_dependencies(c("# ---", deps, "# ---"), "test.R") From 93f4410ab93cb6e19cd6a49cd4ce33f93055b38b Mon Sep 17 00:00:00 2001 From: MikeJohnPage <38110953+MikeJohnPage@users.noreply.github.com> Date: Wed, 24 Jul 2024 20:29:30 +0200 Subject: [PATCH 21/22] Indicate argument type (#1940) * Indicate argument type Make it clear that `min_version` expects a character vector, and not a double/integer when specifying exact versions. * Correct typo * Rebuild docs * Tweak wording --------- Co-authored-by: Jenny Bryan --- R/package.R | 3 ++- man/use_package.Rd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/package.R b/R/package.R index 989efe0a8..4160aedf7 100644 --- a/R/package.R +++ b/R/package.R @@ -23,7 +23,8 @@ #' "Suggests", "Enhances", or "LinkingTo" (or unique abbreviation). Matching #' is case insensitive. #' @param min_version Optionally, supply a minimum version for the package. Set -#' to `TRUE` to use the currently installed version. +#' to `TRUE` to use the currently installed version or use a version string +#' suitable for [numeric_version()], such as "2.5.0". #' @param remote By default, an `OWNER/REPO` GitHub remote is inserted. #' Optionally, you can supply a character string to specify the remote, e.g. #' `"gitlab::jimhester/covr"`, using any syntax supported by the [remotes diff --git a/man/use_package.Rd b/man/use_package.Rd index 586d9cc64..a0b6659e3 100644 --- a/man/use_package.Rd +++ b/man/use_package.Rd @@ -17,7 +17,8 @@ use_dev_package(package, type = "Imports", remote = NULL) is case insensitive.} \item{min_version}{Optionally, supply a minimum version for the package. Set -to \code{TRUE} to use the currently installed version.} +to \code{TRUE} to use the currently installed version or use a version string +suitable for \code{\link[=numeric_version]{numeric_version()}}, such as "2.5.0".} \item{remote}{By default, an \code{OWNER/REPO} GitHub remote is inserted. Optionally, you can supply a character string to specify the remote, e.g. From a91943706708f7ab41105cc3d5edf6ee61bbfb15 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:58:42 -0400 Subject: [PATCH 22/22] Add yaml to RStudio snippets (#1941) * Add yaml to RStudio snippets * Add news + redocument --------- Co-authored-by: Jennifer (Jenny) Bryan --- NEWS.md | 2 ++ R/edit.R | 2 +- man/edit.Rd | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7b5a0b3a3..d908e7e7c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `edit_rstudio_snippets()` now accepts yaml snippets (@olivroy, #1941). + * `use_standalone()` inserts an improved header that includes the code needed to update the standalone file (@krlmlr, #1903). diff --git a/R/edit.R b/R/edit.R index 58b025d12..203c6450e 100644 --- a/R/edit.R +++ b/R/edit.R @@ -144,7 +144,7 @@ edit_r_makevars <- function(scope = c("user", "project")) { #' @param type Snippet type (case insensitive text). edit_rstudio_snippets <- function(type = c( "r", "markdown", "c_cpp", "css", - "html", "java", "javascript", "python", "sql", "stan", "tex" + "html", "java", "javascript", "python", "sql", "stan", "tex", "yaml" )) { type <- tolower(type) diff --git a/man/edit.Rd b/man/edit.Rd index c76d784a0..43fb62483 100644 --- a/man/edit.Rd +++ b/man/edit.Rd @@ -23,7 +23,7 @@ edit_r_makevars(scope = c("user", "project")) edit_rstudio_snippets( type = c("r", "markdown", "c_cpp", "css", "html", "java", "javascript", "python", - "sql", "stan", "tex") + "sql", "stan", "tex", "yaml") ) edit_rstudio_prefs()