Skip to content

Bug report: Windows failure in system2() call to quarto -V due to environment handling #300

Description

@sshunsuke

Description

On Windows, Quarto availability/version checks fail during R CMD check and testthat runs due to an incorrect system2() invocation in the quarto R package.

The failure occurs even though:

  • quarto.exe exists on disk
  • Sys.which("quarto") returns the correct path
  • system2(Sys.which("quarto"), "--version") works interactively

The error indicates that an environment variable (TMPDIR=...) is being passed as a command-line argument, causing the Quarto CLI to interpret it as a subcommand.

The root cause was identified by tracing failing system2() calls during R CMD check on Windows, with assistance from Microsoft Copilot.


Error message

Observed during R CMD check / testthat on Windows:

ERROR: Unknown command "TMPDIR=C:/Users/UserName/AppData/Local/Temp/Rtmpm6j3m7/file42241e1d6052".
Did you mean command "install"?

Warning in system2("quarto", "-V", stdout = TRUE,
    env = paste0("TMPDIR=", ...)) :
  running command '"quarto" TMPDIR=C:/Users/UserName/AppData/Local/Temp/Rtmpm6j3m7/file42241e1d6052 -V' had status ...

Note the constructed command:

"quarto" TMPDIR=... -V

which is invalid for the Quarto CLI.


Minimal reproducible evidence

On the same Windows machine:

q <- Sys.which("quarto")
q
# "C:/Users/UserName/AppData/Local/Programs/Quarto/bin/quarto.exe"

system2(q, "--version")
# works

system2(
  "quarto",
  "-V",
  stdout = TRUE,
  env = paste0("TMPDIR=", tempdir())
)
# fails on Windows

This suggests that the environment variable is not being passed correctly to system2() on Windows.


Root cause (Windows-specific)

On Windows, system2() does not invoke a shell. Environment variables must be passed as a named character vector, for example:

env = c(TMPDIR = tmpdir)

Passing env = paste0("TMPDIR=", tmpdir) can result in the variable being treated as a positional argument, yielding:

quarto TMPDIR=... -V

which Quarto correctly rejects.


Expected behavior

On Windows, Quarto availability/version checks should:

  • Not fail when quarto.exe is present
  • Pass environment variables via env = c(NAME = value)
  • Avoid constructing commands where environment variables appear as CLI arguments

Platform

  • OS: Windows 11
  • R version: 4.5.2
  • quarto R package version: 1.5.1
  • Quarto CLI version: 1.8.27

Additional context

This issue appears similar to previously reported Windows failures involving Quarto during vignette rendering, but in this case it occurs during test execution (testthat), not during vignette building.


Suggested fix (conceptual)

Replace patterns like:

system2("quarto", "-V", env = paste0("TMPDIR=", tmpdir))

with:

system2("quarto", "-V", env = c(TMPDIR = tmpdir))

This should make the version check robust on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions