+ - 0:00:00
Notes for current slide
Notes for next slide

Loading Files

1 / 19

Loading & Organizing

  • BE. ORGANIZED.
  • It's hard to load in files if you don't know where they are
  • We can use packages and tools to our advantage when we are organized
  • Less typing
  • Being organized will spark joy

2 / 19

Directories

Your computer is made up of a series of folders



3 / 19

File paths

These are the instructions that tell the computer where to find your file. What series of folders does the computer need to look to find your stuff?

/Users/Coop/Box Sync/S55-5962_RSkillLab_Spring2020

4 / 19

File paths

In order to get the actual file, include the name in the file path

/Users/Coop/Box Sync/S55-5962_RSkillLab_Spring2020/day1.pptx

5 / 19

R is lazy!

Working Directory

  • Where R is going to look for files
  • Where R is going to save files
6 / 19

Working directory

How do you know your working directory?

  • getwd()

How do you change your working directory?

  • setwd("/your/path/goes/here")
  • Note the quotes!
  • HINT: press tab within the quotes and see what happens!
7 / 19

An Alternative: RProjects

Getting and setting your working directory can be a pain in the @$\$

  • What happens if you reorganize your computer and you want to move the files?
8 / 19

An Alternative: RProjects

Getting and setting your working directory can be a pain in the @$\$

  • What happens if you reorganize your computer and you want to move the files?

RProjects provides a nice alternative with several added benefits

  1. It syncs to Github. Excellent for version control and open science!
  2. Your project is it's own contained ecosystem. If you move it on your computer, it doesn't matter. No need to get/set your working directory.
  3. Easy to look for files within that project (rather than the entire computer)
8 / 19

We are going to make this together next Wednesday!

9 / 19

.R files

  • Aka scripts
  • Text files
  • Contain the code that you've written
  • (Equivalent to syntax files in SPSS)
10 / 19

.R files

  • Aka scripts
  • Text files
  • Contain the code that you've written
  • (Equivalent to syntax files in SPSS)

Why use them?

  • Keep track of what functions you use
  • Save only the commands/functions/progress that is useful
  • Make notes to yourself!
    • # Updated code for R class!
    • # reliability estimates for depression scale
    • # scatter plot for BMI predicting diabetes diagnosis
  • Share your analyses with collaborators and readers
10 / 19

Other file types

  • .RProject -- not where you would write any form of code -- more to come!
  • .Rmd -- aka "RMarkdown" or "RNotebook"; will talk about for reproducibility!
  • Your data!
11 / 19

Your data

Original data files

  • Most of the time, these will either be .csv or .txt, depending on how you collect the data

These are NOT altered by R! (different from SPSS)

If your data is not one of these two formats, don't worry! R can do a lot of stuff!

We will work with .csv to keep things simple.

12 / 19

Loading .csv files

13 / 19

Loading .csv files

14 / 19

Loading .csv files

15 / 19

Loading .csv files

The following line of code will appear in your console:

midus <- read.csv("~/Desktop/rSkillLab/midus.csv")

If you do not use a RProject, then you MUST copy/paste this line of code into your script (.R) file!

16 / 19

A note about Excel

  • Excel is owned by Microsoft
  • Microsoft is not a non-profit; they make a stupid amount of money
  • When programming languages were developed, Microsoft didn't play nicely with things that weren't also owned by Microsoft
  • What does this mean for you?
    • If you are working with a data file, it is better to save it as a .csv or .txt rather than .xls or .xlsx
    • It used to be really hard to get your data into R if it was a .xls or .xlsx format. It's now a lot easier. So it doesn't matter much, but if you have a say in the matter, change it.
    • Color coding/highlighting in Excel doesn't translate to R. Stop using it for data. Story time.
17 / 19

Typical workflow in R

  1. Open a script (new or existing)

  2. Prepare to run analyses:

    • Set your working directory (if not using RProject)
    • Load your data
    • Load any packages you might want to use in the analyses
  3. Write code/run analyses

  4. Save your script!

    • Make sure that this includes the code to open your .csv from your Dropbox/Box/Github etc.
    • Again, note: R does't change the original data file!
18 / 19

Typical format of .R file

19 / 19

Loading & Organizing

  • BE. ORGANIZED.
  • It's hard to load in files if you don't know where they are
  • We can use packages and tools to our advantage when we are organized
  • Less typing
  • Being organized will spark joy

2 / 19
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