Skip to content

Commit 4927783

Browse files
committed
Fix short path portability
1 parent 995e36f commit 4927783

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

R/install.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ build_cmdstan <- function(dir,
454454
run_cmd <- make_cmd()
455455
}
456456
withr::with_envvar(
457-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
457+
c("HOME" = short_path(Sys.getenv("HOME"))),
458458
withr::with_path(
459459
c(
460460
toolchain_PATH_env_var(),
@@ -479,7 +479,7 @@ clean_cmdstan <- function(dir = cmdstan_path(),
479479
cores = getOption("mc.cores", 2),
480480
quiet = FALSE) {
481481
withr::with_envvar(
482-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
482+
c("HOME" = short_path(Sys.getenv("HOME"))),
483483
withr::with_path(
484484
c(
485485
toolchain_PATH_env_var(),
@@ -501,7 +501,7 @@ clean_cmdstan <- function(dir = cmdstan_path(),
501501

502502
build_example <- function(dir, cores, quiet, timeout) {
503503
withr::with_envvar(
504-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
504+
c("HOME" = short_path(Sys.getenv("HOME"))),
505505
withr::with_path(
506506
c(
507507
toolchain_PATH_env_var(),

R/model.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ compile <- function(quiet = TRUE,
664664
if (compile_standalone) {
665665
expose_stan_functions(self$functions, !quiet)
666666
}
667-
667+
668668
withr::with_envvar(
669-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
669+
c("HOME" = short_path(Sys.getenv("HOME"))),
670670
withr::with_path(
671671
c(
672672
toolchain_PATH_env_var(),

R/run.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ check_target_exe <- function(exe) {
411411
exe_path <- file.path(cmdstan_path(), exe)
412412
if (!file.exists(exe_path)) {
413413
withr::with_envvar(
414-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
414+
c("HOME" = short_path(Sys.getenv("HOME"))),
415415
withr::with_path(
416416
c(
417417
toolchain_PATH_env_var(),

R/utils.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ stanc_cmd <- function() {
107107

108108
# paths and extensions ----------------------------------------------------
109109

110+
short_path <- function(path) {
111+
if (os_is_windows()) {
112+
utils::shortPathName(path)
113+
} else {
114+
path
115+
}
116+
}
117+
110118
# Replace `\\` with `/` in a vector of paths
111119
# Needed for windows if CmdStan version is < 2.21:
112120
# https://github.com/stan-dev/cmdstanr/issues/1#issuecomment-539118598
@@ -693,7 +701,7 @@ assert_file_exists <- checkmate::makeAssertionFunction(check_file_exists)
693701
get_cmdstan_flags <- function(flag_name) {
694702
cmdstan_path <- cmdstanr::cmdstan_path()
695703
withr::with_envvar(
696-
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
704+
c("HOME" = short_path(Sys.getenv("HOME"))),
697705
flags <- wsl_compatible_run(
698706
command = "make",
699707
args = c("-s", paste0("print-", flag_name)),

0 commit comments

Comments
 (0)