Skip to content

Error occured when using Rscript command line tool to build a book in bookdown #592

Closed

Description

@psychelzh

Because of the cross-reference feature, I am using bookdown instead of rmarkdown to generate dynamic reports. I have more than one reports to generate, so I drafted an R script to call bookdown:render_book in a for loop to generate all the reports. Unfortunately, it errored. For simplicity, I build one minimal example:

The bookdown file to render (saved as index.Rmd):

---
title: "test"
output: html_document
---

```{r test}
ext_var
```

The build.R:

ext_var <- "test.html"
bookdown::render_book("index.Rmd", output_file = ext_var) # it will call `rmarkdown::render`.

When using following commands: Rscript build.R, it will generate the following error messages:

$ Rscript build.R
Error in rmarkdown::render(main, output_format, ..., clean = clean, envir = envir,  :
  'ext_var'
Calls: <Anonymous> -> render_cur_session -> <Anonymous>
Please delete _main.Rmd after you finish debugging the error.

Then I changed my build.R to use rmarkdown::render instead:

ext_var <- "test.html"
rmarkdown::render("index.Rmd", output_file = ext_var)

There won't be any error. So I guess there might be some issues to fix.

sessionInfo():

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RevoUtils_11.0.0     RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17    bookdown_0.7    digest_0.6.15   rprojroot_1.3-2 backports_1.1.2
 [6] magrittr_1.5    evaluate_0.10.1 stringi_1.1.7   rstudioapi_0.7  rmarkdown_1.10 
[11] tools_3.5.0     stringr_1.3.1   xfun_0.1        yaml_2.1.19     compiler_3.5.0 
[16] htmltools_0.3.6 knitr_1.20   

Activity

  1. psychelzh commented on Jun 16, 2018

    @psychelzh
    Author

    I guess all the environmental variables are lost when "knitting" the "R Markdown" files through bookdown in command line tool. Given that rmarkdown succeeded in tackling this issue, I guess it could be solved in bookdown, too.

  2. psychelzh commented on Jun 17, 2018

    @psychelzh
    Author

    Oh, it is my fault. The function bookdown::render_book has set the argument clean_envir as !interactive(). It is this behavior that causes the error. So I did a little modification to my index.Rmd, then it worked:

    ext_var <- "test.html"
    bookdown::render_book("index.Rmd", output_file = ext_var, clean_envir = FALSE)

    So close this.

  3. added this to the v0.8 milestone on Jun 17, 2018
  4. yihui commented on Jun 17, 2018

    @yihui
    Collaborator
  5. psychelzh commented on Jun 17, 2018

    @psychelzh
    Author

    Okay, thanks!

  6. dmanuge commented on Dec 18, 2018

    @dmanuge

    @psychelzh I was searching the web/debugging for 24 hours until I came across your post. I was getting an error that the name of my file to be rendered (e.g. 'index.Rmd') was missing, followed by this:

    <Anonymous> -> <Anonymous> -> resolve -> basename

    Basically, I am calling "Rscript" multiple times to render N reports, and when I ran them independently, I had no errors, but then when calling them through a system command, I had the above error.

    Thanks for sharing this. I skipped over this argument in the render_book docs.

  7. github-actions commented on Nov 6, 2020

    @github-actions

    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.

  8. locked as resolved and limited conversation to collaborators on Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions