From 18e520fb5fa329dea6b5e8ba44303b0df13daff6 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sat, 1 Jun 2024 14:33:36 -0400 Subject: [PATCH 01/17] check envs for lib paths --- R/Rprofile-package.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/Rprofile-package.R b/R/Rprofile-package.R index 4c611ec..6002f5e 100644 --- a/R/Rprofile-package.R +++ b/R/Rprofile-package.R @@ -17,7 +17,11 @@ lockEnvironment(rprofile) #' #' @export .RprofileJordan <- function() { - .libPaths(c(.libPaths(), "~/R/pak-library", "~/R/scribe-library")) + .libPaths(c( + .libPaths(), + Sys.getenv("R_LIBS_PAK", "~/R/pak-library"), + Sys.getenv("R_LIBS_SCRIBE", "~/R/scribe-library") + )) .AttachDevtools() .AddAttachedPackagesToDefaultPackages() From 8a0c19a8075c67ef34ac916681b9c365716f3a2a Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sat, 1 Jun 2024 14:34:53 -0400 Subject: [PATCH 02/17] add custom error class --- R/utils.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index d47412f..127998c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -35,5 +35,7 @@ sf <- function(...) { } .try <- function(expr) { - tryCatch(expr, error = force) + tryCatch(expr, error = function(e) { + invisible(structure(list(condition = e), class = "rprofile_error")) + }) } From 0603b475be6e1aa2308429a7b8b7c2d603d5a3e9 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sat, 1 Jun 2024 14:35:28 -0400 Subject: [PATCH 03/17] correct cran status checks --- R/check-cran-status.R | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/R/check-cran-status.R b/R/check-cran-status.R index 56d4062..8a97ed5 100644 --- a/R/check-cran-status.R +++ b/R/check-cran-status.R @@ -11,10 +11,10 @@ } if (is.null(email) && !length(email)) { - email <- .try(get_description_emails()) - if (inherits(email, "error")) { - return(invisible()) - } + email <- .try(get_description_emails()) + if (inherits(email, "error")) { + return(invisible()) + } } cat("Checking CRAN status\n") @@ -22,8 +22,11 @@ for (e in email) { if (success) cat("\n") cat("checking for", crayon_blue(e)) - # shhhh - res <- fuj::wuffle(.try(utils::capture.output(dang::checkCRANStatus(e)))) + res <- fuj::wuffle(.try(utils::capture.output(dang::checkCRANStatus( + email = e, + cache = tempfile("dang_check_cran_status__", fileext = ".rds"), + cache.life = 3600 + )))) if (!inherits(res, "error")) { show_table() success <- TRUE @@ -38,7 +41,7 @@ show_table <- function() { res <- get_recent_cran_check() - time <- crayon_yellow(res[[1]]) + time <- crayon_yellow(format(res[[1]], "%Y-%m-%d %H:%M:%S", usetz = TRUE)) tab <- res[[2]] cat("\n") @@ -47,7 +50,7 @@ show_table <- function() { } get_recent_cran_check <- function() { - files <- list.files(tempdir(), "^cran-status.*.rds$", full.names = TRUE) + files <- list.files(tempdir(), "^dang_check_cran_status__.*\\.rds$", full.names = TRUE) res <- files[which.max(file.mtime(files))] readRDS(res) } @@ -94,7 +97,7 @@ print_cran_status <- function(x) { row[1L], row[1L] ), - paste0(row[-1L], collapse = " ") + paste0(row[crayon_strip(row) != ""][-1L], collapse = " ") ) }) return(invisible(xx)) From 9b85821abe91c17d6dbdcbc56d7822778e954a6a Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sat, 1 Jun 2024 14:36:08 -0400 Subject: [PATCH 04/17] add lintr --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index a95dfdc..4c366d8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^\.lintr$ From ff5720dcdbffe2f6d5104d3b5eff0a1b9d19663e Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sat, 1 Jun 2024 14:36:32 -0400 Subject: [PATCH 05/17] bump versions --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8441feb..aeb8edb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Rprofile Title: Functions to be loaded with Rprofile -Version: 0.0.0.9006 +Version: 0.0.0.9007 Authors@R: person(given = "Jordan Mark", family = "Barbone", @@ -30,10 +30,10 @@ Suggests: devtools, fortunes, fs, - fuj, + fuj (>= 0.2.1), gh, lintr, - mark, + mark (>= 0.8.0), praise, prompt, readr, From 3503c82ada40da0ea8cce141782e5c46c1819d7f Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Fri, 14 Jun 2024 20:19:03 -0400 Subject: [PATCH 06/17] add yes_no() --- NEWS.md | 1 + R/github-release.R | 18 ++++++------------ R/news.R | 14 +++++--------- R/utils.R | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/NEWS.md b/NEWS.md index bed1cdf..65e6790 100644 --- a/NEWS.md +++ b/NEWS.md @@ -25,6 +25,7 @@ * `.NewsUrls()` now has prettier print for differences; URLs detected are highlighted with `{crayon}` and only the changed lines (with line numbers) are printed * Improvements with package checking +* Prompts via `utils::menu()` cleaned up # Rprofile 0.0.0.9000 diff --git a/R/github-release.R b/R/github-release.R index a277c68..b347ee7 100644 --- a/R/github-release.R +++ b/R/github-release.R @@ -25,19 +25,13 @@ return(FALSE) } - switch( - utils::menu( - title = "\nWould you like to publish this release?", - choices = c( - "yeah, publish", - "no, continue as draft", - "nevermind, cancel" - ) - ), - TRUE, - FALSE, + answer <- yes_no("Would you like to publish this release?", na = "CANCEL") + + if (is.na(answer)) { force_exit() - ) + } + + answer } force_exit <- function() { diff --git a/R/news.R b/R/news.R index b62468c..c202fb6 100644 --- a/R/news.R +++ b/R/news.R @@ -56,15 +56,11 @@ cat(new_copy[lines], fill = TRUE, labels = labels) if (!isFALSE(ask)) { - switch( - utils::menu( - title = "\nOkay to update?", - choices = c("yeah, sure", "no ..." - ) - ), - `1` = message("cool"), - `2` = return(invisible()) - ) + if (yes_no("okay to update?")) { + message("cool") + } else { + return(invisible()) + } } if (requireNamespace("urlchecker", quietly = TRUE)) { diff --git a/R/utils.R b/R/utils.R index 127998c..d326850 100644 --- a/R/utils.R +++ b/R/utils.R @@ -39,3 +39,33 @@ sf <- function(...) { invisible(structure(list(condition = e), class = "rprofile_error")) }) } + +yes_no <- function(..., na = NULL) { + # basically a rewrite of yesno::yesno() + msg <- paste0(..., collapse = "") + yes <- c("Yes", "You betcha", "Certainly", "Absolutely", "Of course") + no <- c("No", "Absolutely not", "Certainly not", "No way", "Not a chance", + "Let me think about it", "Not sure", "I don't know") + + choices <- c( + sample(c(sample(yes, 1), sample(no, 2))), + if (length(na)) sample(na, 1) + ) + + res <- utils::menu(title = msg, choices = choices) + if (res == 0) { + return(NA) + } + + res <- choices[res] + + if (res %in% yes) { + return(TRUE) + } + + if (res %in% no) { + return(FALSE) + } + + NA +} From 6c14bc3728103260fcf34c909923128b7427b203 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Fri, 14 Jun 2024 20:19:17 -0400 Subject: [PATCH 07/17] correct paths in .NewsUrls() --- R/news.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/news.R b/R/news.R index c202fb6..6985b0e 100644 --- a/R/news.R +++ b/R/news.R @@ -22,10 +22,11 @@ dir.exists(path) ) - news <- file.path(news, "NEWS.md") + pkg <- normalizePath(path, "/", TRUE) + news <- file.path(pkg, "NEWS.md") if (!file.exists(news)) { - stop("NEWS.md not found: ", news) + stop("NEWS.md not found: ", path) } force(url) From dbb790af3d26e3c8b88d8d980d909d8ae9206adf Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Fri, 14 Jun 2024 20:37:20 -0400 Subject: [PATCH 08/17] delint --- R/check-cran-status.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/check-cran-status.R b/R/check-cran-status.R index 8a97ed5..b4e1170 100644 --- a/R/check-cran-status.R +++ b/R/check-cran-status.R @@ -50,7 +50,11 @@ show_table <- function() { } get_recent_cran_check <- function() { - files <- list.files(tempdir(), "^dang_check_cran_status__.*\\.rds$", full.names = TRUE) + files <- list.files( + tempdir(), + "^dang_check_cran_status__.*\\.rds$", + full.names = TRUE + ) res <- files[which.max(file.mtime(files))] readRDS(res) } From 064d4592e07c7b3f759cabb798faddc55f90d168 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 30 Jun 2024 23:38:48 -0400 Subject: [PATCH 09/17] add global handlers --- NEWS.md | 1 + R/handle.R | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 R/handle.R diff --git a/NEWS.md b/NEWS.md index 65e6790..2400ec3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ * `@jmbarbone`'s preferred settings are now included as `.RprofileJordan()`, now a single command I can run in my `.Rprofile` * `.CheckCranStatus()` has simplified output when `{cli}` is available; linked included to packages [#8] * packing `lint`ing now included +* `.GlobalHandle()` added to call `rlang::global_handle()` ## Fixes diff --git a/R/handle.R b/R/handle.R new file mode 100644 index 0000000..d668a1b --- /dev/null +++ b/R/handle.R @@ -0,0 +1,9 @@ +#' Global handle +#' +#' See [rlang::global_handle()] +#' +#' @export +.GlobalHandle <- function() { + fuj::require_namespace("rlang") + rlang::global_handle() +} From 8c9ef88da8566cdc72d50041d1fb3e9aa1d0bed5 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 30 Jun 2024 23:39:16 -0400 Subject: [PATCH 10/17] import from fuj --- DESCRIPTION | 2 +- R/Rprofile-package.R | 2 ++ R/utils.R | 24 ------------------------ 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aeb8edb..6a3f1fe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ RoxygenNote: 7.3.1 Depends: R (>= 3.6.0) Imports: + fuj (>= 0.2.1), magrittr, utils Suggests: @@ -30,7 +31,6 @@ Suggests: devtools, fortunes, fs, - fuj (>= 0.2.1), gh, lintr, mark (>= 0.8.0), diff --git a/R/Rprofile-package.R b/R/Rprofile-package.R index 6002f5e..4e1ed23 100644 --- a/R/Rprofile-package.R +++ b/R/Rprofile-package.R @@ -1,4 +1,5 @@ #' @keywords internal +#' @importFrom fuj %||% %out% %colons% %wo% "_PACKAGE" # The following block is used by usethis to automatically manage @@ -26,6 +27,7 @@ lockEnvironment(rprofile) .AttachDevtools() .AddAttachedPackagesToDefaultPackages() .GitBranchPrompt() + .GlobalHandle() if (interactive()) { .UtilMessage("source_rprofile") diff --git a/R/utils.R b/R/utils.R index d326850..9312f97 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,27 +1,3 @@ -`%||%` <- function(x, y) { - if (is.null(x)) y else x -} - -`%colons%` <- function(package, name) { - # poor copy of fuj::`%colons%` - stopifnot( - length(package) == 1, - is.character(package), - length(name) == 1, is.character(name) - ) - - requireNamespace(package) - get(name, envir = asNamespace(package)) -} - -`%out%` <- function(...) { - ("fuj" %colons% "%out%")(...) -} - -`%wo%` <- function(...) { - ("fuj" %colons% "%wo%")(...) -} - assign_ <- function(...) { ("base" %colons% "assign")(...) } From 708688d4b8f51fbad839e4452c755dd8790f6953 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 30 Jun 2024 23:39:34 -0400 Subject: [PATCH 11/17] confirm release --- R/github-release.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/github-release.R b/R/github-release.R index b347ee7..5e24415 100644 --- a/R/github-release.R +++ b/R/github-release.R @@ -18,7 +18,7 @@ #' `FALSE`. #' @param prerelease Whether to create prerelease. Default is `FALSE`. #' @export -.GithubRelease <- function(publish = NULL, prerelease = FALSE) { +.GithubRelease <- function(publish = NULL, prerelease = NULL) { fuj::require_namespace("cli", "gh", "usethis") ask <- function() { if (!interactive()) { @@ -38,6 +38,17 @@ stop(fuj::new_condition("...", "forced_exit")) } + + if (is.null(prerelease)) { + if (ask()) { + prerelease <- yes_no("Is this a pre-release?") + } else { + prerelease <- FALSE + } + } + + prerelease <- isTRUE(prerelease) + if (!prerelease) { fuj::require_namespace("usethis") return(tryCatch( From 8525afc08ae2bf466878e7ebf8e4ccfdbbf30053 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 30 Jun 2024 23:42:08 -0400 Subject: [PATCH 12/17] normalize path in file open --- NEWS.md | 1 + R/open-file.R | 1 + 2 files changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 2400ec3..512f0b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,7 @@ * `.CheckCranStatus()` has simplified output when `{cli}` is available; linked included to packages [#8] * packing `lint`ing now included * `.GlobalHandle()` added to call `rlang::global_handle()` +* `.FileOpen()` now normalizes a path for a file before attempting to open ## Fixes diff --git a/R/open-file.R b/R/open-file.R index f306ef8..434a382 100644 --- a/R/open-file.R +++ b/R/open-file.R @@ -16,6 +16,7 @@ #' @rdname OpenFile .OpenFile.default <- function(x, force = FALSE, ...) { if (!force && isTRUE(.try(file.exists(x)))) { + x <- normalizePath(x, "/") requireNamespace("xopen") xopen::xopen(x) return(x) From 40535386bfee266090fe2834c8b83c06f3542d04 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 30 Jun 2024 23:42:17 -0400 Subject: [PATCH 13/17] add alias --- NAMESPACE | 6 ++++++ NEWS.md | 1 + R/open-file.R | 4 ++++ man/OpenFile.Rd | 3 +++ man/dot-GithubRelease.Rd | 2 +- man/dot-GlobalHandle.Rd | 11 +++++++++++ 6 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 man/dot-GlobalHandle.Rd diff --git a/NAMESPACE b/NAMESPACE index 5db31f6..660f94e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,12 +9,14 @@ export(.AddRprofileOptions) export(.AttachDevtools) export(.CharacterIndex) export(.CheckCranStatus) +export(.FileOpen) export(.FindRprofile) export(.Fixmes) export(.FixmesHere) export(.GitBranchPrompt) export(.GitPrepareCommitMsg) export(.GithubRelease) +export(.GlobalHandle) export(.LintFile) export(.NewsUrls) export(.NiceMessage) @@ -34,4 +36,8 @@ export(.SpellCheckFile) export(.Todos) export(.TodosHere) export(.UtilMessage) +importFrom(fuj,"%colons%") +importFrom(fuj,"%out%") +importFrom(fuj,"%wo%") +importFrom(fuj,"%||%") importFrom(magrittr,"%>%") diff --git a/NEWS.md b/NEWS.md index 512f0b8..003244f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,7 @@ * packing `lint`ing now included * `.GlobalHandle()` added to call `rlang::global_handle()` * `.FileOpen()` now normalizes a path for a file before attempting to open +* `.OpenFile()` added as an alias for `.FileOpen()` ## Fixes diff --git a/R/open-file.R b/R/open-file.R index 434a382..4ffe657 100644 --- a/R/open-file.R +++ b/R/open-file.R @@ -11,6 +11,10 @@ UseMethod(".OpenFile") } +#' @export +#' @rdname OpenFile +.FileOpen <- .OpenFile + #' @export #' @param force If `TRUE` ignores potential file path in `x` #' @rdname OpenFile diff --git a/man/OpenFile.Rd b/man/OpenFile.Rd index 4b62d84..f89be4c 100644 --- a/man/OpenFile.Rd +++ b/man/OpenFile.Rd @@ -3,6 +3,7 @@ \name{OpenFile} \alias{OpenFile} \alias{.OpenFile} +\alias{.FileOpen} \alias{.OpenFile.default} \alias{.OpenFile.data.frame} \alias{.OpenFile.matrix} @@ -10,6 +11,8 @@ \usage{ .OpenFile(x, ...) +.FileOpen(x, ...) + \method{.OpenFile}{default}(x, force = FALSE, ...) \method{.OpenFile}{data.frame}(x, ...) diff --git a/man/dot-GithubRelease.Rd b/man/dot-GithubRelease.Rd index 78b07c2..11c80ba 100644 --- a/man/dot-GithubRelease.Rd +++ b/man/dot-GithubRelease.Rd @@ -4,7 +4,7 @@ \alias{.GithubRelease} \title{Create a \strong{GitHub} Release} \usage{ -.GithubRelease(publish = NULL, prerelease = FALSE) +.GithubRelease(publish = NULL, prerelease = NULL) } \arguments{ \item{publish}{Whether to publish the release or keep as a draft. Default is diff --git a/man/dot-GlobalHandle.Rd b/man/dot-GlobalHandle.Rd new file mode 100644 index 0000000..871b6da --- /dev/null +++ b/man/dot-GlobalHandle.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/handle.R +\name{.GlobalHandle} +\alias{.GlobalHandle} +\title{Global handle} +\usage{ +.GlobalHandle() +} +\description{ +See \code{\link[rlang:global_handle]{rlang::global_handle()}} +} From 6b58dbd57dd876bf272c03249e5f106682a7edd8 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Mon, 1 Jul 2024 23:59:38 -0400 Subject: [PATCH 14/17] typo --- R/github-release.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/github-release.R b/R/github-release.R index 5e24415..8a746dd 100644 --- a/R/github-release.R +++ b/R/github-release.R @@ -6,7 +6,7 @@ #' `usethis::use_github_release()` is employed to create a prerelease. This #' assumes ... #' - the package is hosted on **GitHub** -#' - the remote is named **origin**d +#' - the remote is named **origin** #' - the branch is named **main** #' - the package has a **DESCRIPTION** file which contains an appropriate #' `Package` name and `Version` From 32a941ef1fc484d7ee97740d171c1fd0cab7f1e6 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Mon, 1 Jul 2024 23:59:43 -0400 Subject: [PATCH 15/17] redoc --- man/dot-GithubRelease.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/dot-GithubRelease.Rd b/man/dot-GithubRelease.Rd index 11c80ba..8187985 100644 --- a/man/dot-GithubRelease.Rd +++ b/man/dot-GithubRelease.Rd @@ -21,7 +21,7 @@ When \code{prerelease} is \code{TRUE}, a facsimile of assumes ... \itemize{ \item the package is hosted on \strong{GitHub} -\item the remote is named \strong{origin}d +\item the remote is named \strong{origin} \item the branch is named \strong{main} \item the package has a \strong{DESCRIPTION} file which contains an appropriate \code{Package} name and \code{Version} From dafd9aa7865f3aa32b0df5486ad35b6f7200f39e Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Mon, 1 Jul 2024 23:59:46 -0400 Subject: [PATCH 16/17] redoc --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a3f1fe..9affab4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,12 +16,13 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Depends: R (>= 3.6.0) Imports: fuj (>= 0.2.1), magrittr, + rlang, utils Suggests: cli, From 76e006ce96e9f4172dff110143a5cdc7e202f54f Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Tue, 2 Jul 2024 23:47:35 -0400 Subject: [PATCH 17/17] add more news items --- NEWS.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 003244f..18b477b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,9 +15,15 @@ * `@jmbarbone`'s preferred settings are now included as `.RprofileJordan()`, now a single command I can run in my `.Rprofile` * `.CheckCranStatus()` has simplified output when `{cli}` is available; linked included to packages [#8] * packing `lint`ing now included -* `.GlobalHandle()` added to call `rlang::global_handle()` +* `.CheckCranStatus()` specifically sets temporary file for check status results +* `.CheckCranStatus()` outputs corrected +* `.GlobalHandle()` added to call `rlang::global_handle()`; added into `.RprofileJordan()` * `.FileOpen()` now normalizes a path for a file before attempting to open * `.OpenFile()` added as an alias for `.FileOpen()` +* `.RprofileJordan()` checks for additional library paths from envvars `R_LIBS_PAK` and `R_LIBS_SCRIBE` +* `.GithubRelease()` now prompts for both `publish` and `pre-release` params when they are not set +* `.NewsUrls()` paths corrected and no longer error in error +* `{fuj}` is now imported ## Fixes