-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_Setting_up_R.Rmd
125 lines (69 loc) · 6.1 KB
/
01_Setting_up_R.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
---
title: "01 Setting up R"
author: "Jillian Dunic"
date: "July 8, 2015"
output: html_document
---
I'm assuming that you have installed R and Rstudio by now. If you have had any problems, please start an issue on the Github page or, if we haven't gotten there yet, send me an email.
You should also log in to your Github accounts now. We will be using them later in the class.
*It is also a good practice to make a directory that contains all of your R projects in one place. I have a directory called R_projects.
*Rstudio projects*
Let's start by creating an Rstudio project. A project is basically a special folder that contains all of the work that you do in Rstudio in that project file. It helps your keep your different projects organised. I suggest that you create a project that will contain all of the work that you do in this course. I use projects to keep track of the code for my manuscripts and R packages that I may be working on.
When you open Rstudio you can create a new project by:
File -> New project
You'll be prompted with a dialog box
![New project dialog box. Make sure you create a git repository (it will create a local repo).](/images/Rstudio_images/Rstudio_create_new_project.png)
We just met git the other day. Be sure that you create a local git repository so that we can keep track of our changes! We'll push it to an online repository shortly.
*Rmarkdown (html)*
Before we jump into coding, let's just make our first text file. We're going to start with a special type of file called Rmarkdown. These types of text files are great! They allow us to write text and embed code, the results of that code, and input figures! It is how I have created this walk-through. We'll start with an html document. These are the most flexible and can be converted to a PDF or MS Word document later.
Let's create our first Rmarkdown file. This is easy in Rstudio!
File -> New file -> Rmarkdown...
Now fill in the title of your document and your name. For now let's select the HTML option.
Now you should have an R Markdown document! You can modify the information at the top of the script as you'd like. You can also start one of these from scratch as just a raw text file but Rstudio sets it up nicely for you :)
Write some stuff Just so you can see it.
*Tracking our changes -- let's use git!*
Instead of using git within Rstudio, let's get more practice using the command line/terminal.
Let's open terminal (Mac users can just go to spotlight and type in terminal)
**If you are on a Windows machine you can access a terminal (instructions from http://smallbusiness.chron.com/open-terminal-session-windows-7-56627.html)
**By keyboard**: 'Press "Win-R," type "cmd" and press "Enter" to open a Command Prompt session using just your keyboard.'
**By mouse**: 'Click the "Start | Program Files | Accessories | Command Prompt" to open a Command Prompt session using just your mouse.'
Let's look back at the notes from yesterday's class.
How do we change directories via the terminal?
A:
> cd path
What's the first thing we should do when we go to use git?
A: Check the git status and check what branch we are on. We can do this with
> git status
![You should see something like this. Today the branch doesn't matter since we should all have master. We will learn more about this later, but for now I want you to just note where this information is. We can see that we have not staged anything. And in red at the bottom we can see all of the new files that have been created that we have yet to add.](/images/git_images/git_status1.png)
Let's stage some files for a commit. You can play with this if you'd like. You can do git status after everything you do to see what's going on.
> git add file_name
or
> git add .
*if you would like to add all the changes that you have made
Great where are we now? If we check git status now, what do you see? Is it something like this?
![The files in green are what you have added and are what will be tracked by git when we commit. The files in red are ones that git is not keeping track of and will not be committed.](/images/git_images/git_add1.png)
Everyone should now have some files staged and ready to be committed. Let's commit and include a message.
> git commit -m 'initial commit'
Awesome. Any questions? Again, turn to your neighbour if you are having any issues.
What we have done now is kept track of our changes on our local computer. But let's now send those changes to a remote repository. Let's all go to our Github pages so that we can create an online repository.
Just as we did yesterday, we're going to hit the big green button on our profile page that says 'New'
![In case you forget. This is the button to make a new repository!](/images/git_images/git_create_repo.png)
Great. We've now made another repository. Copy the link to this repository. It should look something like:
https://github.com/jdunic/Intro-To-Practical-Computing-R
With your username/repo_name
Now we need to go back to our terminal and initiate this online repository.
Add the URL by doing:
> git remote add origin https://github.com/jdunic/Intro-To-Practical-Computing-R.git
Note!!! That we have added '.git' to the end of our URL. If you're getting an error make sure you've typed everything in exactly. Then ask your neighbour to take a second look.
You can check that this all worked by doing
> git remote -v
You should see something like this
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
Is this all set up for everyone? The final step is to **push** our local changes to the remote repository.
> git push origin master
Remember, origin is the name of the remote repository.
This may still feel tricky and over your head. If it does I recommend that you see me in office hours tomorrow and practise one more time on your own. We can do another practice run through at the end of next class if people would like to. The goals is that we do this enough times throughout the semester, that by the end, this should seem trivial. We'll get there!
References:
Setting up a remote repository
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/