@@ -11,13 +11,15 @@ import { rBinaryPath, resourcePath } from "./resources.ts";
1111import { readYamlFromString } from "./yaml.ts" ;
1212import { coerce , satisfies } from "semver/mod.ts" ;
1313import { debug } from "../deno_ral/log.ts" ;
14+ import { isWindows } from "../deno_ral/platform.ts" ;
1415
1516export 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 ( / - - - Y A M L _ S T A R T - - - ( .* ) - - - Y A M L _ E N D - - - / 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 (
0 commit comments