Skip to content

Commit

Permalink
Code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Jan 22, 2024
1 parent 0876d74 commit 51c927f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly2
Title: Orderly Next Generation
Version: 1.99.10
Version: 1.99.11
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
21 changes: 14 additions & 7 deletions R/interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@ rstudio_get_current_active_editor_path <- function() {
##
## I am not sure if we also want to allow working interactively from a
## draft directory too.
detect_orderly_interactive_path <- function(path = getwd(),
editor_path = rstudio_get_current_active_editor_path()) {
detect_orderly_interactive_path <- function(
path = getwd(),
editor_path = rstudio_get_current_active_editor_path())
{
is_valid <- is_plausible_orderly_report(path)
suggested_wd <- NULL
if (!is.null(editor_path)) {
dir <- fs::path_dir(editor_path)
if (paths_are_different(dir, path) && is_plausible_orderly_report(dir)) {
if (!paths_are_identical(dir, path) && is_plausible_orderly_report(dir)) {
suggested_wd <- dir
}
}

if (!is_plausible_orderly_report(path)) {
msg <- c("Working directory {.path {path}} is not a valid orderly report.")
if (!is.null(suggested_wd)) {
cli::cli_abort(
c(msg, i = "Use {.code setwd({.str {suggested_wd}})} to set the working directory to the report currently open in RStudio."))
cli::cli_abort(c(msg, i = paste(
"Use {.code setwd({.str {suggested_wd}})} to set the working",
"directory to the report currently open in RStudio.")))
} else {
cli::cli_abort(msg)
}
Expand All @@ -47,8 +50,12 @@ detect_orderly_interactive_path <- function(path = getwd(),
# doesn't make individual bullet points available in the condition object.
# The following mimicks cli_abort more closely, making testing easier.
msg <- c(
cli::format_inline("Working directory {.path {path}} does not match the report currently open in RStudio."),
cli::format_inline(i = "Use {.code setwd({.str {suggested_wd}})} to switch working directories."))
cli::format_inline(paste(
"Working directory {.path {path}} does not match the report currently",
"open in RStudio.")),
cli::format_inline(i = paste(
"Use {.code setwd({.str {suggested_wd}})}",
"to switch working directories.")))
rlang::warn(msg, use_cli_format = TRUE)
}
as.character(fs::path_norm(file.path(path, "../..")))
Expand Down
8 changes: 2 additions & 6 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,8 @@ saverds_atomic <- function(data, path, allow_fail = FALSE) {
}


paths_are_different <- function(x, y) {
tryCatch({
x_real <- fs::path_real(x)
y_real <- fs::path_real(y)
x_real != y_real
}, error = function(e) FALSE)
paths_are_identical <- function(x, y) {
fs::path_norm(x) == fs::path_norm(y)
}


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-orderly.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
options(outpack.schema_validate =
requireNamespace("jsonvalidate", quietly = TRUE) &&
utils::packageVersion("jsonvalidate") >= "1.4.0",
packageVersion("jsonvalidate") >= "1.4.0",
orderly_index_progress = FALSE)


Expand Down

0 comments on commit 51c927f

Please sign in to comment.