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

Packages

1 / 26

Are you struggling?

2 / 26

Plan for today

  • Brief recap
  • Packages
3 / 26

Recap of using variables

  • Most of the time, we want to do more than add, subtract, multiply etc.
4 / 26

Recap of using variables

  • Most of the time, we want to do more than add, subtract, multiply etc.

  • We want to act on our variables. We do this with operators & functions

    • Each function has a unique name
    • Each function requires some input, and the function can be modified using arguments
    • Each function will produce an output
4 / 26

Recap of using variables

  • Most of the time, we want to do more than add, subtract, multiply etc.

  • We want to act on our variables. We do this with operators & functions

    • Each function has a unique name
    • Each function requires some input, and the function can be modified using arguments
    • Each function will produce an output
  • Remember:

    • objects are nouns
    • functions & operators are verbs
    • arguments are adverbs
4 / 26

Recap of using variables

Where do you find functions?

  • Some exist in R by default
    • t.test()
    • cor()
    • scale()

Lots of people all over the world write their own functions. And they (rightly!) think it's useful to share these functions.

5 / 26

Packages

What is a package?

  • A collection of functions and datasets
  • Open source

Packages are the reason R is so powerful!

  • While you can definitely write your own functions, most of what you need to do someone else has already done for you!
6 / 26

7 / 26

8 / 26

9 / 26

10 / 26

11 / 26

12 / 26

13 / 26

14 / 26

How do I get packages?

Packages can be downloaded from the CRAN (Comprehensive R Archive Network)

You will do this from inside R

Need to be connected to the internet!

15 / 26

2 ways to install packages

  1. Install button in the Packages tab

  2. R Code



    Either way, you need to know the name of the package

16 / 26

Install Button

17 / 26

Install Button

18 / 26

Install Button

19 / 26

R code to install packages








install.packages("psych")

20 / 26

Packages

INSTALLING

  • Downloading the package and saving it to your computer
  • Like installing Microsoft Word on your computer
  • Do this ONCE
21 / 26

Packages

INSTALLING

  • Downloading the package and saving it to your computer
  • Like installing Microsoft Word on your computer
  • Do this ONCE

LOADING

  • Like opening Microsoft Word to write a paper
  • Once a package is loaded, you can use all of it's functions and datasets are ready to use
  • You need to do this EVERY TIME you open a new R session
21 / 26

2 ways to load packages

  1. Checkbox in the packages tab (not recommended)

  2. R code



    Either way, you need to know the name of the package

22 / 26

R code to load packages








library(psych)

23 / 26

Dependencies

Uses functions from other packages

Installed automatically

Loaded automatically

24 / 26

Help! (again)

Ways to find documentation:

?psych -- opens documentation specific to that pacakge or function

??psych -- searches for this in all documentation (that you have installed and loaded)

To find a package that does what you need: Google

25 / 26

Summary

Packages are a collection of functions and data sets

  1. You install the package once; must be connected to the internet
  2. You load the package every time you use it; do not need to be connected to the internet
26 / 26

Summary

Packages are a collection of functions and data sets

  1. You install the package once; must be connected to the internet
  2. You load the package every time you use it; do not need to be connected to the internet

How do you find the function you need? How do you now what package it's in?

  • G-o-o-g-l-e!
  • "structural equation modeling in R"
26 / 26

Summary

Packages are a collection of functions and data sets

  1. You install the package once; must be connected to the internet
  2. You load the package every time you use it; do not need to be connected to the internet

How do you find the function you need? How do you now what package it's in?

  • G-o-o-g-l-e!
  • "structural equation modeling in R"

How do you know how to use the function? What are the function's arguments?

  • Help documentation in R
  • ? function.name
26 / 26

Are you struggling?

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