Skip to content

Commit 829a277

Browse files
committed
fix(R): detect and warn about x64 R on Windows ARM
When x64 R fails on Windows ARM, parse YAML output to detect the architecture mismatch and provide a specific error message with ARM64 R download links instead of the generic "check your R installation" message. Also adds platform information to quarto check output with warning when x64 R is detected on ARM Windows.
1 parent d96d9da commit 829a277

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/core/knitr.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { rBinaryPath, resourcePath } from "./resources.ts";
1111
import { readYamlFromString } from "./yaml.ts";
1212
import { coerce, satisfies } from "semver/mod.ts";
1313
import { debug } from "../deno_ral/log.ts";
14+
import { isWindows } from "../deno_ral/platform.ts";
1415

1516
export interface KnitrCapabilities {
1617
versionMajor: number;
1718
versionMinor: number;
1819
versionPatch: number;
1920
home: string;
2021
libPaths: string[];
22+
platform?: string;
2123
packages: KnitrRequiredPackages;
2224
}
2325

@@ -115,6 +117,42 @@ export async function knitrCapabilities(rBin: string | undefined) {
115117
if (result.stderr) {
116118
debug(` with stderr from R:\n${result.stderr}`);
117119
}
120+
121+
// Check if this is x64 R on Windows ARM
122+
if (result.stdout) {
123+
try {
124+
const yamlMatch = result.stdout.match(/--- YAML_START ---(.*)--- YAML_END ---/s);
125+
if (yamlMatch) {
126+
const yamlLines = yamlMatch[1];
127+
const caps = readYamlFromString(yamlLines) as KnitrCapabilities;
128+
129+
if (caps.platform) {
130+
const isWindowsArm = isWindows && Deno.build.arch === "aarch64";
131+
const isX64R = caps.platform.includes("x86_64") || caps.platform.includes("i386");
132+
133+
if (isWindowsArm && isX64R) {
134+
throw new Error(
135+
"x64 R detected on Windows ARM.\n\n" +
136+
"x64 R runs under emulation and is not reliable for Quarto.\n" +
137+
"Please install native ARM64 R:\n" +
138+
" Download: https://www.r-project.org/nosvn/winutf8/aarch64/R-4-signed/\n" +
139+
" RTools: https://cran.r-project.org/bin/windows/Rtools/rtools45/files/\n\n" +
140+
"After installation, set QUARTO_R environment variable:\n" +
141+
" set QUARTO_R=C:\\Program Files\\R-aarch64\\R-4.5.0\\bin\\Rscript.exe"
142+
);
143+
}
144+
}
145+
}
146+
} catch (e) {
147+
// If it's our specific x64-on-ARM error, rethrow it
148+
if (e instanceof Error && e.message.includes("x64 R detected")) {
149+
throw e;
150+
}
151+
// Otherwise YAML parse failed, continue to return undefined
152+
debug(" Failed to parse YAML for architecture detection");
153+
}
154+
}
155+
118156
return undefined;
119157
}
120158
} catch {
@@ -136,6 +174,20 @@ export function knitrCapabilitiesMessage(caps: KnitrCapabilities, indent = "") {
136174
for (const path of caps.libPaths) {
137175
lines.push(` - ${path}`);
138176
}
177+
178+
// Show platform information if available
179+
if (caps.platform) {
180+
lines.push(`Platform: ${caps.platform}`);
181+
182+
// Check for x64 R on Windows ARM and show warning
183+
const isWindowsArm = isWindows && Deno.build.arch === "aarch64";
184+
const isX64R = caps.platform.includes("x86_64") || caps.platform.includes("i386");
185+
if (isWindowsArm && isX64R) {
186+
lines.push(`⚠️ WARNING: x64 R on Windows ARM is not supported`);
187+
lines.push(` Install ARM64 R: https://www.r-project.org/nosvn/winutf8/aarch64/R-4-signed/`);
188+
}
189+
}
190+
139191
lines.push(`knitr: ${caps.packages.knitr || "(None)"}`);
140192
if (caps.packages.knitr && !caps.packages.knitrVersOk) {
141193
lines.push(

src/resources/capabilities/knitr.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cat("libPaths:\n")
88
for (lib in .libPaths()) {
99
cat(paste0(' - ', shQuote(lib)), "\n")
1010
}
11+
cat("platform:", R.version[['platform']], "\n")
1112
cat("packages:\n")
1213
cat(" knitr: ")
1314
if (requireNamespace("knitr", quietly = TRUE)) {

0 commit comments

Comments
 (0)