In-Class Introductions and RMarkdown
Basics Intro to Quantitative Ecology:
Your group will submit a single document, but every member of your group needs to create their own markdown document and follow the code in the exercise.
Create a new R Markdown file and name it
in_class_introductions.Rmd
.
When you first create a new Rmd document, RStudio will populate it with some content. You should delete the auto-populated text and code chunks, but make sure you do not delete the header part of the document.
---
on the first
line of the file.Content in R markdown documents is arranged using headings. First-level headings have large text, second-level headings are slightly smaller, etc.
A heading should be brief: think of it as the name of a section of your document.
Headings are denoted using the number sign, #
, at the
beginning of a line.
First-level headings begin with a single #
, second-level
begin with a double ##
, etc.
Make a section called Introductions using a first level heading. In your introduction section, each member should include a sentence that lists their name and major. For example:
Hello, my name is ____ and my major is ____.
palmerpenguins
.One of the great things about R is that you can extend it by
installing packages. Just use the
install.packages()
function.
For this exercise your group will need to install the
palmerpenguins
package, which contains data collected from
3 species of penguin.
Make a new first-level heading and call it Installing and Loading Packages.
Create a code chunk and place the following code in it:
install.packages("palmerpenguins")
You only need to install a package once. After the package installs, you should put a comment character at the beginning of the line so that you don’t re-install the package every time!
After you’ve successfully installed a package, you have to tell R to
load it into memory using the library()
or
require()
functions.
require()
Make another code chunk in which you’ll use the
require()
function to load the penguins data into R’s
memory:
require("palmerpenguins")
Now you’ll have the penguins
data loaded into R’s
memory.
Note: even though penguins
object is loaded, it may not
be visible in the Environment window.
In general, datasets that are loaded from packages won’t show up in the environment window, even though they are available for use.
Create a new first-level heading called Data Inspection
Create a new code chunk and use the head()
function to
print the first 6 lines of the penguins
data.
Finally, you can hit the knit button in RStudio to render your R markdown file into a html document.
One group member should upload the file into Moodle.