Getting Started
-
Install R
The main R page is
here: www.r-project.org
To download R, choose a mirror site here:
cran.r-project.org/mirrors.html
Click on the link for your OS (Linux, Mac, or Windows). You should get the
latest version (currently 3.3.1). You just need the "base" program and not
any of the extras.
-
Install RStudio
The main RStudio page is
here: www.rstudio.com
Click the "Download RStudo" button. Choose the RStudio Desktop (Free
License). Again there are installers for Linux/Mac/Windows.
-
Install the rmarkdown package
Open RStudio. From the Console (R command line), run the following:
install.packages("rmarkdown")
-
Test your installation
In the "File" menu, choose "New File -> R Markdown..." Give the document
a title and select the "HTML" option. This defaults to an example R
Markdown file. Click the button "Knit HTML". You should get a formatted
HTML file with example text, R code, and plot.
Note: here is a screen shot of RStudio showing where you should find the
Knit HTML button (this may look slightly different depending on your OS
and RStudio version). Be sure that you have a file open with extension
.Rmd, and that the line output = html_document is in the
header. Otherwise, the Knit HTML button may not appear.
Using RStudio from the CADE Lab
RStudio is installed on the CADE Lab machines (these are the Linux machines
with names of the form "lab1-X" and "lab2-X", where X is a number). You can go
to the lab and work on the machines directly, or you can also log into them
remotely. See
the
CADE Lab
FAQ, especially the page
on
access
using NoMachine. Once you are on a machine, here is how to use RStudio:
- Open a terminal window, and type
rstudio
- Create a new R Markdown document and run "Knit HTML" as in Step 4
above. At this point, RStudio will ask you if it can install some
necessary packages. Say "yes". This will take a few minutes (but only has
to be done once).
- Cursor problem! You may find that the cursor in the RStudio
editor window is not always in the correct location (try moving around in
some text and editing to see if this happens to you). This is easy to fix
by changing the font settings. Go to the menu "Tools -> Global Options
...", where you will find an option for "Appearance". Here you should
select a different font and hit "Apply". Now check that the cursor appears
in the right place!
Useful R Markdown Links
-
Main R Markdown webpage:
Check out the "Get Started" and "Articles" links. Also, the "Gallery"
shows the cool things you can do with R Markdown (but these examples are
typically more advanced than is needed for this class).
-
R Markdown "Cheatsheet":
This is just about everything you need to know about R Markdown. It's good
to have this pdf handy.
-
R Markdown Reference Guide:
This has a bit more details than the cheatsheet, but still pretty concise
reference.
Useful R Code Help
You can learn all of the R you need for this class by following the code
examples we do in class. These will always be posted on the
schedule page. Here are some further resources to
get help learning R:
-
Try R: An interactive tutorial
that takes you through the basics of R. This is a good place to start. The
first 3 chapters get you through the basics of R.
-
R Tutor: Another good
tutorial. I recommend going through the first section, "R Introduction".
-
Official
R Introduction: this is a lengthy introduction to R. Probably more
details than you need, but a good place to read if you don't remember how
to do something.