1 Introduction to R and RStudio Server
- Log in into the RStudio Server Pro
- Upload and download files from the server
- Use R as a calculator
- Create first objects in R
- Do you very first plot
This chapter introduces you to R and RStudio which you’ll be using throughout the course both to learn statistical concepts and to analyse real data. To clarify which is which: R is the name of the programming language itself and RStudio is a convenient development environment that will make your life easier.
Today we begin with the fundamental building blocks of R and RStudio: the interface, creating and saving files, and basic commands.
1.1 Opening RStudio Server Pro
We will work in the RStudio Server Pro, an online R System. Thus, you don’t need to install R or RStudio on your computer (yet). You will receive a login and a password for the server. Do not share your credentials. In case of difficulties I might need to log in into your RStudio Server account. To allow me to do so, you need to sign an agreement and to email it me.
Before you can log in into the server, you need to activate the VPN client. If you are not familiar with the VPN client, please visit this website.
To log in into the RStudio Server, click hier. Or copy the address into your browser: https://cheops-rstudio-edu.rrz.uni-koeln.de:8787/auth-sign-in.htm. After logging in, you will see the home interface (Figure 1.1).
To start a new session, click on the button New Session
next to the R symbol and choose the following settings (you can rename the session if you wish):
1.2 The RStudio interface
In RStudio Server you should see a window that looks like in Figure 1.3.
The panel on the left is where the action happens. It’s called the console. Every time you launch RStudio, it will have the same text at the top of the console telling you the version of R that you’re running.
The panel in the upper right contains your workspace. This shows the variables and objects you define during your R session, and a history of the commands that you enter.
Any plots that you generate will show up in the panel in the lower right corner. This is also where you can browse your files, and access help files, and upload and download files.
1.3 File management
We will start by making a data folder in RStudio Server that you can use to store all your data sets. Click on the Files tab in the lower right panel, and the New Folder tab. Enter the folder name data
in the window that opens, and click OK. You should now have a new folder!
Next, go to the course site, and download the file meteo.csv
posted for this week’s session. Put it in a location on your computer that you will remember! I highly suggest you also make a folder for the course and there a data
folder on your computer to store the material for this course.
To have access to files stored on the hard drive on your computer in RStudio Server, you need to upload them from your computer to the server. To upload the data set click on the RStudio Server data
folder once, and click the upload button, like so:
In the window that opens, browse to where you stored your data set on your computer, click on the data file, then click OK. Open the data
folder again in RStudio Server, to make sure the data is in there. You can upload any sort of file like this.
We are not doing anything with this meteo.csv
file, except learning how to upload it.
To download a file first mark it (you can mark several files) by clicking on the little square left to it. Then, click the button More
> Export
> Download
(Figures 1.5 and 1.6). Save the file(s) on your computer.
1.4 Practice on your own!
To complete this problem set you will next run through some Exercises, and submit your R script (i.e. *.R file) with answers to all the Exercises. If you need to type text, don’t forget to use the comment sign #
before typing your text so that R will not misinterpret your text as commands.
Remember to save your work as you go along! Click the save button in the upper left-hand corner of the window.
We will start the exercises C.1.1 and C.1.2 in class. Finish the exercises on your own and produce your first plot in exercise C.1.3 😄.
1.5 Turning in your work
- Save your R script and download the *.R file to your computer.
- Upload your *.R file to ILIAS. You will find an upload option in today’s session.
- You should receive a solution file after the deadline.
Be sure to upload before the deadline!
1.6 Logging out of the server
There are other classes and students using the server. To keep it as fast as possible, it is best if you sign out when you are done. To do so follow all the same steps for closing an R Markdown document as above:
- Save all your work, i.e. the R document.
- Click on the orange button in the far right corner of the screen to quit R.
- Choose don’t save for the Workspace image.
- When the browser refreshes, you can click on the button
Sign Out
next to your login in the top right. - You are signed out!
1.7 Reading assignment
Chapters 1.1 and 1.2 in Ismay and Kim (2021)