library(cmu202) library(ggplot2) library(dplyr) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", warning = FALSE, message = FALSE, echo = FALSE, fig.width = 7, height = 6 )
axis.size <- 20 font <- "Times" vignette.theme <- theme(rect = element_rect(fill = "white", colour = "black", size = 0.5), text = element_text(face = "plain", colour = "black", size = 11, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0), axis.title.x = element_text(size = axis.size, vjust = 1, family = font), axis.title.y = element_text(size = axis.size, angle = 90, vjust = 1), axis.text.x = element_text(size = 15, vjust = 1), axis.text.y = element_text(size = 15, hjust = 1), axis.ticks = element_line(size = 0, colour = "grey20"), plot.title = element_text(family = font, face = "bold", size = 25, hjust = 0.5, vjust = 1))
The term "knitting" refers to the conversion of an RMarkdown document to a human-readable styling, such as a .pdf
or .html
document. In the knitting process, R evaluates all code chunks and produces the output while also displaying the code used to generate such an output. Note that one can hide either the output or the code itself. For a full guide on how to control these features visit the official knitr website.
Note that when knitting occurs, the code is evaluated in order inheriting all previously executed code. For example, we will define a variable named frank
below as such:
frank <- "Mudge" x <- 5 y <- 6
Note that for any following code chunk, we can use the frank
variable.
# Simply calling the variable will produce the value of the variable as the output, in this case "Mudge"
frank
We also see assignment and manipulation of the x
and y
variables:
x
y
x + y
The inheritance demonstrated applies to all R objects, including but not limited to library()
calls, variable assignments, function definitions and the loading of data. Note that the inheritance only applies to code chunks below the assigment.
For example, the following code will cause an error because z
is called before it is defined:
z z <- 1
If one were to reference the frank
variable in a code chunk placed before the assignment code, the code would not knit. Furthermore, the code is re-run with an empty environment each time knitting occurs.
In short, knit often!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.