Coding Notes
Coding Notes
Tour of RStudio
How to make a project file:
New Project New Directory New Project Name Create Project
- If you open this file it will open RStudio directly with this file (it will not be new)
Creating a Script
- File New File R Script Save As
Run: runs a selected line of code (single or chunk) or command + enter to run
Source: run the whole script from top to bottom
: if you put sections in your script it will put an outline; find sections of script by using this
- Running a piece of code more than once put it in script and save it
Console Section
- Output of script ends up here (telling us what is being run and what the output is)
- able to use this to do simple maths
- able to create variable e.g. X = 7 and will create a value in the environment and can use the variable
to generate a equation e.g. X = 7; Y = 3; put in the console X+Y and then it will tell us the answer
- good for when you only want to do an equation or install a package once
: cleaning tool; able to sweep out the console and start again
Environment section
- where data appears when you feed it in
- create new frames they will appear here
- create variables or paths to data and they will appear here
- history section shows what we have been doing so far
Files section
- shows the folder area
Plots
- where plots that have been drawn appear
Packages
- list of all the packages that have been installed
Load a package:
- open the script
- file script open script
- *should leave notes in script using #
- ------: this will activate the outline tab in script section
Saying that the filter and lag are similar and can get confused so make sure to use the double colon when
using dplyr
***load packages in the script section because it needs to load everytime you have an R session
run
View function : View(variable name) – spreadsheet of data run or click on beaches in environment
section
http://jenrichmond.rbind.io/post/apa-figures/
library(tidytuesdayR)
install.pack
use_tidytemplate()
- getting the template
glimpse()
- to look at the variables in the dataset
unique(dataset$variable)