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

Dependencies are not picked up in Quarto Book when chunk eval is using an expression #1816

Closed
DavZim opened this issue Feb 9, 2024 · 3 comments
Labels
dependencies 👶 feature a feature request or enhancement

Comments

@DavZim
Copy link

DavZim commented Feb 9, 2024

I have created a new and empty Quarto Book (RStudio IDE: New Project -> Quarto Book -> tick "use renv") which uses expressions in eval, for example

```{r}
#| eval: !expr knitr::is_html_output()
# this is run only in the html version
# alternatively knitr::is_latex_output() for code that is only run in the pdf output
```

The issue is that packages that are only used in the chunks with eval expressions are not picked up by renv.
Eg in the newly created quarto book, I have this index.qmd (other files are unchanged):

# Preface {.unnumbered}

```{r}
#| eval: !expr knitr::is_html_output()

# This is not picked up
tibble::tibble(x = 1:3, y = 3:1)
```

```{r}
# this is picked up correctly
data.table::datab.table(x = 1:3, y = 3:1)
```

When I run renv::dependencies(), I get this output:

> renv::dependencies()
Finding R package dependencies ... Done!
                                  Source    Package Require Version   Dev
1   /home/dazimme/temp-tester2/index.qmd data.table                 FALSE
2   /home/dazimme/temp-tester2/index.qmd  rmarkdown                 FALSE
3   /home/dazimme/temp-tester2/intro.qmd  rmarkdown                 FALSE
4   /home/dazimme/temp-tester2/renv.lock       renv                 FALSE
5 /home/dazimme/temp-tester2/summary.qmd  rmarkdown                 FALSE

which shows that the tibble dependency is not picked up.
I would expect that tibble is also picked up as it is used.

I am using renv version 1.0.3 (latest on CRAN at the time of writing).

@kevinushey kevinushey added feature a feature request or enhancement dependencies 👶 labels Feb 9, 2024
@kevinushey
Copy link
Collaborator

Thanks for the bug report. renv tries to skip parsing chunks for dependencies when eval is non-TRUE, or is set to a non-constant value which would require evaluation.

Perhaps we should consider some subset of eval expressions which we would consider safe to evaluate?

@DavZim
Copy link
Author

DavZim commented Feb 10, 2024

Isn't the opposite better, if eval is not false, evaluate the dependencies of the chunk. That should be an easy fix that should catch most use cases with some false positives (but I think renv detecting too many dependencies is better than it detecting too few).

@kevinushey
Copy link
Collaborator

That's a good point -- on the balance, I think you're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies 👶 feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants