From 7ad6db74dfdc6348399675e2ff761e9b0d1d783b Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:35:09 +0100 Subject: [PATCH] Improve error message --- R/multi_irace.R | 4 ++-- R/path_rel2abs.R | 10 +++++----- man/path_rel2abs.Rd | 11 +++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/R/multi_irace.R b/R/multi_irace.R index f069f7dc..1280323b 100644 --- a/R/multi_irace.R +++ b/R/multi_irace.R @@ -68,7 +68,7 @@ multi_irace <- function(scenarios, parameters, n = 1L, parallel = 1, split_outpu # 'path/to/execDir' -> 'path/to/execDir/run_{i}'. execDir <- file.path(execDir_old, sprintf("run_%02d", i)) scenarios[[i]]$execDir <- execDir - if (!dir.exists(execDir)) dir.create(execDir, recursive = TRUE) + fs::dir_create(execDir) if (logFile_old != '') { logFile <- if (is.sub.path(logFile_old, execDir_old)) { @@ -82,7 +82,7 @@ multi_irace <- function(scenarios, parameters, n = 1L, parallel = 1, split_outpu # pathExt <- tools::file_ext(logFile_old) # pathWithoutExtWithIndex <- sprintf("%s_%02d", pathWithoutExt, i) # paste(pathWithoutExtWithIndex, pathExt, sep = ".") - irace.error("Invalid 'logFile' path: ", "The 'logFile' must be located inside the 'execDir'.") + irace.error("Invalid 'logFile' path (", logFile_old, "): ", "The 'logFile' must be located inside the 'execDir' (", execDir_old, ").") } scenarios[[i]]$logFile <- logFile } diff --git a/R/path_rel2abs.R b/R/path_rel2abs.R index 56cebb7b..f9d1262b 100644 --- a/R/path_rel2abs.R +++ b/R/path_rel2abs.R @@ -1,9 +1,9 @@ #' Converts a relative path to an absolute path. #' -#' It tries really hard to create canonical paths. If the path passed -#' corresponds to an executable, it tries to find its path using `Sys.which()`. -#' Expansion of `'~'` in Windows follows the definition of `fs::path_expand()` -#' rather than `base::path.expand()`. +#' If the path passed corresponds to an executable, it tries to find its path +#' using [Sys.which()]. Expansion of `'~'` in Windows follows the definition +#' of [fs::path_expand()] rather than [base::path.expand()]. This function +#' tries really hard to create canonical paths. #' #' @param path (`character(1)`) Character string representing a relative path. #' @param cwd (`character(1)`) Current working directory. @@ -31,5 +31,5 @@ path_rel2abs <- function (path, cwd = getwd()) path <- as.vector(sys_path) } } - fs::path_abs(path, start = cwd) + as.character(fs::path_abs(path, start = cwd)) } diff --git a/man/path_rel2abs.Rd b/man/path_rel2abs.Rd index e7b562c5..19c85e1b 100644 --- a/man/path_rel2abs.Rd +++ b/man/path_rel2abs.Rd @@ -2,9 +2,7 @@ % Please edit documentation in R/path_rel2abs.R \name{path_rel2abs} \alias{path_rel2abs} -\title{Converts a relative path to an absolute path. It tries really hard to create -canonical paths. If the path passed corresponds to an executable, it tries -to find its path using \code{Sys.which()}.} +\title{Converts a relative path to an absolute path.} \usage{ path_rel2abs(path, cwd = getwd()) } @@ -17,9 +15,10 @@ path_rel2abs(path, cwd = getwd()) (\code{character(1)}) Character string representing the absolute path } \description{ -Converts a relative path to an absolute path. It tries really hard to create -canonical paths. If the path passed corresponds to an executable, it tries -to find its path using \code{Sys.which()}. +If the path passed corresponds to an executable, it tries to find its path +using \code{\link[=Sys.which]{Sys.which()}}. Expansion of \code{'~'} in Windows follows the definition +of \code{\link[fs:path_expand]{fs::path_expand()}} rather than \code{\link[base:path.expand]{base::path.expand()}}. This function +tries really hard to create canonical paths. } \examples{ path_rel2abs("..")