-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
tidy=TRUE option not working in before_chapter_script when new_session=TRUE (knit and merge method) #1049
Comments
Hi, What tells you it is not working ? It works as expected when I tried. You did not provide a reproducible example so I needed to build one. I tried with bookdown-demo (https://github.com/rstudio/bookdown-demo) :
You will have a chunk correctly formated by mean(1 + 2) Remove the mean(
1 + 2
) So this is working fine. If it is not working for you, please follow the issue guide: Having a reproducible example will insure we can understand the problem bette and have all the required information: there is many configuration you can set in a bookdown project! |
Just a confirmation. Do you have in your new_session: true I think I can reproduce with this option set to TRUE. (A reproducible example would have been easier to follow here to find how you encountered the issue) |
I can confirm there is a bug with Knit and Merge approach ( We execute the It is why it works with Before the change in 581bb63, the This You will encounter this issue only with Knit and Merge approach. With One way to insert common elements in books chapter is to source the script for a chunk in your document directly, or use a child Rmd file. Several ways among them these 2
We'll think if this is something we can fix. This issue will only be encountered with option that @yihui did you have this side effect in mind when inserting the change in 581bb63 ? Is there any workaround we could find to also avoid this while keeping 581bb63 ? Otherwise, maybe we should advice to use child Rmd or sourcing R script in each docs as it is efficient and with less side effect as it is user controlled and not a feature we try to maintain. 😅 |
Sorry I didn't foresee this problem. Another workaround is to use
This seems to be a corner case that most users probably won't run into ( |
This confirms what I thought. Thank you ! |
Apologies for not providing a MWE. I really appreciate the help and the workaround. |
I believe this same issue is affecting
Is there an |
Are you using the last version of bookdown ? This is working for me when I had this in local({
hook_old <- knitr::knit_hooks$get("error") # save the old hook
error_handler_function <- function(x, options) {
# wrap x
x <- paste(strwrap(x,76), collapse="\n## ")
x <- paste(x,'\n',sep='')
# pass the new x to the old hook
hook_old(x, options)
}
knitr::knit_hooks$set(error = error_handler_function)
}) and this in before_chapter_script: dummy.R and this is ```{r, error = TRUE}
# to be wrap by the hook
err <- sample(c("a", " "), size = 100, replace = TRUE, prob = c(0.8,0.2))
stop(paste0(err, collapse = ""))
``` All this is not really issues with bookdown. If you still have questions, please ask on one of the Q&A site: https://yihui.org/issue/#got-a-question If you found a new issue, open a new one with a specific example to that issue. Having one topic per issue in Github is way easier for us. Thank you ! |
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. |
I'd like to automatically tidy all R code in the book I'm working on. The book already has a before_chapter_script, so I want to add this line to it:
knitr::opts_chunk$set(tidy=TRUE)
It seems to not be having an effect.
I do see tidying working when I add
tidy=TRUE
to a chunk as an option. It also works if I include the line above as the first chunk in the file.I also tried changing
tidy=TRUE
toecho=FALSE
in the before_chapter_script to see if it would do anything, and it does turn off all echoing.I can't imagine why this particular setting won't work while others do, so I'm posting here.
By filing an issue to this repo, I promise that
xfun::session_info('bookdown')
. 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('rstudio/bookdown')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: