Giter Club home page Giter Club logo

targets-parameterized-bookdown's Introduction

targets-parameterized-bookdown

DOI

Example repository for rendering a bookdown book, compiling parameterized Rmarkdown documents, using the targets package.

This example extends the targets-minimal example. To mimic a directory of input files, we split the example data into two chunks.

library(tidyverse)
data <- read_csv('data/raw_data.csv')

nrows <- 50

data1 <- head(data, n = nrows)
data2 <- tail(data, n = nrows)

write_csv(data1, 'data/split/data1.csv')
write_csv(data2, 'data/split/data2.csv')

To setup a target for our input files, we use tar_files from tarchetypes (target: paths). Dynamic branching in subsequent targets is mapped over these files (targets: raw_data, data, hist, fit).

Parameterized RMarkdown documents are generated by mapping over the fitted model and histograms using a template document (template/template.Rmd) (target: report).

Finally, the output documents are merged into a book with bookdown. We use a custom wrapper function render_with_deps to explicitly declare the book's dependency on the output reports (target: book).

Notes

  • We need to change the extension of the parameterized github_document outputs (target: report) from .md to .Rmd because bookdown doesn't pick up .md files unless they are explicitly listed with the rmd_files argument in _bookdown.yml. See here.

  • The title and output_file for rendered RMarkdown documents are set in this example to the name of the branch (target: report). If adapted for your own use, this could alternatively be set to an id from the data, etc.

  • We can't use the tar_render function from tarchetypes because we need to call bookdown::render_book and not rmarkdown::render (target: book). Therefore, we need to track the .Rmd files in separate targets.

  • You may need to use pandoc >= 2.11.2 when generating the github_documents (target: report) so ATX style headings are used by default.

targets-parameterized-bookdown's People

Contributors

robitalec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

eeholmes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.