-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_Tutorial01WhatisR.Rmd
151 lines (96 loc) · 6.64 KB
/
in_Tutorial01WhatisR.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
title: "Tutorial 1: What are R & R-studio?"
---
```{r setup, include=FALSE}
# OPTIONS -----------------------------------------------
knitr::opts_chunk$set(echo = TRUE,
warning=FALSE,
message = FALSE)
```
```{r, include=FALSE}
# PACKAGES-----------------------------------------------
# Tutorial packages
library(vembedr)
library(skimr)
library(yarrr)
library(RColorBrewer)
library(GGally)
library(tidyverse)
library(plotly)
library(readxl)
library(rvest)
library(biscale)
library(tidycensus)
library(cowplot)
library(units)
# FUNCTIONS -----------------------------------------------
# Get R version
GetRLatest <- function(Website="https://cran.r-project.org/banner.shtml"){
require(rvest)
#scrape the text from the website
RWebsite <- read_html("https://cran.r-project.org/banner.shtml") %>%
html_nodes("li") %>%
html_text()
# get the line that includes latest release and get rid of the stuff after
RLatest <- base::strsplit(RWebsite[grep("latest release",
tolower(RWebsite))],"\n")[[1]][1]
return(RLatest)
}
```
<br><br>
# 1. What is R??
#### **R IS A LANGUAGE SPOKEN BY YOUR COMPUTER**
**R** is a free, open source statistical programming language. It contains millions of words/commands that are useful for dataset cleaning, analysis, and visualization.
By a "programming language", I mean it is a collection of commands that you can type into the computer in order to analyse and visualize data. The easiest way I find to think about R is that it is literally a language, like Spanish, English or Hindi. Or like a set of magic commands in a fantasy novel.
Learning R means learning vocabulary and grammar in order to communicate. It also means it gets easier with experience and practice..
<br>
If you open "R" on your computer (DON'T DO THIS), you will see a simple window with a cursor ready to hear commands. There is no help or support. This is how I learned to programme in R. It's not fun!
```{r, Tut_Fig1, echo=FALSE, fig.cap = "*Basic R*",fig.align='center'}
knitr::include_graphics('./Figures/fig1_RConsole.png')
```
<br><br>
# 2. What is R-Studio/POSIT?
<br>
#### **R-STUDIO/POSIT is a Software Application like Word, Chrome or Spotify**
<br>
**R-studio** is a *software program/app*, like Microsoft Word, or the Chrome Web-browser. It's has recently been re-branded to Posit because it can also now "speak" other computer languages. For GIS folks, it's a competitor to Google Collab.
It's a program that's designed to make it easy to write R-commands. RStudio has many useful features. For example, you can easily see help files, run code, see your results and create professional graphics. R-Studio also allows us to make interactive documents called R-Markdown files.
<br>
There is a version you can download onto your own computer called R-Studio/Posit Desktop, and a version that runs on a website called 'R-Studio Cloud'.
```{r, Tut_Fig2, echo=FALSE, fig.cap = "*R-studio is much more sophisticated*",fig.align='center'}
knitr::include_graphics('./Figures/fig2_RStudioIntro.png')
```
<br>
Watch this 5 min video on the newest version of R studio. More here: <https://posit.co/blog/announcing-rstudio-1-4/>
```{r,echo=FALSE,fig.align='center'}
embed_url("https://www.youtube.com/watch?v=SdMPh5uphO0")
```
<br><br>
# 3. What is R-Markdown?
<br>
#### Markdown is a way of writing documents with computer code embedded into them.
#### R-Markdown is a markdown file that uses R code
<br>
```{r, Tut_Fig6, echo=FALSE, fig.align='center'}
knitr::include_graphics('./Figures/fig6_AboutMarkdown.png')
```
<br>
R Markdown is a document format that blends the capabilities of R (a programming language primarily used for statistical computing and data analysis) with the formatting and layout capabilities of Markdown (a lightweight markup language). It allows you to create dynamic documents that combine narrative text, code, and the output of that code (such as tables, plots, and figures) in a single document. <br>
Read more here: <https://rmarkdown.rstudio.com> or watch this short video
```{r,echo=FALSE,fig.align='center'}
embed_url("https://vimeo.com/178485416?embedded=true&source=video_title&owner=22717988")
```
Here's how R Markdown works:
1. **Narrative Text**: You can write your document using plain text, using Markdown syntax to format your text, add headings, lists, links, and more.
2. **Code Chunks**: You can embed R code chunks within your Markdown document. These chunks are demarcated by triple backticks or by the "\`\`\`{r}" syntax, and they allow you to execute R code directly within your document.
3. **Output Display**: When you knit (compile) the R Markdown document, the R code within the code chunks is executed, and the output is dynamically displayed in the final document. This output can include tables, plots, statistical summaries, and more.
4. **Knitting**: The process of converting an R Markdown document into a final, formatted document is called "knitting." When you knit an R Markdown document, R code is executed, the output is generated, and the Markdown text and the output are combined into a single document.
5. **Flexibility**: R Markdown supports various output formats, including HTML, PDF, Word, presentations, and more. This means you can easily create different types of documents from the same source.<br><br>
R Markdown is widely used for creating reports, documents, tutorials, and presentations that involve data analysis and visualization. It is a powerful tool for reproducible research because it allows you to document your analysis process, code, and results in a single document. Changes to the code or data can be easily updated and reflected in the final document without manually reformatting everything.
To use R Markdown, you typically need to have R and a few additional packages installed. You write your document in a plain text file with the **`.Rmd`** extension, and then use an R Markdown "knitting" process to generate the final document in your desired format. We will cover this in the next tutorial.
<br><br>
## Some examples?
1. **R Markdown Gallery**: The official R Markdown Gallery showcases a variety of R Markdown examples, including interactive visualizations, reports, presentations, and more. You can find this gallery on the R Markdown website.
Website: [**R Markdown Gallery**](https://rmarkdown.rstudio.com/gallery.html)
2. **R Bloggers**: R Bloggers is a community-driven site that aggregates blog posts related to R programming. Many R bloggers share their R Markdown examples, tutorials, and creative outputs on this platform.
Website: [**R Bloggers**](https://www.r-bloggers.com/)