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

Setting eval = FALSE globally doesn't comment R code when purl()-ing #2103

Closed
cderv opened this issue Feb 3, 2022 · 2 comments
Closed

Setting eval = FALSE globally doesn't comment R code when purl()-ing #2103

cderv opened this issue Feb 3, 2022 · 2 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Feb 3, 2022

Related to discussion for mlverse/torch#765

It seems like setting

knitr::opts_chunk$set(eval = FALSE)

in a vignette will make chunks NOT be included for execution in the resulting R scripts. This means like the vignette on CRAN will be checked by running purl then executing the R file which will error (as the chunks are not made to be run on CRAN).

If the options is set on the chunk it is taken into account it seems

if (isFALSE(options$eval)) code = comment_out(code, '# ', newline = FALSE)

Is this expected ?
vweave and vtangle of knitr are not the easiest to understand. So maybe I am missing something

cc @dfalbel

@yihui
Copy link
Owner

yihui commented Mar 4, 2022

This is indeed difficult to understand or explain. In short, personally I'm against the idea of checking the R scripts generated from vignettes during R CMD check: https://stat.ethz.ch/pipermail/r-devel/2014-May/069113.html but R core didn't agree with me.

Since purl() can't reliably generate a script that is equivalent to the code actually executed by knit() (because purl() doesn't run any code, e.g., it wouldn't run opts_chunk$set() in code chunks), I had three hacks in knitr to address the problem.

First, the R script is actually generated by hook_purl() instead of purl():

hook_purl = function(before, options, envir) {

knit_hooks$set(purl = hook_purl) # write out code while weaving

hook_purl() is executed during knit(), so it's aware of things like opts_chunk$set(). I don't know why it didn't work for torch package vignettes.

Second, I have tried to disable regenerating R scripts during R CMD check:

# a hack to generate an empty R script to cheat R CMD check because purl() is
# not reliable (#2052, #2036)
if (xfun::is_R_CMD_check() && !file.exists(with_ext(file, 'Rout.save'))) {
file = with_ext(file, '.R')
file.create(file)
return(file)
}

I don't know why it didn't work for torch. There was a brief regression 87d094a but I think it should be very unlikely that the problem was caused by this regression (it only existed for one day---introduced in knitr 1.35 and fixed in 1.36 released one day later).

Third, to truly disable generating R scripts from vignettes, package authors can use the *_notangle vignette engines, e.g.,

  %\VignetteEngine{knitr::rmarkdown_notangle}

https://yihui.org/knitr/demo/vignette/#vignette-engines

Anyway, I can't think of a possible explanation to the original problem. The error log has been deleted on CRAN, and I don't know what the error was now.

If we can reproduce this problem in a minimal example, we can investigate again. For now, I'm closing this issue since we haven't received any other similar reports. It's probably a transient issue. Thanks!

@yihui yihui closed this as completed Mar 4, 2022
@github-actions
Copy link

github-actions bot commented Sep 7, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants