Skip to main content

Embedding R code


This session will cover embedding R code in qmd.

Session Details

  • Date: [Day of week], [Month] [Day], [Year]
  • Time: [Start time]–[End time] ([morning/afternoon/evening] session)
  • Location: [Venue or virtual platform]
  • Instructor: [Instructor Name]

Embedding R code into the website

The quarto markdown .qmd is essentially a successor to RMarkdown, mostly backward compatible and following similar syntax.

Library loading

Here we are loading the libraries used throughout this document.

library(ape)
library(phangorn)

Code chunks

tree1 <- ape::read.tree(text='(((A,B),C),D);')
tree2 <- ape::read.tree(text='(((A,C),B),D);')

dist <- phangorn::RF.dist(tree1, tree2)

dist
[1] 2

Cross reference figures

You can add special tags to be able to create links to figures. See Figure 1 for details.

Code
tree1 <- ape::read.tree(text='(((A,B),C),D);')

plot(tree1)
Figure 1: You can link to this figure

Reading external datasets

We can also read in files that are provided in a relative location to this document.

my.trees <- ape::read.nexus('../data/example.trees')

phangorn::RF.dist(my.trees)
           STATE_0 STATE_2000
STATE_2000      26           
STATE_4000      28         16