Repository navigation
Closed
Description
I am trying to build different books with a kind of parameterized script:
library(tidyverse)
library(glue)
library(bookdown)
parameterized_book_render <- function(.title, .param1) {
outputdir <- "_book/PDF/{.title}/{.param1}" %>% glue()
parameters <- list(title = .title,
param1 = .param1)
bookdown::render_book("index.Rmd",
"bookdown::pdf_book",
output_dir = outputdir,
params = parameters)
}
data <-
tibble(title = c("title1", "title2"),
param1 = c("bla", "blubb"))
data %>%
pmap( ~ parameterized_book_render(..1,
..2))The script works perfectly when it's ran within RStudio.
However, in case I run the code with
Rscript build.RI get this error:
Error in output_dirname(output_dir, config) :
object 'outputdir' not found
Calls: %>% ... parameterized_book_render -> <Anonymous> -> output_dirname
Execution haltedI am also using a Docker container for building (see source code). I am getting exactly the same error there.
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('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'). - 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.
Reacted by Yihui Xie
Metadata
Metadata
Assignees
Labels
No labels
Activity
cderv commentedon Aug 25, 2020
That is strange. FWIW I can reproduce with something more minimal
it is always a good idea to reduce your example to the bare minimum for easier debugging.
cderv commentedon Aug 25, 2020
Oh yes! I always forgot about this one !
You need to set
clean_envir = FALSEinrender_book(). By default it is,clean_envir = !interactive(), hence the difference you see between interactive session and non interactive one. See https://bookdown.org/yihui/bookdown/build-the-book.htmlI let you try.
cderv commentedon Aug 25, 2020
Also for reference duplicate of #835 and #592
cderv commentedon Aug 25, 2020
@yihui It seems unfortunate that this kind of batch mode raise this issue silently. It would not happen I guess if the argument of
render_bookwould be evaluated (like usingforce()) before cleaning the environment. Or in this case if the part usingoutput_dirwould be run before cleaning.But indeed, workaround is pretty simple when you know it though, and it is document in the book.
jenslaufer commentedon Aug 26, 2020
Thanks so much; indeed
clean_envir = FALSEfixes the problem.So it's no bug or something.
fix #932: deprecate the clean_envir argument of render_book(), and us…
yihui commentedon Sep 9, 2020
In retrospect,
clean_envir = TRUEwas a really bad idea. Actually I have also been bitten by this issue by myself. Since it has bitten another person, I just deprecated this argument, and you no longer need it in the future. You may install and test the development version viaThanks for the report!
Catch up with rstudio version.
github-actions commentedon Mar 10, 2021
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.