build_articles: Build articles section

Description Usage Arguments Index and navbar External files Embedding Shiny apps YAML header Suppressing vignettes Tables of contents Figures

View source: R/build-articles.R

Description

build_articles() renders each R Markdown file underneath vignettes/ and saves it to articles/. There are two exceptions:

Vignettes are rendered using a special document format that reconciles rmarkdown::html_document() with the pkgdown template. This means articles behave slightly differently to vignettes, particularly with respect to external files, and custom output formats. See below for more details.

Note that when you run build_articles() directly (outside of build_site()) vignettes will use the currently installed version of the package, not the current source version. This makes iteration quicker when you are primarily working on the text of an article.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
build_articles(
  pkg = ".",
  quiet = TRUE,
  lazy = TRUE,
  override = list(),
  preview = NA
)

build_article(name, pkg = ".", data = list(), lazy = FALSE, quiet = TRUE)

build_articles_index(pkg = ".")

Arguments

pkg

Path to package.

quiet

Set to FALSE to display output of knitr and pandoc. This is useful when debugging.

lazy

If TRUE, will only re-build article if input file has been modified more recently than the output file.

override

An optional named list used to temporarily override values in _pkgdown.yml

preview

If TRUE, or is.na(preview) && interactive(), will preview freshly generated section in browser.

name

Name of article to render. This should be either a path relative to vignettes/ without extension, or index or README.

data

Additional data to pass on to template.

Index and navbar

You can control the articles index and navbar with a articles section in your _pkgdown.yaml. It defines a list of sections, each of which can contain four fields:

The title and description of individual vignettes displayed on the index comes from title and description fields of the YAML header in the Rmds.

For example, this yaml might be used for some version of dplyr:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
articles:
- title: Main verbs
  navbar: ~
  contents:
  - one-table
  - two-table
  - rowwise
  - colwise

- title: Developer
  desc: Vignettes aimed at package developers
  contents:
  - programming
  - packages

Note the use of the navbar fields. navbar: ~ means that the "Main verbs" will appear in the navbar without a heading; the absence of the navbar field in the for the developer vignettes means that they will only be accessible via the articles index.

Special links

External files

pkgdown differs from base R in its handling of external files. When building vignettes, R assumes that vignettes are self-contained (a reasonable assumption when most vignettes were PDFs) and only copies files explicitly listed in .install_extras. pkgdown takes a different approach based on rmarkdown::find_external_resources(), and it will also copy any images that you link to. If for some reason the automatic detection doesn't work, you will need to add a resource_files field to the yaml metadata, e.g.:

1
2
3
4
5
6
---
title: My Document
resource_files:
  - data/mydata.csv
  - images/figure.png
---

Note that you can not use the fig.path to change the output directory of generated figures as its default value is a strong assumption of rmarkdown.

Embedding Shiny apps

If you would like to embed a Shiny app into an article, the app will have to be hosted independently, (e.g. https://www.shinyapps.io). Then, you can embed the app into your article using an <iframe>, e.g. <iframe src = "https://gallery.shinyapps.io/083-front-page" class="shiny-app">.

See https://github.com/r-lib/pkgdown/issues/838#issuecomment-430473856 for some hints on how to customise the appearance with CSS.

YAML header

By default, pkgdown builds all articles with rmarkdown::html_document() by setting the template parameter. This overrides any custom settings you have in your YAML metadata, ensuring that all articles are rendered in the same way (and receive the default site template).

If you need to override the output format, or set any options, you'll need to add a pkgdown field to your yaml metadata:

1
2
pkgdown:
  as_is: true

This will tell pkgdown to use the output_format (and options) that you have specified. This format must accept template, theme, and self_contained in order to work with pkgdown.

If the output format produces a PDF, you'll also need to specify the extension field:

1
2
3
pkgdown:
  as_is: true
  extension: pdf

Suppressing vignettes

If you want articles that are not vignettes, either put them in subdirectories or list in .Rbuildignore. An articles link will be automatically added to the default navbar if the vignettes directory is present: if you do not want this, you will need to customise the navbar. See build_site() details.

Tables of contents

You can control the TOC depth via the YAML configuration file:

1
2
toc:
  depth: 2

Figures

You can control the default rendering of figures by specifying the figures field in _pkgdown.yml. The default settings are equivalent to:

1
2
3
4
5
6
7
8
9
figures:
  dev: grDevices::png
  dpi: 96
  dev.args: []
  fig.ext: png
  fig.width: 7.2916667
  fig.height: ~
  fig.retina: 2
  fig.asp: 1.618

Paradigm4/pkgdown documentation built on June 3, 2020, 12:30 a.m.