Skip to content

Commit fb6e390

Browse files
authored
Prefer rlang::is_interactive(), is_string(), and seq2() to our DIY versions (#1084)
* Prefer rlang::is_interactive() to our DIY version Closes #1082 * Prefer rlang::is_string() to our DIY version * Prefer rlang::seq2() to our DIY version
1 parent d97adff commit fb6e390

37 files changed

+84
-88
lines changed

R/addin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @inheritParams use_template
1010
#'
1111
#' @export
12-
use_addin <- function(addin = "new_addin", open = interactive()) {
12+
use_addin <- function(addin = "new_addin", open = rlang::is_interactive()) {
1313
addin_dcf_path <- proj_path("inst", "rstudio", "addins.dcf")
1414

1515
if (!file_exists(addin_dcf_path)) {

R/ci.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NULL
2121
#' https://travis-ci.com. Change to `"org"` for https://travis-ci.org.
2222
#' @export
2323
#' @rdname ci
24-
use_travis <- function(browse = interactive(), ext = c("com", "org")) {
24+
use_travis <- function(browse = rlang::is_interactive(), ext = c("com", "org")) {
2525
check_uses_github()
2626
ext <- arg_match(ext)
2727
new <- use_template(
@@ -51,7 +51,7 @@ use_travis_badge <- function(ext = c("com", "org")) {
5151
use_badge("Travis build status", url, img)
5252
}
5353

54-
travis_activate <- function(browse = interactive(), ext = c("com", "org")) {
54+
travis_activate <- function(browse = is_interactive(), ext = c("com", "org")) {
5555
ext <- arg_match(ext)
5656
url <- glue("https://travis-ci.{ext}/profile/{github_owner()}")
5757

@@ -85,7 +85,7 @@ check_uses_travis <- function(base_path = proj_get()) {
8585
#' integration service for Windows.
8686
#' @export
8787
#' @rdname ci
88-
use_appveyor <- function(browse = interactive()) {
88+
use_appveyor <- function(browse = rlang::is_interactive()) {
8989
check_uses_github()
9090

9191
new <- use_template("appveyor.yml", ignore = TRUE)
@@ -99,7 +99,7 @@ use_appveyor <- function(browse = interactive()) {
9999
invisible(TRUE)
100100
}
101101

102-
appveyor_activate <- function(browse = interactive()) {
102+
appveyor_activate <- function(browse = is_interactive()) {
103103
url <- "https://ci.appveyor.com/projects/new"
104104
ui_todo("Turn on AppVeyor for this repo at {url}")
105105
if (browse) {
@@ -179,7 +179,7 @@ check_uses_gitlab_ci <- function(base_path = proj_get()) {
179179
#' `rocker/r-ver:3.5.3`.
180180
#' @export
181181
#' @rdname ci
182-
use_circleci <- function(browse = interactive(), image = "rocker/verse:latest") {
182+
use_circleci <- function(browse = rlang::is_interactive(), image = "rocker/verse:latest") {
183183
check_uses_github()
184184
use_directory(".circleci", ignore = TRUE)
185185
new <- use_template(
@@ -210,7 +210,7 @@ use_circleci_badge <- function() {
210210
use_badge("CircleCI build status", url, img)
211211
}
212212

213-
circleci_activate <- function(browse = interactive()) {
213+
circleci_activate <- function(browse = is_interactive()) {
214214
url <- glue("https://circleci.com/add-projects/gh/{github_owner()}")
215215

216216
ui_todo("Turn on CircleCI for your repo at {url}")

R/course.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use_course <- function(url, destdir = getOption("usethis.destdir")) {
6363
destdir <- user_path_prep(destdir %||% conspicuous_place())
6464
check_path_is_directory(destdir)
6565

66-
if (destdir_not_specified && interactive()) {
66+
if (destdir_not_specified && is_interactive()) {
6767
ui_line(c(
6868
"Downloading into {ui_path(destdir)}.",
6969
"Prefer a different location? Cancel, try again, and specify {ui_code('destdir')}"
@@ -87,7 +87,7 @@ use_course <- function(url, destdir = getOption("usethis.destdir")) {
8787
#' @export
8888
use_zip <- function(url,
8989
destdir = getwd(),
90-
cleanup = if (interactive()) NA else FALSE) {
90+
cleanup = if (rlang::is_interactive()) NA else FALSE) {
9191
url <- normalize_url(url)
9292
check_path_is_directory(destdir)
9393
ui_done("Downloading from {ui_value(url)}")
@@ -295,7 +295,7 @@ download_url <- function(url,
295295
}
296296

297297
status <- try_download(url, destfile, handle = handle)
298-
if (inherits(status, "error") && interactive()) {
298+
if (inherits(status, "error") && is_interactive()) {
299299
ui_oops(status$message)
300300
if (ui_nope("
301301
Download failed :(
@@ -366,7 +366,7 @@ tidy_unzip <- function(zipfile, cleanup = FALSE) {
366366
)
367367

368368
if (isNA(cleanup)) {
369-
cleanup <- interactive() &&
369+
cleanup <- is_interactive() &&
370370
ui_yeah("Shall we delete the ZIP file ({ui_path(zipfile, base_path)})?")
371371
}
372372

@@ -375,7 +375,7 @@ tidy_unzip <- function(zipfile, cleanup = FALSE) {
375375
file_delete(zipfile)
376376
}
377377

378-
if (interactive()) {
378+
if (is_interactive()) {
379379
rproj_path <- dir_ls(target, regexp = "[.]Rproj$")
380380
if (length(rproj_path) == 1 && rstudioapi::hasFun("openProject")) {
381381
ui_done("Opening project in RStudio")

R/cran.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#'
1010
#' @export
1111
#' @inheritParams use_template
12-
use_cran_comments <- function(open = interactive()) {
12+
use_cran_comments <- function(open = rlang::is_interactive()) {
1313
check_is_package("use_cran_comments()")
1414
use_template(
1515
"cran-comments.md",

R/create.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ create_package <- function(path,
3333
rstudio = rstudioapi::isAvailable(),
3434
roxygen = TRUE,
3535
check_name = TRUE,
36-
open = interactive()) {
36+
open = rlang::is_interactive()) {
3737
path <- user_path_prep(path)
3838
check_path_is_directory(path_dir(path))
3939

@@ -69,7 +69,7 @@ create_package <- function(path,
6969
#' @rdname create_package
7070
create_project <- function(path,
7171
rstudio = rstudioapi::isAvailable(),
72-
open = interactive()) {
72+
open = rlang::is_interactive()) {
7373
path <- user_path_prep(path)
7474
name <- path_file(path)
7575
check_not_nested(path_dir(path), name)
@@ -167,7 +167,7 @@ create_from_github <- function(repo_spec,
167167
destdir = NULL,
168168
fork = NA,
169169
rstudio = NULL,
170-
open = interactive(),
170+
open = rlang::is_interactive(),
171171
protocol = git_protocol(),
172172
credentials = NULL,
173173
auth_token = github_token(),

R/data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ check_files_absent <- function(paths, overwrite) {
113113
#' \dontrun{
114114
#' use_data_raw("daisy")
115115
#' }
116-
use_data_raw <- function(name = "DATASET", open = interactive()) {
116+
use_data_raw <- function(name = "DATASET", open = rlang::is_interactive()) {
117117
stopifnot(is_string(name))
118118
r_path <- path("data-raw", asciify(name), ext = "R")
119119
use_directory("data-raw", ignore = TRUE)

R/edit.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#' created. If the parent directory does not exist, it is also created.
66
#'
77
#' @param path Path to target file.
8-
#' @param open If, `NULL`, the default, will open the file when in an
9-
#' interactive environment that is not running tests. Use `TRUE` or
10-
#' `FALSE` to override the default.
8+
#' @param open Whether to open the file for interactive editing.
119
#' @return Target path, invisibly.
1210
#' @export
1311
#' @keywords internal
@@ -17,13 +15,11 @@
1715
#' edit_file("DESCRIPTION")
1816
#' edit_file("~/.gitconfig")
1917
#' }
20-
edit_file <- function(path, open = NULL) {
18+
edit_file <- function(path, open = rlang::is_interactive()) {
2119
path <- user_path_prep(path)
2220
create_directory(path_dir(path))
2321
file_create(path)
2422

25-
open <- open %||% (interactive() && !is_testing())
26-
2723
if (open) {
2824
ui_todo("Modify {ui_path(path)}")
2925

R/git.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use_git <- function(message = "Initial commit") {
3030
}
3131

3232
git_ask_commit <- function(message, untracked = FALSE) {
33-
if (!interactive() || !uses_git()) {
33+
if (!is_interactive() || !uses_git()) {
3434
return(invisible())
3535
}
3636

@@ -182,7 +182,7 @@ use_git_config <- function(scope = c("user", "project"), ...) {
182182
git_protocol <- function() {
183183
protocol <- getOption(
184184
"usethis.protocol",
185-
default = if (interactive()) NA else "ssh"
185+
default = if (is_interactive()) NA else "ssh"
186186
)
187187

188188
## this is where a user-supplied protocol gets checked, because
@@ -227,8 +227,7 @@ use_git_protocol <- function(protocol) {
227227
}
228228

229229
choose_protocol <- function() {
230-
## intercept with our internal interactive()
231-
if (!interactive()) {
230+
if (!is_interactive()) {
232231
return(invisible())
233232
}
234233
choices <- c(

R/github.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use_github <- function(organisation = NULL,
5858
repo_desc <- project_data()$Title %||% ""
5959
repo_desc <- gsub("\n", " ", repo_desc)
6060

61-
if (interactive()) {
61+
if (is_interactive()) {
6262
ui_todo("Check title and description")
6363
ui_code_block(
6464
"

R/helpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ version_spec <- function(x) {
9595
numeric_version(x)
9696
}
9797

98-
view_url <- function(..., open = interactive()) {
98+
view_url <- function(..., open = is_interactive()) {
9999
url <- paste(..., sep = "/")
100100
if (open) {
101101
ui_done("Opening URL {ui_value(url)}")

0 commit comments

Comments
 (0)