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

don't allow the use of targets made available by create_bindings() during knitting #174

Open
fmichonneau opened this issue Aug 31, 2017 · 2 comments

Comments

@fmichonneau
Copy link
Contributor

I don't know if it's technically possible, but I noticed that if I knit a manuscript after invoking create_bindings(), then it will use the target in memory even if they are not explicitly listed as dependencies of the manuscript.

@krlmlr
Copy link
Collaborator

krlmlr commented Sep 3, 2017

Can you please be more specific?

@fmichonneau
Copy link
Contributor Author

With test.R:

foo <- function() {
    runif(1)
}


render <- function(f, ...) {
    rmarkdown::render(f, ...)
}

with manuscript.R:

---
title: test
---

The random number is `r target1`.

with remake.R:

sources:
  - test.R

targets:

  all:
    depends: manuscript.pdf

  target1:
    command: foo()

  manuscript.md:
    knitr: true

  manuscript.pdf:
    command: render("manuscript.md", output_format=I("pdf_document"))

The first time we attempt to generate the manuscript, it will fail as expected. The target manuscript.pdf doesn't explicitly depend on target1.

> make()
[  LOAD ] 
[  READ ]                |  # loading sources
<  MAKE > all
[  KNIT ] manuscript.md  |  knitr::knit("manuscript.Rmd", "manuscript.md")
[  READ ]                |  # loading packages
Quitting from lines 2-5 (manuscript.Rmd) 
Restoring previous version of manuscript.md
Error in eval(parse_only(code[i]), envir = envir) : 
  object 'target1' not found

Realistically, in a large project, at some point, I will have created target1 to inspect it before including it in the manuscript, and this works as expected:

> make("target1")
<  MAKE > target1
[ BUILD ] target1        |  target1 <- foo()

At this point, if I try to build the manuscript, it will still fail (the target has been built, but the manuscript doesn't explicitly depend on it):

> make()
<  MAKE > all
[  KNIT ] manuscript.md  |  knitr::knit("manuscript.Rmd", "manuscript.md")
Quitting from lines 2-5 (manuscript.Rmd) 
Restoring previous version of manuscript.md
Error in eval(parse_only(code[i]), envir = envir) : 
  object 'target1' not found

If I use create_bindings(), target1 is available in memory, and therefore, the manuscript builds without issue, while I would expect a similar error message as previously:

> create_bindings()
> make()
<  MAKE > all
[  KNIT ] manuscript.md  |  knitr::knit("manuscript.Rmd", "manuscript.md")
[ BUILD ] manuscript.pdf |  render("manuscript.md", output_format = "pdf_doc...
/usr/bin/pandoc +RTS -K512m -RTS manuscript.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output manuscript.pdf --template /home/francois/.R/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' 

Output created: manuscript.pdf
[ ----- ] all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants