Coding1: Setting up Python, R, and your first program. Part 2.
This post focuses on doing the same we did in part 1, but for R. This post is entirely about setting up R, and RStudio, then getting ready to rock.
Table of Contents:
Downloading & Installing R
Setting Things Up
Running a R Script
Your First R Function
Pros and Cons of R/Python
1 - Downloading & Installing R
The direct link to downloading R is located here: (*Link*). The site takes you to the mirrors you can use for downloading it. Pick whichever link you have for your country, and then download & install as normal. Like with Python, make sure you remember where you installed it. As of he time of writing, you want to grab R-4.1.2. Video format you can follow is below.
1.1 Downloading & Installing RStudio
You can download RStudio from here: (*Link*). For now, go with the basic RStudio Desktop. If we end up getting advanced enough, the RStudio Server might come in handy, but for now, stick with the Desktop version. Download, and install RStudio as normal.
2 - Setting Things Up
Once you have downloaded, and installed both R & RStudio, open up RStudio. You’ll see something like the below
Click no to the popup. Click on Tools (at the top) —> Global Options —> General, now make sure it’s pointed to the correct installation path for where you installed R.
Now, click on File —> New File —> R Script. We are now ready to go.
3 - Running a R Script
As with Python, before we can run a script, we must save it to our local hard drive. I’ll recommend saving it in the exact same directory as you saved the python script, it’ll be easy to locate in the future.
In RStudio, clicking on the run button is not good enough. You need to select the lines you want R to run as well.
4 - Your First R Function
For the first R function, we’ll re-introduce the print function here as well. Recall the print function was a way to get the script to generate an output, we’ll use that same thing again. The difference is that in R, we do not have to use it. If we ask R to run a line, and that line runs a simple calculation, R will assume we want it to print the output as well.
Putting everything together below:
5 - R vs Python Summarized
If a company deals with financial time series, they’ll prefer to work with R.
If the job title has the word "Machine Learning Engineer" in it, then you'll use Python. If it's a tech company, you'll use Python.
Click Here to go to Coding2: Variables, Comments, & Errors.