-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRscripts.Rmd
36 lines (26 loc) · 1.24 KB
/
Rscripts.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
# R scripts
## Create and save a script
* Store commands in a .R/.r script. Create and save a script in RStudio with:
+ File -> New File -> R Script
+ Once the file has opened: File -> Save
+ Specify a name: ***the extension .R is automatically added***
<img src="images/rscript_rstudio.png" width="500"/>
* Execute commands or blocks of commands from RStudio:
<img src="images/rscript_rstudio_cmd.png" width="500"/>
## R syntax
* Case sensitive: **g** is not **G**
* Comment lines start with **#**
* Commands are separated by a **new line** or **;**
```{r, eval=FALSE}
# This is a comment: it will not be interpreted
a <- 10
A + 1
# Will throw an error because A and a are different
```
<img src="images/syntax_error.png" width="500"/>
## RStudio tips in the console
Ctrl + Enter: execute the current line.<br>
<img src="images/arrow_up.png" width="40"/> Upper arrow: goes to the commands previously typed.
Ctrl + cmd + <img src="images/arrow_up.png" width="40"/> : Browse command history.
<img src="images/tab_key.png" width="50"/> Type a letter in the console + "tab": R Studio proposes the different functions or object stored which start with that letter. <br> for example, type **get + "tab"**:
<img src="images/tab_functions.png" width="350"/>