From b377bf25f65b2e08cd674e6b0cf978d9d1597eda Mon Sep 17 00:00:00 2001 From: Alan Yeung Date: Mon, 11 Nov 2024 20:48:48 +0000 Subject: [PATCH 1/3] rstudio version check bug fix --- R/new_script.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/new_script.R b/R/new_script.R index 795855a..4fd3c0d 100644 --- a/R/new_script.R +++ b/R/new_script.R @@ -33,9 +33,17 @@ new_script <- function() { r_code <- paste0(r_code_part1, r_code_part2, collapse = "") } - if (!is.null(author) && rstudioapi::getVersion() >= 1.2) { + dated_version <- grepl("[0-9]{4}\\.[0-9]+\\.", rstudioapi::getVersion()) + + if (dated_version) { + required_version <- TRUE + } else { + required_version <- rstudioapi::getVersion() >= 1.2 + } + + if (!is.null(author) && required_version) { invisible(rstudioapi::documentNew(r_code, type = "r")) - } else if (!is.null(author) && rstudioapi::getVersion() < 1.2) { + } else if (!is.null(author) && !required_version) { filename <- rstudioapi::showPrompt( title = "Filename", message = "Filename for new script\nYou can choose a folder to store this in after this", From d97380e999eb96df0385984b848adccddf706146 Mon Sep 17 00:00:00 2001 From: alan-y Date: Mon, 11 Nov 2024 20:50:13 +0000 Subject: [PATCH 2/3] Style code (GHA) --- R/new_script.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/new_script.R b/R/new_script.R index 4fd3c0d..8894c04 100644 --- a/R/new_script.R +++ b/R/new_script.R @@ -33,7 +33,7 @@ new_script <- function() { r_code <- paste0(r_code_part1, r_code_part2, collapse = "") } - dated_version <- grepl("[0-9]{4}\\.[0-9]+\\.", rstudioapi::getVersion()) + dated_version <- grepl("[0-9]{4}\\.[0-9]+\\.", rstudioapi::getVersion()) if (dated_version) { required_version <- TRUE From 36d2cec67d2094e7fdc000b17aed5b5fb4286b08 Mon Sep 17 00:00:00 2001 From: Alan Yeung Date: Tue, 12 Nov 2024 15:27:50 +0000 Subject: [PATCH 3/3] stop if no author --- R/new_script.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/new_script.R b/R/new_script.R index 8894c04..58db69c 100644 --- a/R/new_script.R +++ b/R/new_script.R @@ -14,6 +14,10 @@ new_script <- function() { default = Sys.info()[["user"]] ) + if (is.null(author)) { + stop("Please enter a name for the script author") + } + git <- rstudioapi::showQuestion( title = "Git", message = "Are you version controlling using git?", @@ -41,9 +45,9 @@ new_script <- function() { required_version <- rstudioapi::getVersion() >= 1.2 } - if (!is.null(author) && required_version) { + if (required_version) { invisible(rstudioapi::documentNew(r_code, type = "r")) - } else if (!is.null(author) && !required_version) { + } else { filename <- rstudioapi::showPrompt( title = "Filename", message = "Filename for new script\nYou can choose a folder to store this in after this",