Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
otoomet opened this issue Oct 18, 2024 · 1 comment
Closed
3 tasks done

Comments

@otoomet
Copy link

otoomet commented Oct 18, 2024

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

  • I have fully read the issue guide at https://yihui.org/issue/.
  • 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.
  • 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.

@yihui yihui closed this as completed in a4a8288 Nov 4, 2024
@yihui
Copy link
Owner

yihui commented Nov 4, 2024

Thanks for the suggestion! Invalid dependson values will no longer trigger an error, and a warning message will be issued.

Accidentally, dependson = file.info("test.rmd") will work fine, even though you meant to use cache.extra (the chunk option name doesn't matter; it's the value that matters for caching).

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

No branches or pull requests

2 participants