From 78ad45790a6869573f9b577247f81b0ccc111cc4 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 2 Jun 2022 22:07:47 +0200 Subject: [PATCH 1/2] Add a specific handling of windows R binary in bin/ subfolder --- src/core/resources.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/resources.ts b/src/core/resources.ts index ac45215e220..fbb81a4e1f8 100644 --- a/src/core/resources.ts +++ b/src/core/resources.ts @@ -8,7 +8,7 @@ import { existsSync, walkSync } from "fs/mod.ts"; import { dirname, join } from "path/mod.ts"; import { warnOnce } from "./log.ts"; -import { which } from "./path.ts"; +import { safeExistsSync, which } from "./path.ts"; import { quartoConfig } from "./quarto.ts"; import { kHKeyCurrentUser, @@ -63,7 +63,13 @@ export async function rBinaryPath(binary: string): Promise { // if there is an R_HOME then respect that const rHome = Deno.env.get("R_HOME"); if (rHome) { - return join(rHome, "bin", binary); + let rHomeBin = join(rHome, "bin", binary); + if (safeExistsSync(rHomeBin)) return rHomeBin; + if (Deno.build.os === "windows") { + // Some installation have binaries in the sub folder only + rHomeBin = join(rHome, "bin", "x64", binary); + if (safeExistsSync(rHomeBin)) return rHomeBin; + } } // then check the path From 964620d91c50175258bcc0ccfde7e575d43ace9e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 3 Jun 2022 09:32:15 +0200 Subject: [PATCH 2/2] [windows] R is now found if several binaries in PATH This solves issue with some R intallation where several R version are on PATH but not in registry, e.g egde case with scoop. WHERE command on CMD will return full path to each file found, and not only one command like which on UNIX --- src/core/path.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/path.ts b/src/core/path.ts index 2578706fdae..45e58cc2fdf 100644 --- a/src/core/path.ts +++ b/src/core/path.ts @@ -95,7 +95,10 @@ export async function which(cmd: string) { { cmd: args, stderr: "piped", stdout: "piped" }, ); if (result.code === 0) { - return result.stdout?.trim(); + return Deno.build.os === "windows" + // WHERE return all files found, only first is kept + ? result.stdout?.split("\n")[0].trim() + : result.stdout?.trim(); } else { return undefined; }