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

option to hide child code warning #2191

Closed
3 tasks done
jwijffels opened this issue Oct 27, 2022 · 5 comments · Fixed by #2194
Closed
3 tasks done

option to hide child code warning #2191

jwijffels opened this issue Oct 27, 2022 · 5 comments · Fixed by #2194

Comments

@jwijffels
Copy link
Contributor

jwijffels commented Oct 27, 2022

Hello,

I would like to be able to have the option to remove this warning at

knitr/R/block.R

Lines 59 to 62 in ff3d767

if (!is_blank(params[['code']])) warning(
"The chunk '", params$label, "' has the 'child' option, ",
"and this code chunk must be empty. Its code will be ignored."
)

which generates something like this:

Warning message:
In call_block(x) :
  The chunk 'xyz' has the 'child' option, and this code chunk must be empty. Its code will be ignored.

Reason of this is I would like to have the possibility to have a chunk which looks as follows

```{r, label=xyz, child = "children/kind.Rmd"}
f  <- knitr::purl(input = "children/kind.Rmd", output = tempfile(fileext = ".R"), quiet = TRUE)
sc <- paste(readLines(f), collapse = "\n")
source(exprs = parse(text = sc), print.eval = TRUE)

My children/kind.Rmd generates a table (flextable::flextable) which is printed to html. It looks like this

```{r}
library(flextable)
tab <- flextable(head(iris))
tab

If I render this, it will remove the R code in the chunk but still execute the children/kind.Rmd. While if I don't include the 3 lines to extract the R code from the child Rmd and evaluate it, the RStudio Visual editor will not show it. Only if I include the 3 lines of code.

image

Would you be open to have a small pull request which basically adds something like this: !is_blank(params[['code']]) && getOption("knitr.hide.child.code.warning", default = FALSE)

If so, what would be the preferred option name that I can use in this pull request? knitr.hide.child.code.warning?

thanks


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
Copy link
Owner

yihui commented Nov 10, 2022

I guess you can put the code in another chunk with options eval = FALSE, include = FALSE, and leave the chunk with child empty. That way, you won't get the warning, and you can still run the code in RStudio.

@jwijffels
Copy link
Contributor Author

That's also true of course but making it 2 chunks just to be able to show it in RStudio as the RStudio Visual Editor does not execute the child documents when you click on that run button creates code duplication.

@yihui
Copy link
Owner

yihui commented Nov 11, 2022

Essentially what you really want is the ability to run a code chunk with the child option in the RStudio IDE. Ideally that should be supported by the IDE, but the IDE doesn't support the child option well currently, e.g., rstudio/rstudio#12208.

That said, I'm open to adding a global option to suppress this warning (perhaps a shorter option name like getOption('knitr.child.warning', TRUE)?). Please feel free to send a PR. Thanks!

@jwijffels
Copy link
Contributor Author

jwijffels commented Nov 11, 2022

Essentially what you really want is the ability to run a code chunk with the child option in the RStudio IDE.

Indeed, and I had the impression by skimming a bit online that this will not be supported in the near future. So that's why I ended up here.

Thanks. I'll create a pull request to add knitr.child.warning and keep the current default behaviour

yihui added a commit that referenced this issue Nov 19, 2022
…the there are child documents in a chunk and the chunk still contains code (which is not executed) (#2194)

Co-authored-by: Yihui Xie <[email protected]>
@github-actions
Copy link

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 May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants