Lesson 1: R Basics


Before starting this lesson you should have completed all of the steps in Lesson 0. If you have not, go back and do the lesson now.

By the end of this lesson you will be able to:

  • Make an R Project.
  • Commit to Git.
  • Push to Bitbucket.
  • Read in and manipulate data.
  • Make a figure and save it to PDF.
  • Create an R Markdown document.

The video below provides an overview of the lesson and some more detailed explanation of the R code we’ll write below. A PDF of the slides can be downloaded here. Before beginning please download this text file, it is the data we will use for the lesson. We’ll be using some fake picture naming reaction time data from bilinguals and monolinguals. All of the data and completed code for the lesson can be found here.

Make an R Project

An R Project is a powerful way to have a self-contained environment for each of your projects. Using Projects also allows us to commit to Git which is a useful method of version control. Before we make a Project though we’re going to start by making our directory that will store everything we’re going to do in RStudio. I’m going to create a folder called “rcourse_lesson1” and then inside of it four folders: 1) “data”, 2) “figures”, 3) “scripts”, and 4) “write_up”. See the example folder below.Screen Shot 2016-02-11 at 2.49.33 PM.pngI’m also going to put my data file (“rcourse_lesson1_data.txt”) into my “data” folder so that it looks like below.Screen Shot 2016-02-11 at 2.50.44 PM.pngOkay, we’re now ready to make a Project. To make a new Project, go to the top right hand corner of RStudio and click on where it says “Project: (None)” and then choose “New Project…”. An example screen shot is provided below. I want to quickly note that your RStudio may not look exactly the same as mine. For example, you may have the console in the bottom left hand corner instead of the top right. If you want to change the arrangement of your panes go to “Preferences” → “Pane Layout”.Screen Shot 2016-02-11 at 3.00.28 PM.pngYou will be asked if you want to save the current workspace. If you have something important there click “Save”, if you’re not sure click “Save”, otherwise feel free to click “Don’t Save”. A window will then popup asking you how you would like to create your project: 1) “New Directory”, 2) “Existing Directory”, or 3) “Version Control”. See below for an example of what the window should look like.Screen Shot 2016-02-11 at 2.55.05 PM.pngSince we just created our folder structure choose “Existing Directory”. Then use the “Browse…” button to find our root folder. The file path to mine is “~/Desktop/rcourse_lesson1”, as displayed below, since I created my folders on the Desktop. Note, DO NOT browse into one of the sub folders we created (e.g. “data”), be sure to only browse into the main root directory.Screen Shot 2016-02-11 at 2.56.58 PMWhen you’ve navigated to your folder click “Create Project”. You’ve just successfully created a R Project!

Commit to Git

Before beginning any coding we’ll want to make sure that our version control (Git) is set up. To do this go to the top right hand corner that you went to originally to make your project. It should now say the name of your project (for example, mine says “rcourse_lesson1”). Click on it and then choose “Project Options…” as shown below.Screen Shot 2016-02-11 at 3.03.43 PM.pngA window will pop up called “Project Options”. On the left hand side menu choose “Git/SVN” and change the setting of “Version control system” from “(None)” to “Git”. A message will then pop up asking you if you confirm the Git repository, say “Yes”. You will also get a message asking if it is okay to restart RStudio, say “Yes”. You should now see the word “Git” on its side in grey, red, and green in the top menu bar. If you navigate back to the “Git/SVN” page of the “Project Option” it should say “Git”. An example screen shot of the “Project Options” window after you’ve set “Version control system” to “Git” is below.Screen Shot 2016-02-12 at 1.09.18 PM.pngNow that we have Git enabled for our project we should actually commit something. We don’t have much to commit seeing as we have no scripts or figures, but we do have our initial folder structure and the data. To commit to Git click on the sideways “Git” in the menu bar and choose “Commit…”. An example is given below.Screen Shot 2016-02-11 at 3.11.03 PM.pngThis should give you a pop up window that lists everything new that hasn’t been committed to Git yet. To commit something either click the box under “Staged” or select an item and then click “Stage” in the top menu. Select everything so that all boxes are checked (as shown below). Finally, write a message in the window for “Commit message”. Generally for my first commit I just write “Initial commit.” as is done below. When you’re ready click “Commit”.Screen Shot 2016-02-11 at 3.17.52 PM.pngYou will now see a window that summarizes all of the changes committed to Git, click “Close”. You should notice that the box that previously listed our files is now empty, that’s because you have nothing new to commit. You can now close this window. Good job, you’ve just done your first Git commit!

Push to Bitbucket

In addition to committing locally on our personal computer, we’re also going to be pushing our R code up to Bitbucket. When you’re committing to Bitbucket for the first time there are a few steps you need to do. After your first commit though everything will be done directly in RStudio.

Logon to Bitbucket and on the top menu bar choose “Repositories” and then “Create repository”. See example below.

Screen Shot 2016-02-11 at 3.26.18 PMOn the following page type in the name of your repository in “Repository name”, I chose “R Course: Lesson 1”. Leave everything else as is and click “Create repository”.

Screen Shot 2016-02-11 at 3.27.13 PM.pngYou should now be on a page like the one below. Under the section for “Command line” click on “I have an existing project”, as we do indeed already have a directory and one initial Git commit. You should see some Terminal code in the box under “Already have a Git repository on your computer? Let’s push it to Bitbucket.” We’ll go through each line now.

Screen Shot 2016-02-11 at 3.27.25 PM.png

The first line of the Terminal code

cd /path/to/my/repo 

is simply telling you to navigate to your root folder we created earlier. If you are on a Unix-like machine open the Terminal and navigate to the root folder (for me it’s “rcourse_lesson1”). If you are on a Windows machine right click on the folder and choose “Git Bash Here”. Another option is to open the Terminal directly from RStudio, go to the “Git” tab, then “More”, and then choose “Shell…”. This will open a Terminal window already in the folder of your project. This should work fine for Unix-like machines but may be less reliable for Windows machines.Screen Shot 2016-02-11 at 5.53.19 PM.pngOnce you have navigated to the correct folder copy and paste the second line of the code from Bitbucket into the terminal. Remember, the line below is specific to me and my Bitbucket account. Be sure to copy and paste the code that you see in your browser.

git remote add origin git@bitbucket.org:pagepiccinini/r-course-lesson-1.git 

The code should run very quickly and you won’t produce an kind of messages. Now copy and paste the third line of code. If this is your first time pushing to Bitbucket you will be asked if you can accept their SSH RSA key, say yes. Also, if you created a passphrase you’ll have to type it in now.

git push -u origin --all # pushes up the repo and its refs for the first time 

This may take a little bit of time depending on your internet connection, you should be given updates about how far into the upload you are. Finally, copy and paste the last line of code.

git push -u origin --tags # pushes up any tags

If everything ran correctly after this line you should get a message that says “Everything up-to-date”. An example Mac Terminal is provided below.Screen Shot 2016-02-11 at 3.41.02 PMYou’ve now successfully uploaded your R Project to Bitbucket! To confirm this go back to Bitbucket and refresh the page. The instructions for uploading should now be replaced with a summary of the repository and a history of your past commits on the right hand side. An example screen shot is provided below.Screen Shot 2016-02-11 at 3.43.17 PM

Read in and Manipulate Data

Now that Git is set up both locally for the project and with Bitbucket we can finally start coding in R. In RStudio go to “File”→ “New File”→ “R Script”. The first thing we’re going to do is read in our data, but even before that we’re going to get ready to read in our data by loading packages. In R the “#” symbol is used for comments. I generally start all of my code with a comment about loading packages and then load any packages that I need. For this lesson we’ll be using both dplyr and ggplot2 Also, if you end a line with four “#”s it is a code block, and can be collapsed using the small black arrow if you want to only look at a certain part of your code. Start your script by writing and running the code below. To run a particular line of code from a script make sure the cursor is on the line of code you want to run and press Command+Enter on a Mac or Ctrl+Enter on a Linux or Windows machine. To run several lines of code, highlight all the lines you want to run and then press Command+Enter or Ctrl+Enter. You can also click the “Run” button in the top right hand corner of the script. Remember, all of the code fully commented can be found at the link at the top of the lesson.


We can now read in our data. Again I’ll start with a section header comment to note what I’ll be doing in this section and then a sub comment with more specific information about this call. Write the following code and then run it.

# Read in data
data = read.table("data/rcourse_lesson1_data.txt", header = T, sep = "\t")

To read in data we use the “read.table()” call. For R Projects the working directory is always set to the root folder, so in order to load our data into R we need to first go into the “data” folder and then call the text file, thus our call is “data/rcourse_lesson1_data.txt”. The “header = T” part of the code let’s R know that the first row of our file includes our variable names, so it should be treated as a header not as a row of data. Finally the “sep” command is used to tell R what format the data is in. This is a tab delineated file so we set “sep” to “\t”.

Now that we have the data loaded we can look at it. Below are some calls to examine our data such as “dim()” (which tells us the number of rows and columns), “head()” (which prints the first six rows), and “tail()” (which prints the last six rows). I’ve also included an “xtabs()” call, which is a way to see how many data points are in a given level of a variable. For example, the call here sees how many data points we have in the two levels of “group”, “bilingual” and “monolingual”. Write and run the code below.

# Look at data
xtabs(~group, data) 

So far all of this has been basic R code, but now we’re going to use some dplyr code for the first time. Let’s say we want to create a new data frame with only data from our bilinguals. To do this we need to subset out, or filter, “data” to only include bilingual data. We’ll save this to a new data frame called “data_bl”. The code for how to do this is below. For more information on what each part of the code means watch the video or look at the slides at the top of the lesson. Remember, this code will only run if you loaded the dplyr package earlier.

# Subset out bilinguals
data_bl = data %>%
          filter(group == "bilingual") 

The main thing that may seem strange to you is the “%>%” code. This is called a “pipe” in dplyr terminology or an infix operator in more general R terminology. It is a way to letting R know that you’re not done writing code. So, R will not execute the code until it gets a line that doesn’t end in “%>%”. As a result you can stack several dplyr calls in different lines which gives you cleaner, easier to read code. See the video and slides above for an example of adding another “filter()” call.

We can now look at our new data frame “data_bl” just like we did for “data”. We can see that it has half as many rows as “data” with “dim()”. Using “xtabs()” we also see that there are no data points for “group” “monolingual”, which is good since that was our goal with the “filter()” call. I’ve also added another “xtabs()” call on the variable “type”. We see that bilinguals are split into two types, “high” and “low”.

# Look at bilingual data
xtabs(~group, data_bl)
xtabs(~type, data_bl) 

Now that we’ve done a fair amount of coding it’s a good idea to save our script. Be sure to save the script in the “scripts” folder as shown below. Here I named my script “rcourse_lesson1”.Screen Shot 2016-02-11 at 4.36.50 PMSince we saved our script we’ll also want to commit it to Git. To do this go back to the “Git” menu at the top and choose “Commit…” just like we did for our initial commit. Once again check all of the boxes of changed files and write a message in the “Commit message” window, I wrote “Made script.”. When you are ready click “Commit”.Screen Shot 2016-02-11 at 4.39.29 PMClick “Close” on the message window but don’t close out of the Git window just yet. We’ve committed to Git locally but we haven’t pushed that commit up to Bitbucket. To do that all you have to do is click the button in the top right hand corner that says “Push” with an upwards pointing arrow. You will get a message about the commit. When it is done click “Close” and then close out of the Git window. To confirm that your push to Bitbucket did indeed take place go back to Bitbucket in your browser and refresh the page. You should now see your newest commit with its message in the right hand side of the page as shown below.Screen Shot 2016-02-11 at 4.43.36 PMSee how easy that was! All future commits and pushes can also happen directly within RStudio, letting you have both a local and online record of all of your work.

Make a Figure

We’ve now gotten some experience with dplyr but none yet with ggplot2, specifically making a figure. We’ll start by making a boxplot of reaction times separated by our two groups. To do this type in and run the code below. Again, I’ve started with a section header and then another sub comment about the plot itself.

# By group
data.plot = ggplot(data, aes(x = group, y = rt)) +

See the video and slides for details of each part of the code. The key features to note are that every plot in ggplot2 is initiated with the call “ggplot()”. We then give it our data frame and set the aesthetics (“aes()”). On the second line we say what type of plot we’ll be making, in this case a boxplot. Most ggplot2 specific plots are made with “geom_” and then the type of plot to make, in this case “boxplot”. Also note that for ggplot2, to connect lines of code we use the “+” operator not the “%>%” operator. All of this is assigned to “data.plot” and then we call “data.plot” to see the figure.

Right now we only have our plot locally in RStudio. Presumably you’ll want to get a file version of the plot to include in papers or presentations. Below is an updated version of the code to print the plot to a PDF. The first line calls the call “pdf()”. Note, I want my figure to go into my “figures” folder, so when I give the file path to “pdf()” I start with “figures/” before naming the plot “data.pdf”. I then have my plot call and end with “dev.off()” to close the graphics device “pdf()”. If you look in the “figures” folder you should now find a PDF of the figure you saw in RStudio.

# By group
data.plot = ggplot(data, aes(x = group, y = rt)) +

Once again we need to commit our updates to Git and then push to Bitbucket. Go to “Git” in the top menu, “Commit…”, select all modified files, write a commit message (e.g. “Made figure.”), and then click “Commit”. Before closing the window be sure to click “Push” to send it up to Bitbucket. Now when you refresh Bitbucket in your browser you should see your most recent commit.Screen Shot 2016-02-11 at 4.59.53 PMYou have successful made a figure, saved it to a PDF, committed your work to Git, and pushed that commit up to Bitbucket. Congrats!

Create an R Markdown Document

The final thing we’ll be doing today is creating an R Markdown document to showcase all of our amazing work. The first thing we need to do is save our environment, which has our data, our subsetted data, and our figure. To save the environment be sure you are in the “Environment” tab in RStudio, then click on the figure of the floppy disk to save it. See the screen shot below. A red arrow is pointing to where you should see the floppy disk. Remember though, the “Environment” tap may be in a different pane on your screen.Screen Shot 2016-02-17 at 10.16.39 AM.pngChoose your “write_up” folder for where to save the environment and give it a name like I did below such as “rcourse_lesson1_environment”. Press save when ready.Screen Shot 2016-02-11 at 5.05.54 PMNow with our environment saved we can start writing up our results. To make an R Markdown document go to “File” → “New File” → “R Markdown…”. Either now or in a moment you may be asked to install some packages. These are required to create our documents, agree to any package installs. A window will pop up asking for more information. Make sure “Document” is chosen from the right hand side bar (it should be automatically). In “Title” write whatever you want, I’ve chosen “R Course: Lesson 1”. For “Author” it should be your name by default, if not fill in your name. For “Default Output Format” choose “HTML” if it is not already selected. When you’re ready click “OK”.

Screen Shot 2016-02-11 at 5.09.51 PM.png

The file will by default have some text pre-added that give examples of how to use R Markdown documents. Feel free to read through it, but when you’re ready delete everything below the following code

title: 'R Course: Lesson 1'
author: "Page Piccinini"
date: "February 11, 2016"
output: html_document

and on the first line below the second set of “—“s type


The use of the " {r} " and final  " ” let’s RStudio know that this part should be read as R code, not as normal text. Any time you type text not inside those commands it well be printed the same way it would be in text file and not read as code. The “load()” call tells RStudio to read in that environment file we saved earlier. Note, up until now all file paths have been based on the root directory, so why don’t we write “write_up/rcourse_lesson1_environment.RData”? It’s because RMarkdown documents are special, and their directory is based on where the R Markdown document itself is saved, so we can just directly type the name of the environment file since it will be in the same folder as our R Markdown document.

On the next line we can start writing up our document. Type in the text below:

# Data

Here is a look at our two data frames. First is the one we read in, the second is our subset of just the bilinguals' data.


Here's a figure of the bilinguals compared to the monolinguals.

Note, that this is just regular text, and is not enclosed it our command to be run as R code. Also, while in R scripts the “#” is used for commenting in Markdown “#” is used to mark formatting, specifically sections, “#” is the highest section “##” a subsection and so forth.

We’re not going to want to just write about our data and figure though, we’re going to want to actually see them. I’ve updated the code to now include two chunks of R code, the first will  display the first few rows of both of our data frames and the second will print our figure. I’ve also added the “fig.align=’center’ ” call to make sure our figure is centered.

# Data

Here is a look at our two data frames. First is the one we read in, the second is our subset of just the bilinguals' data.



Here's a figure of the bilinguals compared to the monolinguals. {r, fig.align='center'} data.plot

When you have all of this typed into your R Markdown document click the button that says “Knit HTML”. You will be asked to save the R Markdown document before continuing. Navigate to the “write_up” folder, name your file, and save it. See example below.Screen Shot 2016-02-11 at 5.29.12 PMPress “Save” when ready and it will create your document. You show now have a document something like the one below that.Screen Shot 2016-02-12 at 1.03.37 PM.pngIf you want to make a PDF instead of an HTML file simply go back to your R Markdown document and next to where you clicked “Knit HTML” there should be a downward pointing black arrow, click it and choose “Knit PDF”. You can switch back and forth between HTML and PDF as much as you like. Note, if you do not have some kind of Tex installed this will not work. RStudio’s PDF compiler is based on Tex. This should give you a PDF like the one below.Screen Shot 2016-02-12 at 1.03.47 PM.pngAs always we’re going to want to commit these changes to Git and then push up to Bitbucket. Go to “Git” in the top menu, “Commit…”, select all modified files, write a commit message (e.g. “Made write-up.”), and then click “Commit”. Before closing the window be sure to click “Push” to send it up to Bitbucket. Now when you refresh Bitbucket in your browser you should see your most recent commit.

If you are done with the lesson you can also close the project. It’s important to close projects, otherwise you might start working on a new analysis in an unrelated R Project. To close your project go to the dropdown menu where your project name is written and click “Close Project”. An example screen shot is provided below.Screen Shot 2016-03-22 at 1.17.39 PM.png

Conclusion and Next Steps

We got through a lot today, congrats! You can now do a lot of basic functions in R in a very sophisticated way, and you can summarize you work in a nice document to share with the world. If you want to keep going with this Project look at my full script linked to at the top of the lesson. You’ll see I made a second figure with just the bilinguals and a third figure with a different way to visualize the original data. I also computed some descriptive statistics using dplyr’s “group_by()” and “summarise()” calls. We’ll be using more dplyr code throughout the course, but if you’d like a jump start I highly recommend Hadley Wickham’s tutorial at useR 2014. Happy coding!


Add yours →

  1. If I remember correctly you never explained how to properly get a data file from github into R. As of now, this is not trivial (for me). I don’t really get it and am still looking for solutions via Google… this is a bit annoying (because I think I should be able to do it easily, but I am not )

    • There’s a couple ways you can do this. One is to go to the repository for the entire lesson and click “Clone or download”. You then get the option to download a zip file that includes all of the completed scripts and the data. If you go specifically to the data file itself, you can click “Raw” and then either copy and paste the information to a text file, or “Save As…” to a text file.

  2. I think this would profit from a bit more information on what we really need Bitbucket and GitHub for. How can we use it and profit from it?

    • I discuss this a bit in the video, but don’t go into too much detail. For more information about the benefits of Git I’d recommend checking out this tutorial by Jennifer Bryan (http://happygitwithr.com/) that will be given at the upcoming useR! 2016.

    • This annoyed me for ages everytime I wanted to download something from github, couldnt find it anywhere.

      So if you want to download a single file, click on it to be on the right page, then right-click the “Raw” button on the top right, and then “save link as”.

      Thank you so much pagepiccinini for this really well written tutorial! Hopefully I can start managing my data propertly soon.. R is so intimidating, but seems very handy

  3. I just wanted to say how much I like this R course. Although not a beginner with R, I’ve learnt some useful new stuff. Keep up the great work!

  4. Thank you so much for creating these very informative, highly organized tutorials and videos. I wish I had found these earlier!!

  5. I think I duplicated the lesson but when I go to my github page (as opposed to my BitBucket page) I don’t see a repository with all of the committed material. What am I missing.

    • If you want to push to GitHub you have to be sure that you both made the repository on GitHub and added the remote origin for GitHub for your project. Assuming you did that it should work!

      • Dr. Piccinini:

        First, I should have said earlier that your R course is simply excellent. I say this for at least four reasons (so other near-novices like me might take the decision to invest time to work through your examples as I am certain they will find it much worth the effort):

        – you show VERY clearly how to set up R projects and even what a “project” means in RStudio. I may be on the dull end of your students, but I never understood what a “project” was, why it was important (as opposed to just saving scripts into a folder without an explicit .RProj) and how to organize it. Now I do. Thank you, THANK YOU.

        – you describe well the integration of projects created in RStudio with version control sites (or at least with BitBucket).

        – and your melding of basic statistical principles with useful R language is quite understandable. As I think many people would observe, R can be extremely obscure and the “help” files in R are often anything but “helpful”

        – your design of the videos and the assigned work in the lectures is as close to perfect for a non-advanced student.

        I also can’t quite find the words to compliment you on your approach to organizing projects: stratifying one’s work into data files/cleaning, figure generation, scripts for the actual analysis and write-up (with RMarkdown interacting with the items in the environment created by the forgoing) is brilliant. Maybe others have approached their R-related work this way, but I’ve never seen it presented so logically and professionally. Bravo!

        Two suggestions:

        – Github (and other version control software) is a giant black box when first confronted. It is not at all clear (until making many errors) that “committing” is not the same as uploading, and beyond that what a “branch” means. Ditto for FIRST creating a project’s storage site on Github or BitBucket. Perhaps you can make the process (and the logic and the terminology) a bit more transparent.

        – I know there are ways to create a repository from the command line (the command line is, of course, in and of itself terrifying to many of us) BEFORE then using it (? via somehow downloading or cloning it to one’s local machine). Perhaps you can enlighten us on that as well.

        I don’t know when I’ve come across a better-thought-through instructional site involving R. I realize you aren’t teaching an entire R course, but you surely make getting one’s familiarity with the language as well as data integration solid enough to make additional learning easier.


      • Thank you so much for all of your generous comments! Students like you are exactly who I designed the course for, so it’s great to get such positive feedback.

        Regarding your comments on git and GitHub/Bitbucket, these are entirely valid and something I need to consider. I’ve gotten comments from other students as well that this topic is rather opaque and could benefit from more explanation. For the moment I’ve been directing people to Jenny Bryan’s Happy Git (http://happygitwithr.com/). However, I’m thinking more and more that my course would benefit from a separate lesson focusing on git in more detail on topics such as branches, committing versus pushing, and other areas you bring up. Hopefully, I’ll have time soon to add some kind of lesson like that to the course.

        Thank you again both for your comments and suggestions! I hope the course continues to be useful to you as you work on your own projects in R!

  6. Hi again Dr. Piccinini:

    I think one ambiguity is that the concept of ‘git’ is a repository service and BOTH ‘GitHub’ and ‘BitBucket’ are implementations such a service (please correct me if I err here). To the novice (I am guilty as charged) it appears that ‘GitHub’ is a ‘git’ service whereas that is less clear with ‘BitBucket’ (although if I understand correctly it is a ‘git’ service wherein the repository is, by definition, private to the user whereas ‘GitHub’ repositories are public (unless one pays for private repositories). So, as you might imagine, when instructed to make a ‘git’ ‘commit’ (both jargon-y of course) its kinda natural to be confused that ‘BitBucket’ is every bit (oops! no pun intended) as much of a repository as is ‘GitHub’.

    I did indeed look at Happy Git before I wrote the previous post, but got lost. It sort of helped but could have been more explicit in its instructions.

    I think (but could be wrong) that most students would like to understand how to create a ‘git’ repository on both their local machines AND on one of the repository services from the command line (just so one can understand what is going on under-the-hood). I would imagine — please correct me again — that that is PRECISELY what RStudio is doing (i.e. effectively issuing command line code) when one ‘commits’ and then ‘pushes’ to either BitBucket or GitHub.

    Now that I look back on what I have written, I realize that your course has taught me even more than I realized. A few days ago I would never have been able to use ‘commit’ or ‘push’ correctly. That’s a lot of progress.

    One final question: suppose I want to download the data for your lessons from your GitHub account directly into a RProject I have established (e.g. the ‘data’ folder you might use for a given lesson). Is there a simple way to do that? Otherwise I find myself going to your GitHub account and one-by-one downloading the files and then moving them by hand into my RProject. Not a lot of fun.

    In any case, looking forward to working through all of your very VERY well-thought-out lessons. Couldn’t ask for more.

    • You are correct that the difference ‘git’ versus GitHub/Bitbucket can be confusing. To repeat what you said in other words, ‘git’ is a command line version control system, whereas GitHub and Bitbucket are both website where you can push your projects with git version control to. Think of GitHub / Bitbucket as another back-up system, similar to saving your work to a second hard drive. GitHub and Bitbucket are just two such online services that provide roughly the same product (online backups of projects). In the course I chose to illustrate with Bitbucket since (as you say) it allows free private repositories, but I saved the lessons publicly to GitHub since, in general, that’s where most people save their public work.

      Yes, RStudio is taking away the command line aspect of git and letting you do it all within the GUI (well almost all, when you first pushed up to Bitbucket you had to open up the terminal). However, there are a lot of limitations with RStudio’s git interface. For example, if you want to make branches you have to do it through the terminal. GitHub also provides their own git GUI, GitHub Desktop (https://desktop.github.com/), that provides more options than RStudio’s. Several other GUIs exist too, but I think you’re right that an initial basic understanding of how git works directly in the command line is important before moving to GUIs.

      That’s a couple ways to download directly from GitHub. One, if you go to the page for the lesson (e.g. https://github.com/pagepiccinini/rcourse_lesson1) you can download the entire repository with the “Clone or download” button. Then you can move the “data” folder or whatever you want into your project folder. Outside of downloading the entire repository the options aren’t as good. As you said, you can do the one by one download, which can be a pain. So my main suggestion would be download the entire repository and select the folders / files you want, or clone the repository to your GitHub account, and delete any files you don’t want (e.g. scripts files if you want to make them from scratch).

      I hope that helps! Happy coding!!

  7. Still using this page each time I create a project.
    Please never delete it 🙂

  8. Dear Page!

    Thx a lot for your tremendous R course!

    It seems though, that the bitbucket website has changed and so the “Command line” section with “I have an existing project” is not shown anymore. Following your instructions unfortunately leads to an fatal error messagen in git bash “fatal: Could not read from remote repository.Please make sure you have the correct access rights
    and the repository exists.” I’m pretty sure, that I’ve named the bitbucket repository correctly and have also added correctly the SSH-RSA key as described in your lesson 0!

    Thank u so much for your help!

    Best, Gregory

  9. Dear Page!

    I just wanted to comment, that I figured out the reasons for the problems I mentioned in my post on 25 March: One problem was that Bitbucket commits per default a readme file when creating a repository (no initial push from local git is performed because of the inconsistency due to this readme file in the Bitbucket repository) and the second problem was unfortunately a typo on my side when defining the remote Bitbucket repo in Git Bash and my lack of Git knowledge, how to correct this statement!

    Now everything is working just fine as you show in your course! :-))

    Thx again for your great R-Course-Lessons!!!

    Best, Gregory

  10. Hi…Thank you very much for this great course!!!
    Can you update the figures and instructions to the “New Layout” in Bitbucket?
    Now, there is not an option for “existing project”, and when I try to upload my local folder I receive a “fatal error” (or something like that!…)

    Thanks again!

    • Glad you enjoyed the course! I’m trying to find time to update for the new Bitbucket layout. Hopefully in the next few weeks I’ll be able to make the necessary updates.

      • I ran into the same issues. To save the time for yourself, you might consider just copying Gregor’s helpful comment. Simply un-checking the default setting for creating a README file puts everything back on track.

    • Although english is not my native language i´m going to try to help a bit because this part of synchronising our project in R with Bitbucket was a real pain in the ass.

      First like Gregory has said, when you create the repository DON´T create by default the README foulder. Then it´s going to appear TWO lines of code that you have to copy and paste in the “Git Bash Here” (in Piccinini´s page appear 3 lineas of code).

      And here it cames what was my biggest misstake, I was trying to synchronize the “rcourse_lesson1” on “Git Bash Here”, there I was recibing the “fatal err”.##Then I tried on the “data” foulder inside rcourse_lesson1####. From that moment I finally was abble to see in the Bitbucket webpage everything synchronize!!! =D

      Saludos! and I hope this was usefull!

      Thanks you a lot Dr. Piccinini

  11. Hi Javier!

    I had the same problem (have a look on my post on 27.03.2018): In the new Bitbucket Layout you just have to uncheck the per default by Bitbucket included readme file when creating the repository, than everything will just work out fine! Otherwise there will be a fatal error at initial push because of the inconsistency due to this readme file in the Bitbucket repository.

    Best, Gregory

    • Austin Nottingham September 18, 2018 — 4:34 pm

      Hello. I’m encountering the same fatal error problem. Will deleting the readme from my existing repo fix that? If so, how do I delete the readme? Also, ever since I tried to connect git to rstudia I get a strange error every time I open rstudio. In the title bar it says svn.exe – system error
      in the body of the text box I’m getting
      The program can’t start because libapr-1.dll is missing from your computer. Try reinstalling the program to fix the problem. I’ve reinstalled twice now and the problem doesn’t go away. Is this related to that fatal error or is it a separate issue?

      • Hello Austin!
        You can delete the readme file, or any other file in a bitbucket repo, simply via clicking on the specific file and selecting afterwards inside the “…”-menu field, right beside the “edit”-button, the “delete” command. That should fix the issue when pushing your local repo for the first time to the remote new bitbucket repo, as described in this lesson.
        It seems though that you have also a kind of issue with another version control tool, called “subversion” (SVN). Besides “Git”, “SVN” can also be integrated in RStudio in Tools/Global Options/Git/SVN where you set the corresponding executable “svn.exe”. However, this has nothing to do with integrating the chosen version control “Git” as shown in this lesson. So have a look, if there is any path defined for an “svn.exe” file within “Tools/Global Options/Git/SVN” in RStudio and delete the path, so there will remain only the path for the “git.exe”. This may solve your described issue.
        Best, Gregor

      • Austin Nottingham October 8, 2018 — 7:14 pm

        Thanks for the tip about file deletion. It’s straightforward, but not intuitive. Also, I resolved the SVN issue by locating and deleting my Rstudio profile folder and then restarting Rstudio. This had the effect of also resetting the appearance preferences, but those were trivial to re-implement.

  12. Hello! I am following your course and enjoying it very much. I have an issue though, Bitbucket has been updated, so there’s no section “Command Line, then I cannot insert the command to upload the project to it. Could you help me?

    • Hello Katia, I have the same problem.It is driving me crazy- Removing the README. file as suggested in other comments has not solved the issue for me, I still get “fatal errors”.

      Have you managed to find a solution that works with the updated Bitbucket?

%d bloggers like this: