I'm building a reporting infrastructure that makes extensive use of child documents (via {r, child = 'somedir/child_doc.Rmd'}
) AND is parametrized through the params
dictionary in the YAML
header of the master document. An example might be:
---
title: Project Report
subtitle: POIGNANT DESCRIPTION OF THE WORK AT HAND
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
bookdown::pdf_document2:
template: ~
toc: yes
toc_depth: 2
colorlinks: yes
fontsize: 11pt
documentclass: scrartcl
geometry: margin=1in, a4paper
params:
submodule:
value:
intro:
data_dir: 'data'
---
Using this structure, accessing data_dir
becomes problematic as the working directory differs for the master and child documents and thus relative path definitions also diverge. Ways out are:
Usage of absolute/expanded path names in defining
data_dir
. Gets long/unwieldy quickly.Postprocessing of the
params
object to expand the path within the master document. Asparams
is immutable when accessed from withinR
chunks, this can only be solved in an inelegant manner:```{r params-processing, include = FALSE} local_params <- params local_params$submodule$intro$data_dir <- path.expand(local_params$submodule$intro$data_dir)
Followed by internal usage of
local_params
instead ofparams
.In-place expansion of the path using something like
!R path.expand('data')
when defining the parameter in theYAML
header. While this (or the `-based equivalent) works for thedata
field in the example,knitr
ing fails in the path case as theR
expression is not expanded but used as a character-representation - and literal"path.expand('data')"
obviously doesn't exist as a path.
I'd appreciate any hints on how to solve this prettily - especially whether 3. can be made work ...