" />
+ - 0:00:00
Notes for current slide
Notes for next slide

Projects & R Markdown

You’ll thank yourself later



Danielle Navarro     @djnavarro

https://djnavarro.github.io/chdss2018/

11 December 2018

1 / 14

RStudio projects

2 / 14

Introduction


What? Tool for R to track your project

Why? Because file paths are a nightmare

How? I'm so glad you asked...

3 / 14

Introduction


What? Tool for R to track your project

Why? Because file paths are a nightmare

How? I'm so glad you asked...

3 / 14

How to create

  • RStudio projects menu (top right)
  • New Project > Existing Directory
  • Create in the same folder as the git repo
  • Drop down list of projects in the menu

As usual, the details are in the tutorial

4 / 14

Behold our creation!



5 / 14

One benefit to projects...

  • Close RStudio. Reopen by clicking .Rproj file
  • R is automatically in the "correct" folder
  • Switch between projects using the menu
6 / 14

One benefit to projects...

  • Close RStudio. Reopen by clicking .Rproj file
  • R is automatically in the "correct" folder
  • Switch between projects using the menu

6 / 14

Taking the pain out of file paths

7 / 14

Only you can prevent laptop fires


@JennyBryan

8 / 14
  • The "here" package is better than a laptop fire
  • Detects the .Rproj file (or a .here file if you have one)
  • Tells you where the project root is:
library(here)
9 / 14
  • The "here" package is better than a laptop fire
  • Detects the .Rproj file (or a .here file if you have one)
  • Tells you where the project root is:
library(here)
  • Use the here function to specify paths:
location <- here("analysis","data","mydatafile.csv")
print(location)
## [1] "C:/Users/Dan/GitHub/sites/chdss2018/analysis/data/mydatafile.csv"
9 / 14

git + projects + here

Your code...

  • is portable across operating systems
  • is easy for other people to download
  • stills works if you move the folder
  • doesn't produce "mysterious" fires
10 / 14

git + projects + here

Your code...

  • is portable across operating systems
  • is easy for other people to download
  • stills works if you move the folder
  • doesn't produce "mysterious" fires

10 / 14

R Markdown

11 / 14
  • File > New File > R Markdown
  • Enter information in dialog box (right)
  • Save the file
  • Click "Knit"

12 / 14

The result is a nice HTML file and a short R Markdown tutorial.
Before the next part, try writing something with R Markdown



13 / 14

thank u, next

14 / 14

RStudio projects

2 / 14
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow