Why learn to code?
efficiency
transparency
flexibility in application
shareable
automated processes/report writing
marketable skill
needed for publications
Software
What is R?
R is a “suite of software facilities for data manipulation, calculation and graphical display.”
R uses packages that are collections of functions, data, and compiled code in a “well-defined format”.
Packages are downloaded from The Comprehensive R Archive Network (CRAN), R’s central software repository. Also, on GitHub, GitLab, BitBucket or other code sharing platforms.
Why use R?
open-source and free
small total user base / large in ecology and statistics
find help online, e.g., stackoverflow
statistics
plotting / graphics
data management
What is RStudio?
RStudio is an “Integrated Development Environment (IDE)”.
RStudio brings tools/languages together.
We use R within RStudio.
Online resources to learn R
Today
Goal
‘Get familiar with fundamentals of R useful for data’
‘To get beyond the initial shock or fear of programming and start using R’
Today
Learning Objectives
Write and execute code in R via RStudio
R language vocabulary
Read/write data
Find help
Manipulate data efficiently
Plot data/results
Today
Execution
Presentation / code walk through
Challenges (independent or in teams of 2-3)
Today
Schedule
900 - 930 : Introductions and Setup
930 - 1015 : RStudio and R (objects and functions)
1015 - 1130 : Data Input and Output
1130- 1200 : Finding Help
1200 - 1300 : Lunch
1300 - 1400 : Data Mgmt
1400 - 1500 : Plotting
1500 - 1600 : Final Challenge
RStudio
RStudio
Installing Packages
Packages for Workshop
Please install from CRAN
tidyverse
readxl
ggridges
gridExtra
install.packages (c ("tidyverse" ,
"readxl" ,
"ggridges" ,
"gridExtra" )
)
The language of R
Objects
A storage place for information; stored in the “Environment”
‘Attributes’ describes the structure or information of the object
The language of R
Objects
The language of R
Objects
# y is an 'object' that is assigned the value 3
y = 3
y
# Same operation '=' '<-'
y <- 3
The language of R
Objects
# We can create new objects from objects
y2 = y-2
y2
# We can do math with our objects
# Mind your parentheses (order of operation)
y* 2 / y* 4
The language of R
Functions
‘does stuff’; creates or manipulates objects
‘Arguments’ are the types of things a function is asking for; the inputs
The language of R
object = function (argument = input1, argument = input2)
object = function (input1, input2)
The language of R
Functions
# How to find out the arguments of a function?
?is.numeric
The language of R
Wrapping functions
# Functions are commonly 1) wrapped, 2) have multiple arguments
x = matrix (
data = c (1 ,2 ,3 ,4 ,5 ,6 ),
nrow = 2 ,
ncol = 3
)
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
The language of R
Values
numeric
integer
character
factor
Objects
vector
matrix
array
list
dataframe
S3, S4, S5, and beyond
Next: Data input and output (Kyle)