-
Start an R session in this directory (
07-knitr
)- RStudio users, open the
*.Rproj
file in this directory
- RStudio users, open the
-
Build the project:
remake::make()
-
Fetch the ragout:
remake::fetch("ragout")
-
Create a new file
final.Rmd
in this directory, with the following contents:--- title: "Final cooking report" author: "<Your name>" output: rmarkdown::html_document --- ```{r init, echo = FALSE, message = FALSE} if (!isNamespaceLoaded("remake")) remake::create_bindings() ``` Look at the ragout I made today: ```{r} ragout ``` I combined fried meat and vegetables: ```{r} fried_meat cooked_potatoes peeled_carrots ``` Some of the components were more difficult to prepare than others: ```{r} plot( factor(c("Fried meat", "Cooked potatoes", "Peeled carrots")), sapply( list(fried_meat, cooked_potatoes, peeled_carrots), function(x) length(format(x)) ) ) ```
-
Render the document using
rmarkdown::render("final.Rmd")
, preferably in a fresh R session.- RStudio users can hit Ctrl+Shift+K when
final.Rmd
is open
- RStudio users can hit Ctrl+Shift+K when
-
View the resulting
final.html
in your browser. -
Create a file
R/knit.R
with the following contents:knit_with_deps <- function(target_name, source_name, ..., envir = parent.frame()) { dep_names <- as.character(unlist(substitute(list(...))[-1])) deps <- list(...) names(deps) <- dep_names deps <- deps[unique(names(deps))] dep_env <- as.environment(deps) parent.env(dep_env) <- envir rmarkdown::render( input = source_name, output_format = "all", envir = dep_env ) }
-
Add the following rule to your
targets
inremake.yml
:final.html: command: knit_with_deps(target_name, "final.Rmd", ragout, peeled_carrots, cooked_potatoes, fried_meat)
-
Make sure the
final.html
target is part of the main target!targets: all: depends: - ragout - final.html
-
Build the project.
-
View the resulting
final.html
in your browser, again.
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.
07-knitr
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||