knitr icon indicating copy to clipboard operation
knitr copied to clipboard

Confusing error message when chunk option _dependson_ refers to `file.info()`

Open otoomet opened this issue 4 months ago • 0 comments

I (mistakenly) write a code chunk like

# Markdown

```{r, dependson = file.info("test.rmd")}
# Need `cache.extra =`, not `dependson =` here
# Note: need name of a file that actually exists
"hi there!"
```

(I call this file test.rmd and compile as

$ Rscript -e "knitr::knit('test.rmd')"

)

Unfortunately, knitr gives an incomprehensible error message:

processing file: test.rmd
Error in defaults[[name]] : subscript out of bounds
Calls: <Anonymous> ... get -> setNames -> resolve -> setNames -> <Anonymous>
Execution halted

I'd expect a message along the lines

Processing code chunk 1... Invalid chunk name for 'dependson' option at line 3.

(This seems only to happen if the file.info refers to an existing file, not to a non-existing file.)

Session info:

> xfun::session_info('knitr')
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 20.04.6 LTS

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  evaluate_1.0.1  graphics_4.4.1  grDevices_4.4.1 highr_0.11     
  knitr_1.48.6    methods_4.4.1   stats_4.4.1     tools_4.4.1    
  utils_4.4.1     xfun_0.48       yaml_2.3.10    

By filing an issue to this repo, I promise that

  • [x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

otoomet avatar Oct 18 '24 23:10 otoomet