Fix vignette build on Windows: forward-slash bib path#13
Open
VincentGuyader wants to merge 1 commit intomainfrom
Open
Fix vignette build on Windows: forward-slash bib path#13VincentGuyader wants to merge 1 commit intomainfrom
VincentGuyader wants to merge 1 commit intomainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
```
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
À 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` :
```
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.