options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(fig.align="center", fig.width=5, fig.height=5, warning = FALSE, message = FALSE)
library(xaringanthemer)
duo_accent(
  primary_color = "ivory",
  secondary_color = "midnightblue",
  header_font_google = google_font("Roboto", "400"),
  text_font_google   = google_font("Lato", "300"),
  code_font_family = "Fira Code",
  code_font_url = "https://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/fira_code.css",
  header_color = "#f54278",
  title_slide_text_color = "#354a66"
)

What are functions?

function: reusable code that performs a well-articulated task

--

--

What types of task:

--

--


How to use

--

--

?plot

Where do you get functions

We can think of 3 sources of functions:

--

--

--


What is a package?

A package: is a collection of functions and data.

Some examples:


CRAN

Comprehensive R Archive Network (CRAN): The official repository of packages for the R language.

knitr::include_graphics("images/CRANScreen.png")

Installing and using packages

Example: Installing the genius package

install.packages("genius")

library: gives you access to the functions and data of a package that is already installed

Example:

First try to use the genius_lyrics function of the genius package:

sg <- genius_lyrics(artist = "Kes", song = "Savannah Grass")

--

Now use library:

library(genius)
sg <- genius_lyrics(artist = "Kes", song = "Savannah Grass")

sg
reactable::reactable(sg)

Writing our own functions

Write a function th * input: * a vector of variables * a number n


What are the steps?


Do these steps correspond to functions we are familiar with?



thisisdaryn/workshop documentation built on Jan. 17, 2020, 7:31 p.m.