Python has quickly gained traction as a competitor and companion to R in the world of data analysis. As such, being able to use this immensely versatile language is quickly becoming an essential skill in epidemiology work. Here, we’ll take the first steps on your Python journey by going through how to download Python, as well as a suite of tools including an Integrated Development Environment, PyCharm.
How To Download and Install Python
To get started on our journey with Python, first, you must download it from the official source, which is conveniently called python.org. Once you are on the home page, head over to the downloads tab, and select the page for your specific OS. On the OS page, you should select the “Latest Python 3 Release” if you have a more modern OS, or otherwise select Python 3.7.13 if you have any PC with anything more recent than Windows XP.
The reason we are selecting Python 3 instead of Python 2 is that Python 2 is being sunset for most uses, and has some fundamental differences between itself and 3, which seems like it will continue onward as the standard Python version for some time.
After selecting the version you wish to download, simply scroll down to the “Files” section of the release, and select your preferred method of installation. For most, the Windows or macOS installers will be useful, and for Linux users, the tarball will probably work best. In any case, select your install method, wait for the download to complete, and then open the file. From that point, an installation should take place that may need permissions and should complete itself in a matter of seconds.
As a last check, be sure to go to your computer Search bar and type “py”. You should see the Python version you’ve downloaded as an option, and open it. The screen should look similar enough to a normal command prompt. Go ahead and close it out for now, as we discuss for a moment why you might need an IDE as opposed to just developing code for python using that environment.
Do I need a Python IDE like PyCharm?
In short, yes. Could you run through most analyses of datasets using only the command line? Probably, yes. But using an IDE has very many benefits, such as making it easy to save and debug your work, sharing that work with colleagues, and some even making writing code much faster. One such IDE is PyCharm by JetBrains. PyCharm includes such functionality as code completion, optimization, and simple corrections as well, which makes development quite a bit quicker than it would be otherwise. For this tutorial, we’ll be installing PyCharm through Anaconda, which is a free suite of different tools that can be useful throughout a project or analysis life-cycle. Let’s take a look at how to get you started.
How to install Anaconda and PyCharm
To download Anaconda, simply go to anaconda.com, and at the home page, either hit download or select the icon of your OS and then select your installer. Due to there being so many tools packaged within Anaconda, it can be quite a sizable download of around half a gigabyte.
Once it’s downloaded, an installation wizard will appear on opening. Agree to the terms, then select your destination folder. I would suggest keeping this on your local drive (usually the C: Drive) and creating its own folder. From there, select any advanced options you wish and hit install. After a few moments, you should be able to hit next again and encounter an offer to view the Anaconda Individual Edition Tutorial and Getting Started with Anaconda, which you can view if you so wish. From there you can hit the finish button and you’re all set.
Going forward in these tutorials, we will be using a tool within Anaconda that’s made by JetBrains called PyCharm. It’s a lovely IDE that is very feature-rich and even has fairly informative error handling which can help you spot errors and fix them quickly, which is usually a daunting task with any level of analysis. To open PyCharm, open Anaconda and wait for it to load for a moment. From there, select “Launch” under PyCharm, and you should be all set.
How do I get started with PyCharm?
Upon opening PyCharm for the first time, you might be a little lost on how to get started, and that’s alright. Luckily, the PyCharm team has made some excellent tutorials on their IDE and made them immediately available to you upon opening. While it might be tempting to dive right in and click New Project, instead give the onboarding tour a quick go, and then once you’ve completed that, play around in the Learn PyCharm tab. Both of these steps will help build an understanding of the IDE you’re working with and will make learning Python much faster as you won’t have to juggle learning the tools and the language at the same time.
Once you have the tutorials completed, it’s a good idea to set up some folders to put your eventual python files and projects so that your computer doesn’t become a mess of such files. Also, structuring where you’ll be putting things will help you in the future if you wish to use something like Github for sharing and improving your code.
Summary
In this article, we’ve quickly covered how to download one of the most versatile programming languages around, Python. We also quickly covered how to download Anaconda, a suite of data analysis tools and IDEs, and how to get started with PyCharm, which will be used in future articles. Our next articles will cover the basics, including variable creation, data importation, and Exploratory Data Analysis in both Python and R.
Welcome to the inaugural post of the Broadly Epi Blog, where we will be covering how to do various analyses in R and Python! Before we can begin any real journey into how to use R for data analysis, we first need to ensure that you have R installed, and an IDE, or Integrated Development Environment. To these ends, we’re going to tackle a quick walk-through of how to download and install R and RStudio, as well as some customization tips for the latter. For those of you wanting to learn Python, a sister post should be up shortly. Going forward, every effort will be made to create paired posts, examining how to solve the same problems in both R and Python.
How To Download and Install R
To download R, the first thing you’ll need to do is to pop over to the Comprehensive R Archive Network, or CRAN for short. You can either search for CRAN manually if you like, or click here to be directed right to where you need to be. From the homepage, simply click on the download link appropriate for whatever OS you’re running.
Next, click on the “base” sub-directory. Also, once everything is up and running with R and RStudio, you’ll want to return to this page and click on the RTools option to download it, as it will be useful for packages, which will be discussed in a later blog post.
Once you have selected your desired OS and clicked on the “base” subdirectory, now you just have to click the “Download R 4.1.x for Windows/MacOS/Linux” and wait a few moments for the file to download (at time of writing it’s 86 megabytes in size). Once downloaded, open up the executable file (which should be published by Ooms) and allow changes. From there, it’s as easy going through the install wizard and making sure things are saved to your local drive (usually your C: drive). The reason for this is that if you work in any sort of VPN environment with virtual drives, it can take some serious time to perform operations and run code (think hours instead of seconds).
Do I really need an R IDE like RStudio?
In short, no. Many developers in fact despise RStudio with a burning passion (and in truth, sometimes I do too) so they work off the command line, a simple text editor like Notepad++, or even use other IDEs that were originally built for other programming languages.
A bit of a spoiler but many IDEs, including RStudio, support cross-language scripting! This means that for certain projects, say those that need to use SQL, Python and R, can all be developed in one IDE so there aren’t a bunch of them just cluttering your desktop.
Now as for why I’m going forward with RStudio, it’s quite simple. I’m assuming that anyone reading this could have any amount of R experience, and I find RStudio to be a fairly good starting point for people who plan to use R as part of a greater suite of tools. This is due to the fact that RStudio is approachable, and any “bad habits” picked up from its use can be left behind when the time comes.
Now, as to why we’re using an IDE in the first place, that’s a much easier answer. First, it gives us a program that can help organize, test, and plan out future programming projects. Second, an IDE is basically universal in terms of writing code, whether it’s R, Python, Java or nearly anything else. Lastly, if you plan on working in data science or public health, you’re going to be expected to have some experience with tools like IDEs and maybe even notebooks (which will be addressed later).
How to install RStudio
Installing RStudio is about as simple a process as one could hope for. First, head over to RStudio and click “download free desktop IDE”. From there, I advise “RStudio Desktop” to start out with, click on the download button, and then select what OS you’re working with, and a .exe, .dmg, or .rpm will download depending on your OS option. Then it’s simple as open the file, run through a quick navigation wizard, making sure you’re installing on the C: drive if possible, and opening up RStudio for the first time. Let’s take a look at how to now customize RStudio a bit, and you'll be all set for the upcoming series of analysis tutorials.
How can I configure RStudio?
As with any IDE, there’s a few features out the box that are not configured ideally. First and foremost is the color scheme of the IDE. White background, black text? Not exactly what most people are looking for. Black background with a rainbow of different colors to determine if something is a variable, function, or anything else? Now you’re hacking the planet, or at least looking the part.
To adjust how your RStudio looks, simply go to Tools > Global Options, then select Appearance. From there, have a blast finding out which palette pleases you most. You should also pop down to the Pane Layout and see what fits best. For me, I find having the script window in the top left corner, the console/terminal in the bottom left, the environment in the upper right, and the plots, viewer, and help documentation on the bottom right. That said, do whatever feels right to you, but in future articles it might be worth keeping in mind my specific set up so things don’t get too confusing if I’m giving screenshots alongside GitHub code snippets. For the uninitiated, the script window is used for being able to write, save, and repeat code on demand as well as some other fancy things we’ll get into later, the console is for trying out code you’re likely to only run once, and the environment tab shows what variables you currently have loaded into your current workspace.
Summary
In this very quick lesson, we got you acquainted with how to install R and RStudio. From this point on, we’re going to start using R and RStudio to perform various analyses, build visuals to help examine problems, and later on even create our own Machine Learning models to do some incredible prediction or categorization work. It may sound like a lot to tackle, but ultimately learning such topics will make seemingly insurmountable tasks a question of adapting some code and hitting run.
Websites store cookies to enhance functionality and personalise your experience. You can manage your preferences, but blocking some cookies may impact site performance and services.
Essential cookies enable basic functions and are necessary for the proper function of the website.
Name
Description
Duration
Cookie Preferences
This cookie is used to store the user's cookie consent preferences.