---
title: '%PROJECT% - %PACKAGE%'
subtitle: '%TASK% - %SUFFIX%'
author: '%AUTHOR%'
date: '%DATE%'
output: 
  officedown::rdocx_document:
    reference_docx: "%TEMPLATEFILE%"
    toc: yes
  page_size:
    width: 8.3
    height: 11.7
    orient: "portrait"
  page_margins:
    bottom: 1
    top: 1
    right: 1.25
    left: 1.25
    header: 0.5
    footer: 0.5
    gutter: 0.5
header-includes:
  - \usepackage{fancyhdr}
  - \pagestyle{fancy}
  - \fancyhead[CO,CE]{%TASKIDX%}
  - \fancyhead[LO,LE]{}
  - \fancyhead[RO,RE]{}
  - \fancyfoot[CO,CE]{%COPYRIGHTX%}
  - \fancyfoot[RO,LE]{\thepage}
  - \fancyfoot[LO,RE]{}
  - \fancypagestyle{plain}{\pagestyle{fancy}}
classoption: twoside
geometry: 'left=2cm,right=2cm,top=3cm,bottom=2cm'
---

```{r eval=FALSE, echo=FALSE, message=FALSE, warning=FALSE}
# ===================== HELPER CODE ==========================
if(FALSE) {
  library(D4TAlink.light)
  #library(D4TAlink)
  setTaskSponsor("%SPONSOR%")
  setTaskStructure(pathsDefault)
  try(setTaskRoot("%ROOT%"))

  # load the task
  task <- loadTask(project="%PROJECT%", package="%PACKAGE%", taskname="%TASK%")
  
  # render the task
  shell.exec(renderTaskRmd(task,suffix="%SUFFIX%"))
  
  # archive the task to the home directory
  archiveTask(task,zf<-paste0("~/",task$task,".zip"),overwrite=FALSE)
  
  # settings for new repository
  oro <- getTaskRoot() 
  setTaskRoot("/PATH/TO/NEW/REPOSITORY")
  ost <- getTaskStructure() 
  setTaskStructure(pathsDefault)

  # copy the task to a new repository
  newtask <- restoreTask(zf)
  print(list.files(getTaskPaths(newtask)$data,
                   full.names=FALSE,recursive=TRUE))
  
  #restore old settings
  setTaskRoot(oro) 
  setTaskStructure(ost)
}
# ============================================================
```

```{r optionsChunk, echo=FALSE, message=FALSE, warning=FALSE}
options(warn=1)
knitr::opts_chunk$set(
  fig.cap = TRUE,
	eval = TRUE, 
	echo = FALSE,
	comment = "#",
  message = FALSE,
	error = TRUE, 
  warning = TRUE,
	dpi = 150,
  dev.args = list(pointsize=8)
)
library(officedown)
library(officer)
```

```{r loadLibraries, warning=FALSE}
# Load libraries
library(D4TAlink.light)
#library(D4TAlink)
setTaskSponsor("%SPONSOR%")
setTaskStructure(pathsDefault)
# try(setTaskRoot("%ROOT%"))
```

```{r loadTask}
# Load task
task <- loadTask(project="%PROJECT%", package="%PACKAGE%", taskname="%TASK%",quiet=TRUE)
# if task does not exist on repository, create it 
if(is.null(task)) {
  task <- initTask(project="%PROJECT%",
                   package="%PACKAGE%",
                   taskname="%TASK%",
                   sponsor="%SPONSOR%",
                   author="%AUTHOR%")
}

options(warn = 2)
```

\newpage

# Scope

In this section the scope / rationale of the task should be explained.

# Input

The section list the information and data sources.

* List of patients (see email by JD dated 2022-05-01 17:12).
* List of assays (see task 20220102_loadAssays).

```{r loadInput}

# Code to load input data

# ta <- loadTask(task$project,task$package,"20220102_loadAssays)
# ass <- readBinary(ta,"assays")

```

# Methods and Results

The results-section contains more details regarding the results of task X.

```{r consideredRCode}

# Chunk that contains the analysis R code.

```

## Table

```{r tab.cap="caption 1", tab.id="mtcars"}
head(data.frame(l=letters,L=LETTERS))
```

## Plot

```{r fig.cap="A boxplot", fig.id = "boxplot"}
boxplot(1:8)
```


# Output

The section contains detailed information on output (incl. location).

* List of assays.

```{r saveOutput, echo=FALSE}

# Code to save data

# saveBinary(ass,ta,"assays")

```

\newpage

# References

1. R Core Team (2022). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.

\newpage

# Appendices

## Session information

```{r sessionInfo, echo=FALSE, results="asis"}

# In the appendix the session information is being printed for reproducibility.

sessionInfo()

```

## List of figures

<!---BLOCK_TOC{seq_id: 'fig'}--->

## List of tables

<!---BLOCK_TOC{seq_id: 'tab'}--->

