Learning Objectives
- Project or Script
- Working Directory
- Folder Structure
-
Documentation
- Introduction to Markdown
- Formatting Markdown
Drawing of the Titanic gymnasium
Project or Script
Thus far, everything we have worked with scripts. Today, we work with projects. An R project:
-
is a way to divide work into multiple contexts.
-
is a folder containing a collection of code, data,
etc.
- has a root directory and R must know what this is.
- is easy to to handle in Rstudio.
Paperboy Ned Parfett, Soldier and Paperboy
RStudio Project (1/3)
Let's make a new project!
-
File -> New Project
-
Three options
- New Directory
- Existing Directory
- Version Control
-
Select the first option.
Version Control must be installed
separately and is not something we can
cover today.
RStudio Project (2/3)
-
Create an Empty Project
-
I promise, you don't want to do either of the
others.
RStudio Project (3/3)
-
Directory Name:
foo
-
~
is your home directory
-
If you don't know what git is, don't start a
repository.
If you do, RStudio will instantiate an empty git
repo at the project root.
-
If you open in a new session, RStudio will open a new window.
Our New Project
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> getwd()
[1] "/home/andy/foo"
- Please find the folder you created.
- You should find a file called foo.Rproj
- This is a RStudio specific file.
Your Turn! (1/3)
## Load some data:
data(cars)
## Look at it:
str(cars)
head(cars)
?cars
## Play with it:
colMeans(cars)
plot(cars$speed, cars$dist)
Your Turn! (2/3)
-
Save the file as
my_cars.R
. What happens?
-
What does the following code return? Does it make sense?
getwd()
Your Turn! (3/3)
- Close RStudio and restart it.
- See how to open specific projects.
Folder Structure (1/2)
- You can make up your own project structure.
- Project structure used today is modeled on R packages.
- I use a similar structure when working in R.
-
Goals:
- Separates data management from data analysis.
- Emphasizes documentation and reproducibity.
- Compatible with version control sites like GitHub.
Folder Structure (2/2)
Root Project Folder (foo):
-
data-raw/
- README.md
- something_awesome.R
-
data/
- README.md
- something_awesome.Rda
-
R/
- README.R
- awesome_function.R
- README.md
- explore.R
- some_awesome_analysis.R
Documentation
-
Start your R journey with documentation!
- All .md files are documentation.
- The file name README.md is a convention.
-
This is actually REALLY important.
-
You can write your documentation in many tools, like
Word. But, it doesn't translate well to the web.
-
Markdown - The plain text way to format your life.
Introducing Markdown
-
Daring Fireball
-
Allows authors/programmers to write in an easy-to-read
plain-text format which can be converted to other formats
like HTML, LaTeX, etc.
- Widely adopted & extended.
-
Programmers REALLY like plain text.
-
A derivative, RMarkdown, can be used to create
reproducible reports.
Formatting Markdown
# Heading 1
## Heading 2
Just write some text to create a paragraph. Just leave a space
between your paragraph and other objects like headers or
lists.
- Bullett List Item 1
- Bullett List Item 2
- Bullett List Item 3
Another paragraph. Lorem ipsum . . .
Next Up
Demo Project: Take Five!