-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathr_dev_env.Rmd
154 lines (105 loc) · 3.7 KB
/
r_dev_env.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
152
153
154
---
title: "建立你的 R 語言開發環境"
author: "郭耀仁"
output:
revealjs::revealjs_presentation:
theme: black
highlight: zenburn
center: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# 使用兩個工具
## 分別是
- R
- RStudio
## 安裝 R
- OSX 從 The Comprehensive R Archive Network([CRAN](https://cran.r-project.org/))下載 .dmg 檔進行安裝
- Windows 從 The Comprehensive R Archive Network([CRAN](https://cran.r-project.org/))下載 .exe 檔進行安裝
## 安裝 RStudio
- OSX 從 [RStudio](https://www.rstudio.com/products/rstudio/download3/) 下載 .pkg 檔來進行安裝
- Windows 從 [RStudio](https://www.rstudio.com/products/rstudio/download3/) 下載 .exe 檔來進行安裝
# 使用介面
## 第一次執行
```{r, out.width = "680px"}
knitr::include_graphics("https://storage.googleapis.com/learn-r-the-easy-way.appspot.com/screenshots_ch1/ch106.png")
```
## 新增一個 R 程式
```{r, out.width = "680px"}
knitr::include_graphics("https://storage.googleapis.com/learn-r-the-easy-way.appspot.com/screenshots_ch1/ch107.png")
```
---
```{r, out.width = "680px"}
knitr::include_graphics("https://storage.googleapis.com/learn-r-the-easy-way.appspot.com/screenshots_ch1/ch108.png")
```
## 完整的四個區塊
- 來源(Source):位於左上角,編寫程式的區塊
- 命令列(Console):位於左下角,執行程式的區塊
- 環境與歷史:位於右上角
- 檔案、圖形、套件、查詢與預覽器:位於右下角
## 建立變數的符號
- R 語言的使用者習慣使用 `<-` 來建立變數
- 在 RStudio 中可以按 `Alt 與 -` 來產生 `<-` 符號
- R 語言是**動態型別語言**,這表示你可以很有彈性地改變變數
## 也可以使用常見的等號
- 你也可以用與其他程式語言相同的 `=` 來建立變數
- 但是我推薦使用 `<-`
## Case Sensitive
## 使用 `#` 做註解
## 包含多筆資料
- 使用 `c()` 函數
## 第一個函數
- 在命令列(Console)輸入 `q()` 可以離開 RStudio
# 補充閱讀
## Git
- Git 版本管理逐漸成為現代程式設計的必備技能
- 有興趣的同學可以閱讀
- 系統訓練班亦有 Git 版本管理的假日專題班課程(10 小時)
## 安裝 Git
- OS X 內建 Git,不需要進行安裝
- Windows 至 [git](https://git-scm.com/download/win) 下載 .exe 檔來進行安裝
## 申請 GitHub 帳號
- 至 [GitHub](https://github.com/) 申請一個帳戶
## 基本的命令列指令
| 指令 | 說明 |
| ------------- |--------------------------|
| cd | 切換目錄 |
| pwd | 取得目前所在的位置 |
| ls | 列出目前的檔案列表 |
| mkdir | 建立新的目錄 |
| touch | 建立檔案 |
| cp | 複製檔案 |
| mv | 移動檔案 |
| rm | 刪除檔案 |
## 設定 Git
- 告訴 Git 你的帳戶與電子信箱
- 在終端機輸入:
```
git config --global user.name "YOUR NAME"
git config --global user.email YOUR EMAIL ADDRESS
```
## 建立一個遠端 repository
- 至 [GitHub](https://github.com/) 建立一個遠端 repository
- 將新建的 repository 複製回本機資料夾
```
cd ~
git clone "YOUR REPOSITORY URL"
```
## 將本機新增的檔案推到遠端 repository
- 在本機資料夾新增檔案
- 存檔後在命令列輸入:
```
git add .
git commit -m "first commit"
git push
```
- `git commit -m` 後面的訊息可以自訂
## 練習
- 上傳兩個檔案至 GitHub
- RStudio 螢幕截圖
- hello_world.R
```{r, results = 'hide'}
# hello_world.R
print("Hello world!")
```