Skip to content

Commit

Permalink
Merge branch 'r-lib:main' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Jun 9, 2024
2 parents d309dd2 + da18e11 commit 1497d10
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: any::rcmdcheck, magick=?ignore-before-r=4.0.0
needs: check

- name: Configure Git User
Expand All @@ -66,5 +66,6 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
env:
_R_CALLS_INVALID_NUMERIC_VERSION_: true
_R_CHECK_FORCE_SUGGESTS_: false
with:
upload-snapshots: true
2 changes: 1 addition & 1 deletion R/badge.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {.fun usethis::use_readme_rmd} for help creating this file.",
"i" = "See {.help usethis::use_readme_rmd} for help creating this file.",
"i" = "Badge link will only be printed to screen."
))
path <- "README"
Expand Down
2 changes: 1 addition & 1 deletion R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#'
#' @export
use_cpp11 <- function() {
check_installed("cpp11")
check_is_package("use_cpp11()")
check_installed("cpp11")
check_uses_roxygen("use_cpp11()")
use_src()

Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ use_data_raw <- function(name = "DATASET", open = rlang::is_interactive()) {

ui_bullets(c(
"_" = "Finish writing the data preparation script in {.path {pth(r_path)}}.",
"_" = "Use {.code usethis::use_data()} to add prepared data to package."
"_" = "Use {.fun usethis::use_data} to add prepared data to package."
))
}
2 changes: 1 addition & 1 deletion R/directory.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ directory_has_files <- function(x) {

check_directory_is_empty <- function(x) {
if (directory_has_files(x)) {
ui_abort("{.path {pth(path)}} exists and is not an empty directory.")
ui_abort("{.path {pth(x)}} exists and is not an empty directory.")
}
invisible(x)
}
4 changes: 4 additions & 0 deletions R/documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
#' @export
use_package_doc <- function(open = rlang::is_interactive()) {
check_is_package("use_package_doc()")
use_directory("R")
use_template(
"packagename-package.R",
package_doc_path(),
open = open
)
ui_bullets(c(
"_" = "Run {.run devtools::document()} to update package-level documentation."
))
}

package_doc_path <- function() {
Expand Down
2 changes: 1 addition & 1 deletion R/github-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ check_uses_github_actions <- function() {

ui_abort(c(
"Cannot detect that package {.pkg {project_name()}} already uses GitHub Actions.",
"Do you need to run {.fun use_github_action}?"
"Do you need to run {.run [use_github_action()](usethis::use_github_action())}?"
))
}

Expand Down
4 changes: 2 additions & 2 deletions R/github_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pat_sitrep <- function(host = "https://github.com",
git_user_check(user)
if (!is.null(user$email) && !any(grepl(user$email, addresses))) {
ui_bullets(c(
"x" = "Git user's email (.val {user$email}}) doesn't appear to be
"x" = "Git user's email ({.val {user$email}}) doesn't appear to be
registered with GitHub host."
))
}
Expand Down Expand Up @@ -233,7 +233,7 @@ scold_for_renviron <- function() {
old, invalid PAT defined in {.path {pth(renviron_path)}}.",
"i" = "For most use cases, it is better to NOT define the PAT in
{.file .Renviron}.",
"_" = "Call {.fun edit_r_environ} to edit that file.",
"_" = "Call {.run usethis::edit_r_environ()} to edit that file.",
"_" = "Then call {.run gitcreds::gitcreds_set()} to put the PAT into
the Git credential store."
))
Expand Down
10 changes: 9 additions & 1 deletion R/logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ use_logo <- function(img, geometry = "240x278", retina = TRUE) {
height <- round(height / 2)
}

ui_bullets(c("_" = "Add logo to your README with the following html:"))
# Have a clickable hyperlink to jump to README if exists.
readme_path <- find_readme()
if (is.null(readme_path)) {
readme_show <- "your README"
} else {
readme_show <- cli::format_inline("{.path {pth(readme_path)}}")
}

ui_bullets(c("_" = "Add logo to {readme_show} with the following html:"))
pd_link <- pkgdown_url(pedantic = TRUE)
if (is.null(pd_link)) {
ui_code_snippet(
Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ suggests_usage_hint <- function(package) {
ui_bullets(c("_" = "Then directly refer to functions with {.code {code}}."))
} else {
code <- glue('requireNamespace("{package}", quietly = TRUE)')
ui_bullets(c("_" = "Use {.code {code}} to test if package is installed."))
ui_bullets(c("_" = "Use {.code {code}} to test if {.pkg {package}} is installed."))
code <- glue("{package}::fun()")
ui_bullets(c("_" = "Then directly refer to functions with {.code {code}}."))
}
Expand Down
34 changes: 18 additions & 16 deletions R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pr_init <- function(branch) {
config_key <- glue("branch.{branch}.created-by")
gert::git_config_set(config_key, value = "usethis::pr_init", repo = repo)

ui_bullets(c("_" = "Use {.fun pr_push} to create a PR."))
ui_bullets(c("_" = "Use {.run usethis::pr_push()} to create a PR."))
invisible()
}

Expand All @@ -251,10 +251,10 @@ pr_resume <- function(branch = NULL) {
check_string(branch)

if (!gert::git_branch_exists(branch, local = TRUE, repo = repo)) {
code <- glue('pr_init("{branch}")')
code <- glue('usethis::pr_init("{branch}")')
ui_abort(c(
"x" = "No branch named {.val {branch}} exists.",
"_" = "Call {.code {code}} to create a new PR branch."
"_" = "Call {.run {code}} to create a new PR branch."
))
}

Expand All @@ -264,7 +264,7 @@ pr_resume <- function(branch = NULL) {
gert::git_branch_checkout(branch, repo = repo)
git_pull()

ui_bullets(c("_" = "Use {.fun usethis::pr_push} to create or update PR."))
ui_bullets(c("_" = "Use {.run usethis::pr_push()} to create or update PR."))
invisible()
}

Expand Down Expand Up @@ -302,7 +302,7 @@ pr_fetch <- function(number = NULL, target = c("source", "primary")) {

if (is.na(pr$pr_repo_owner)) {
ui_abort("
The repo or branch where PR #{pr$pr_number} originates seems to have been
The repo or branch where {.href [PR #{pr$pr_number}]({pr$pr_html_url})} originates seems to have been
deleted.")
}

Expand Down Expand Up @@ -867,16 +867,17 @@ choose_branch <- function(exclude = character()) {
)
prompt <- glue("{prompt}\n{fine_print}")
}
dat$pretty_user <- glue_data(dat, "@{pr_user}")
dat$pretty_name <- format(dat$name, justify = "right")
dat_pretty <- purrr::pmap_chr(
dat[c("pretty_name", "pr_number", "pretty_user", "pr_title")],
function(pretty_name, pr_number, pretty_user, pr_title) {
dat[c("pretty_name", "pr_number", "pr_html_url", "pr_user", "pr_title")],
function(pretty_name, pr_number, pr_html_url, pr_user, pr_title) {
if (is.na(pr_number)) {
pretty_name
} else {
href_number <- ui_pre_glue("{.href [PR #<<pr_number>>](<<pr_html_url>>)}")
at_user <- glue("@{pr_user}")
template <- ui_pre_glue(
"{pretty_name} {cli::symbol$arrow_right} #{pr_number} ({.field <<pretty_user>>}): {pr_title}"
"{pretty_name} {cli::symbol$arrow_right} <<href_number>> ({.field <<at_user>>}): {.val <<pr_title>>}"
)
cli::format_inline(template)
}
Expand Down Expand Up @@ -916,18 +917,18 @@ choose_pr <- function(tr = NULL, pr_dat = NULL) {

some_closed <- any(pr_dat$pr_state == "closed")
pr_pretty <- purrr::pmap_chr(
pr_dat[c("pr_number", "pr_user", "pr_state", "pr_title")],
function(pr_number, pr_user, pr_state, pr_title) {
hash_number <- glue("#{pr_number}")
pr_dat[c("pr_number", "pr_html_url", "pr_user", "pr_state", "pr_title")],
function(pr_number, pr_html_url, pr_user, pr_state, pr_title) {
href_number <- ui_pre_glue("{.href [PR #<<pr_number>>](<<pr_html_url>>)}")
at_user <- glue("@{pr_user}")
if (some_closed) {
template <- ui_pre_glue(
"{hash_number} ({.field <<at_user>>}, {pr_state}): {.val <<pr_title>>}"
"<<href_number>> ({.field <<at_user>>}, {pr_state}): {.val <<pr_title>>}"
)
cli::format_inline(template)
} else {
template <- ui_pre_glue(
"{hash_number} ({.field <<at_user>>}): {.val <<pr_title>>}"
"<<href_number>> ({.field <<at_user>>}): {.val <<pr_title>>}"
)
cli::format_inline(template)
}
Expand Down Expand Up @@ -1001,8 +1002,9 @@ check_pr_branch <- function(default_branch = git_default_branch()) {
"i" = "The {.code pr_*()} functions facilitate pull requests.",
"i" = "The current branch ({.val {gb}}) is this repo's default branch, but
pull requests should NOT come from the default branch.",
"i" = "Do you need to call {.fun pr_init} (new PR)? Or {.fun pr_resume} or
{.fun pr_fetch} (existing PR)?"
"i" = "Do you need to call {.fun usethis::pr_init} (new PR)?
Or {.fun usethis::pr_resume} or
{.fun usethis::pr_fetch} (existing PR)?"
)
)
}
3 changes: 2 additions & 1 deletion R/proj.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ check_is_package <- function(whos_asking = NULL) {

message <- "Project {.val {project_name()}} is not an R package."
if (!is.null(whos_asking)) {
whos_asking_fn <- sub("()", "", whos_asking, fixed = TRUE)
message <- c(
"i" = "{.code {whos_asking}} is designed to work with packages.",
"i" = "{.topic [{whos_asking}](usethis::{whos_asking_fn})} is designed to work with packages.",
"x" = message
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use_roxygen_md <- function(overwrite = FALSE) {
the conversion process."
))
}
ui_bullets(c("v" = "Run {.run devtools::document()} when you're done."))
ui_bullets(c("_" = "Run {.run devtools::document()} when you're done."))

return(invisible())
}
Expand Down
2 changes: 1 addition & 1 deletion R/tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' * Prepare the roxygen directive necessary to import at least one function
#' from tibble:
#' - If possible, the directive is inserted into existing package-level
#' documentation, i.e. the roxygen snippet created by [use_package_doc()]
#' documentation, i.e. the roxygen snippet created by [use_package_doc()]
#' - Otherwise, we issue advice on where the user should add the directive
#'
#' This is necessary when your package returns a stored data object that has
Expand Down
18 changes: 9 additions & 9 deletions R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ create_tidy_package <- function(path, copyright_holder = NULL) {

use_cran_comments(open = FALSE)

ui_bullets(c(
"i" = "In the new package, remember to do:",
"_" = "{.run usethis::use_git()}",
"_" = "{.run usethis::use_github()}",
"_" = "{.run usethis::use_tidy_github()}",
"_" = "{.run usethis::use_tidy_github_actions()}",
"_" = "{.run usethis::use_tidy_github_labels()}",
"_" = "{.run usethis::use_pkgdown_github_pages()}"
))
ui_bullets(c("i" = "In the new package, remember to do:"))
ui_code_snippet("
usethis::use_git()
usethis::use_github()
usethis::use_tidy_github()
usethis::use_tidy_github_actions()
usethis::use_tidy_github_labels()
usethis::use_pkgdown_github_pages()
")

proj_activate(path)
}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ library(usethis)
# Create a new package -------------------------------------------------
path <- file.path(tempdir(), "mypkg")
create_package(path)
#> ✔ Creating '/tmp/Rtmp7yJh5e/mypkg/'.
#> ✔ Setting active project to "/private/tmp/Rtmp7yJh5e/mypkg".
#> ✔ Creating '/tmp/RtmpMuqeSm/mypkg/'.
#> ✔ Setting active project to "/private/tmp/RtmpMuqeSm/mypkg".
#> ✔ Creating 'R/'.
#> ✔ Writing 'DESCRIPTION'.
#> Package: mypkg
Expand All @@ -80,8 +80,8 @@ create_package(path)
#> ✔ Setting active project to "<no active project>".
# only needed since this session isn't interactive
proj_activate(path)
#> ✔ Setting active project to "/private/tmp/Rtmp7yJh5e/mypkg".
#> ✔ Changing working directory to '/tmp/Rtmp7yJh5e/mypkg/'
#> ✔ Setting active project to "/private/tmp/RtmpMuqeSm/mypkg".
#> ✔ Changing working directory to '/tmp/RtmpMuqeSm/mypkg/'

# Modify the description ----------------------------------------------
use_mit_license("My Name")
Expand All @@ -92,7 +92,7 @@ use_mit_license("My Name")

use_package("ggplot2", "Suggests")
#> ✔ Adding ggplot2 to 'Suggests' field in DESCRIPTION.
#> ☐ Use `requireNamespace("ggplot2", quietly = TRUE)` to test if package is
#> ☐ Use `requireNamespace("ggplot2", quietly = TRUE)` to test if ggplot2 is
#> installed.
#> ☐ Then directly refer to functions with `ggplot2::fun()`.

Expand Down
2 changes: 1 addition & 1 deletion man/use_tibble.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/logo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# use_logo() shows a clickable path with README

Code
use_logo("logo.png")
Message
v Creating 'man/figures/'.
v Resized 'logo.png' to 240x278.
[ ] Add logo to 'README.md' with the following html:
# {TESTPKG} <img src="man/figures/logo.png" align="right" height="90" alt="" />

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
use_package("withr", "Suggests")
Message
v Adding withr to 'Suggests' field in DESCRIPTION.
[ ] Use `requireNamespace("withr", quietly = TRUE)` to test if package is
[ ] Use `requireNamespace("withr", quietly = TRUE)` to test if withr is
installed.
[ ] Then directly refer to functions with `withr::fun()`.

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/proj.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# check_is_package() can reveal who's asking

Code
check_is_package("foo()")
Condition
Error in `check_is_package()`:
i foo() (`?usethis::foo`) is designed to work with packages.
x Project "{TESTPROJ}" is not an R package.

# proj_path() errors with absolute paths

Code
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/_snaps/roxygen.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use_package_doc()
Message
v Writing 'R/{TESTPKG}-package.R'.
[ ] Run `devtools::document()` to update package-level documentation.

---

Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/_snaps/tidyverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
v Adding withr to 'Imports' field in DESCRIPTION.
v Adding "@import rlang" to 'R/{TESTPKG}-package.R'.
v Adding "@importFrom glue glue" to 'R/{TESTPKG}-package.R'.
v Adding "@importFrom lifecycle deprecated" to
'R/{TESTPKG}-package.R'.
v Adding "@importFrom lifecycle deprecated" to 'R/{TESTPKG}-package.R'.
v Writing 'NAMESPACE'.
v Writing 'R/import-standalone-purrr.R'.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/upkeep.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
### To finish
* [ ] `usethis::use_mit_license()`
* [ ] `usethis::use_package("R", "Depends", "3.6")`
* [ ] `usethis::use_package("R", "Depends", "4.0")`
* [ ] `usethis::use_tidy_description()`
* [ ] `usethis::use_tidy_github_actions()`
* [ ] `devtools::build_readme()`
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ scrub_testpkg <- function(message) {
gsub("testpkg[a-zA-Z0-9]+", "{TESTPKG}", message, perl = TRUE)
}

scrub_testproj <- function(message) {
gsub("testproj[a-zA-Z0-9]+", "{TESTPROJ}", message, perl = TRUE)
}

skip_if_not_ci <- function() {
ci_providers <- c("GITHUB_ACTIONS", "TRAVIS", "APPVEYOR")
ci <- any(toupper(Sys.getenv(ci_providers)) == "TRUE")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-github-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test_that("uses_github_action() reports usage of GitHub Actions", {

test_that("check_uses_github_actions() can throw error", {
create_local_package()
withr::local_options(list(crayon.enabled = FALSE))
withr::local_options(list(crayon.enabled = FALSE, cli.width = Inf))
expect_snapshot(
check_uses_github_actions(),
error = TRUE,
Expand Down
Loading

0 comments on commit 1497d10

Please sign in to comment.