How do I include sections of R code within my LaTeX document?

We recommend the listings package for including R code in LaTeX documents. If you add


to your preamble, you can then insert R code like this:

fib <- function(n) {
  if (n < 2)
    fib(n - 1) + fib(n - 2)
fib(10) # => 55

We are still working on making the R code executable within writeLaTeX - checkout our blog for all the latest developments!