remake icon indicating copy to clipboard operation
remake copied to clipboard

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

Open fmichonneau opened this issue 7 years ago • 2 comments

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.

fmichonneau avatar Aug 31 '17 22:08 fmichonneau

Can you please be more specific?

krlmlr avatar Sep 03 '17 20:09 krlmlr

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

fmichonneau avatar Sep 03 '17 22:09 fmichonneau