R Packages

Intermediate R

Filip Schouwenaars

DataCamp Instructor

R Packages

  • Where do mean(), list() and sample() come from?
  • Part of R packages
  • Code, data, documentation and tests
  • Easy to share
  • Examples: base, ggvis
Intermediate R

Install packages

  • base package: automatically installed
  • ggvis package: not installed yet

    install.packages("ggvis")
    
  • CRAN: Comprehensive R Archive Network

Intermediate R

Load packages

  • load package = attach to search list
    search()
    
".GlobalEnv"  ...  "Autoloads"   "package:base"
  • 7 packages are attached by default
  • ggvis not attached by default
ggvis(mtcars, ~wt, ~hp)
Error: could not find function "ggvis"
Intermediate R

Load packages: library()

library("ggvis")
search()
".GlobalEnv"  "package:ggvis" ... "package:base"
ggvis(mtcars, ~wt, ~hp)

Intermediate R

Load packages: require()

library("data.table")
Error in library("data.table") : 
there is no package called ‘data.table’
require("data.table")
Loading required package: data.table
Warning message: ...
Intermediate R

Load packages: require()

result <- require("data.table")
Loading required package: data.table
Warning message: ...
result
FALSE
Intermediate R

Wrap-up

  • Install packages: install.packages()
  • Load packages: library(), require()
  • Load package = attach package to search list
  • Google for cool R packages!
Intermediate R

Let's practice!

Intermediate R

Preparing Video For Download...