Skip to content

regression: quarto preview of a knitr project doc fails when cwd is the doc's subdirectory (1.9.18+) #14683

Description

@kevinushey

Bug description

In a Quarto project, previewing a knitr-engine document that lives in a subdirectory fails when the working directory is that subdirectory and the input is passed by bare filename:

cd labs
quarto preview claudetest.qmd --to html --no-watch-inputs --no-browse
Error in rmarkdown:::abs_path(input) :
  The file 'claudetest.qmd' does not exist.
Calls: .main -> execute -> setwd -> dirname -> <Anonymous>
Execution halted
WARN: Error encountered when rendering files

This worked in Quarto 1.8.x and regressed between 1.9.17 and 1.9.18. It is the same failure reported in #14488 (closed as needs-repro/stale); there the suspicion was that an RStudio update had changed the command being run, but the repro below involves no IDE: the identical command in the identical working directory succeeds on 1.8.27 and 1.9.17 and fails on 1.9.18 and 1.9.38.

This is user-visible in RStudio because the IDE's Render button runs exactly this command shape (bare filename, cwd = the document's directory); see rstudio/rstudio#18197.

Steps to reproduce

Minimal website project:

testsite/
|-- _quarto.yml
|-- index.qmd
`-- labs/
    `-- claudetest.qmd

_quarto.yml:

project:
  type: website

website:
  title: "testsite"

labs/claudetest.qmd:

---
title: "Claude Test"
---

```{r}
1 + 1
```

Then:

cd testsite/labs
quarto preview claudetest.qmd --to html --no-watch-inputs --no-browse

Observed behavior

Version Result
1.8.27 works (renders, serves the page)
1.9.17 works
1.9.18 fails with the rmarkdown:::abs_path error above
1.9.38 fails (same error)

Additional data points, all on 1.9.38:

  • quarto render claudetest.qmd from labs/ works -- only preview is affected.
  • quarto preview labs/claudetest.qmd from the project root works.
  • Previewing a subdirectory document with no executable R code works -- only the knitr engine path is affected (markdown-engine docs never call rmarkdown:::abs_path).

So the trigger is specifically: preview + project + knitr engine + input path relative to a subdirectory working directory. The knitr subprocess receives the raw cwd-relative filename while its own working directory is no longer the invocation directory, so setwd(dirname(abs_path(input))) fails.

Suspected cause

Bisecting the release tarballs pins the regression to the 1.9.17 -> 1.9.18 window. The only preview/project-context change in git log v1.9.17..v1.9.18 is #13804 ("Manage projectcontext objects correctly on preview", merged 2026-01-22), which reworked src/command/preview/preview.ts and src/command/render/render-shared.ts so that render() receives a pre-built ProjectContext instead of resolving the input itself. That matches the observed symptom: the relative input path is no longer resolved against the invocation cwd before the engine runs.

Environment

  • macOS 26.5.2 (arm64)
  • R 4.5.3, rmarkdown 2.31, knitr 1.51
  • Quarto versions tested from the official release tarballs: 1.8.27, 1.9.17, 1.9.18, 1.9.38

Checklist

  • Reproduced with the latest release (1.9.38)
  • Minimal, self-contained reproduction included above

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreviewissues related to the `preview` command

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions