Skip to content

Fix vignette build on Windows: forward-slash bib path#13

Open
VincentGuyader wants to merge 1 commit intomainfrom
fix/bib-windows-path
Open

Fix vignette build on Windows: forward-slash bib path#13
VincentGuyader wants to merge 1 commit intomainfrom
fix/bib-windows-path

Conversation

@VincentGuyader
Copy link
Copy Markdown
Member

Contexte

`R-CMD-check` était rouge uniquement sur `windows-latest (release)` :

```
--- re-building 'ac-create-bibliography-file.Rmd' using rmarkdown
Error in `file()`:
! cannot open the connection
Backtrace:

  1. └─knitr::write_bib(...)
  2. └─xfun::pkg_bib(..., prefix = prefix)
    ```

Cause (root cause, pas Windows-only par hasard)

`create_biblio_file()` substitue `tempdir()` dans le template Rmd `inst/templates/bibliography.Rmd`, à la place du marqueur `BIBPATH_HERE`. Sur Windows, `tempdir()` retourne un chemin avec des backslashes :

```
C:\Users\RUNNER~1\AppData\Local\Temp\RtmpIRUQ6m
```

Une fois écrit dans l'Rmd, le chunk devient :

```r
knitr::write_bib(packages, file.path("C:\Users\RUNNER~1\AppData\Local\Temp\RtmpIRUQ6m", 'packages.bib'))
```

Au moment où knitr ré-évalue le chunk, R parse `\U` / `\R` / `\T` comme des échappements Unicode invalides → `xfun::pkg_bib` n'arrive pas à ouvrir le fichier de sortie.

Vérifié localement :

```r

path <- "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\RtmpIRUQ6m"
parse(text = sprintf('file.path("%s", "packages.bib")', path))
PARSE ERR: '\U' used without hex digits in character string
```

À noter qu'il y avait déjà une tentative de fix commentée dans le source : `# escape \` (`R/bibliography.R:79-80`).

Fix

Convertir les backslashes en forward-slashes avant la substitution :

```r
replacement = paste0('"', gsub("\\\\", "/", dir_temp), '"')
```

R accepte les chemins en forward-slash sur Windows, et c'est un no-op sur Linux/macOS.

Tests

Ajout de `tests/testthat/test-bibliography.R` :

  • `create_biblio_file substitutes BIBPATH with forward slashes` : feed un chemin Windows-like (`C:\Users\...`), vérifie que la substitution ne contient plus de backslash et que la chaîne se parse sans erreur.
  • `create_biblio_file produces an html bibliography` : smoke test bout-en-bout (rendu réel) qui vérifie que `bibliography.html` est bien produit.

```

devtools::test()
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 9 ]
```

Reproduction exacte du chemin Windows-only impossible depuis ce runner Linux, mais le test unitaire ré-exerce précisément la chaîne de substitution qui causait le crash.

create_biblio_file() interpolated tempdir() into the bibliography Rmd
template as-is. On Windows, tempdir() returns a path with backslashes
(e.g. "C:\Users\RUNNER~1\AppData\..."). Once that path landed in the
Rmd, the chunk re-evaluating it tripped over substrings like \U, \R,
\T, which R parses as Unicode escapes — yielding `Error in file():
cannot open the connection` from xfun::pkg_bib at vignette build time.

Convert backslashes to forward slashes before substitution. R accepts
forward-slash paths on Windows, so the resulting string is a valid
file path on every OS. (There was already a commented-out attempt at
this same fix in the source: `# escape \`.)

Add a unit test that asserts the substitution result parses cleanly
and contains no backslash, plus a smoke test that the html artifact is
produced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant