#R - Rmd Post Template

A sentence to be used as news excerpt. This should be short enough to fit nicely the carousel on the home page.

R Markdown

Refer to the R Studio website for a comprehensive introduction to R Markdown.

Also refer to the conventional markdown news post template for general instructions and guidelines about writing news posts, such as details about including non-R-generated pictures, links, etc.

Code chunks

This is an example of R chunk labelled my-first-chunk (it is recommended to provide a label for all chunks), without any special option.

# some code
(a <- 10)
## [1] 10
b <- sqrt(a)
a + b
## [1] 13.16228

You can fine-tune the behavior/results using chunk options, e.g. echo=FALSE, eval=FALSE, include=FALSE, results='hide', error=TRUE.

Get used to write consistently-formatted, tidy R code, especially concerning spacing and parentheses (see e.g. the ‘Syntax’ section in Hadley’s style guide).

The following is an example of un-tidy, poorly formatted code:

fun <-function(x  =NULL)
  if(length(x)!=0)  {
  return( x )
fun  (0.0)
## [1] 0

Besides writing tidy code yourself, you might want to use the tidy chunk option, causing the R code to be re-formatted in a tidy way. (This can be enabled for all code chunks in the initial setup chunk. Note that the tidy chunk option requires the package formatR, otherwise the code will remain as is and you will just get a warning when knitting.)

fun <- function(x = NULL) {
  if (length(x) != 0) {
    x <- 0

Note that previous chunks can be re-called by label later in the document, as in the tidy chunk above.

You should avoid exceeding 80 characters per line, since the font size for code chunks is tuned to fit 80 characters without horizontal scrolling:

x <- "

Supporting (source) files

If the R Markdown post needs some supporting files, to be used within code chunks or as code chunks (e.g. R scripts), place them in the same post-specific directory so they can be accessed via relative paths. In particular, it is possible to define stand-alone scripts, e.g. myFun.R, and use knitr::read_chunk(<FILE>, labels = <LABEL>) in a first non-included chunk, before re-calling the content by label in a second chunk.

## myFun.R
#' @title My function.
#' @description My function.
#' @param arg1 My first argument.
#' @param arg2 My second argument.
#' @return My return value.
#' @export
myFun <- function(arg1, arg2) {
  "My return value"


Figures generated by plotting in any R code chunk are automatically generated and linked (note echo=FALSE to show only the image and not the underlying code) plot of chunk pressure


Parameters declared in the params field within the YAML header are accessible as read-only list called params.

The list can be used inline (DUMMY) or in R code chunks:

## [1] "DUMMY"