7.1.3.Learn programming using RStudio - quanganh2001/Google-Data-Analytics-Professional-Certificate-Coursera GitHub Wiki

Hands-On Activity: Cloud access to RStudio

Activity overview

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

By now, you’ve learned about RStudio, an integrated development environment that allows you to more efficiently create and manage projects using R. In this activity, you will learn how to access the cloud version of RStudio.

Upon completing this activity, you will be more familiar with the RStudio interface and comfortable using its basic tools . This is a foundational step that will prepare you for upcoming RStudio activities during this course. This hands-on activity, and the future RStudio activities you will complete, are essential to developing job-ready R programming skills.

Access RStudio Cloud

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

RStudio Cloud (now called Posit Cloud) is the primary tool you will use for this course. In order to use RStudio Cloud, you need stable internet access. It won’t matter what operating system you have because it works in your browser.

You can also install a desktop version, which you can download based on instructions provided in the next (optional) activity. This is a good alternative if you want to be able to work with R offline.

In order to access RStudio Cloud, follow these steps:

  1. Sign up for an account at the RStudio Cloud sign-up page.

W_p167qFTiq6deu6hd4qcQ_b731483850ad4d0aaaf8e1730b3ac718_Screenshot-2021-03-10-7 20 08-PM---Display-2

Here, you will find more information about RStudio Cloud, including the pricing plans. You will use the free version throughout this course, but it does have a few limitations. You can only have up to 15 projects on your free account, and can only use 15 project hours per month. You might consider upgrading later on if you find yourself using RStudio a lot.

  1. For now, click the Sign Up button on the bottom-right to start with the free version.

lXDdhDLSRpOw3YQy0uaTyQ_1cfdc750e8b64b3181555fbbeecb117e_Screenshot-2021-03-10-7 22 18-PM---Display-2

  1. Input your email, a password, as well as your first and last name.
  2. Once you have signed up, open RStudio Cloud for the first time.

LKG-siapQXOhvrImqUFz3Q_d18cdbd9f60e49229eccbb5eef236ae2_Screenshot-2021-03-10-7 24 44-PM---Display-2

  1. Click **New Project **to create a new project workspace and open the RStudio Cloud console.

znxMEXv8T2m8TBF7_N9pKA_97d24251fe604d87a9e5d461ed53cfff_Screenshot-2021-03-10-7 26 12-PM---Display-2

Install and load packages

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

Once you have opened a new project in your console, you can install packages to RStudio Cloud.

Packages are units of reproducible R code. Members of the R community create packages to keep track of the R functions that they write and reuse. Packages offer a helpful combination of code, reusable R functions, descriptive documentation, tests for checking your code, and sample data sets.

The lubridate package that you are about to install is part of the tidyverse. The tidyverse is a collection of packages in R with a common design philosophy for data manipulation, exploration, and visualization. For a lot of data analysts, the tidyverse is an essential tool. You will learn more about the tidyverse later on in this course.

To install the core tidyverse packages and load them, follow these steps:

  1. In the bottom of the console, type install.packages("tidyverse") and press Enter (Windows) or Return (Mac).

vCcs9_32QJ-nLPf99hCf5g_a32a8b6ec85941c8a0a40dc1badaaff1_Screenshot-2021-07-01-11 41 05-PM

This may take a while. You can tell if the process is still running by checking the red Stop icon in the upper right of the console. You can click this icon to interrupt the running code and cancel the command.

epRMQ8RORAyUTEPEToQMQA_876d538430214da6a1a707c6db48a4f1_stop

You can tell that the process is complete when the cursor reappears in the bottom of the console.

V07S4BQAT0SO0uAUAI9EKw_b8a764d5ea57479fa5e908b91672d1f1_done

  1. Load the tidyverse library with the library() function. To load the core tidyverse, type library(tidyverse) and press Enter (Windows) or Return (Mac).

You only need to install a package once, but you need to reload it every time you start a new session.

cPxI9BU4Qb28SPQVOGG9Eg_f9437acd96b9430890762d21203e2af1_Screenshot-2021-07-01-11 45 56-PM

  1. Load the lubridate package. Since this is already part of the tidyverse package, there is no need to re-install. However, the library will need to be loaded. Type library(lubridate) into the console pane and press Enter (Windows) or Return (Mac).

After you complete these steps, you can exit RStudio. Feel free to explore RStudio Cloud on your own to get more familiar with the tools and practice what you are learning in this course.

Reflection

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

In this activity, you accessed RStudio, an IDE for programming in R. In the text box below, write 2-3 sentences (40-60 words) in response to each of the following questions:

  • How does the experience of using RStudio differ from other environments like the standard R program? (If you did not install R to your device, how do the features compare?)
  • What is an advantage of using the RStudio in the cloud?

Explain: Congratulations on completing this hands-on activity! A good response would include that RStudio’s more detailed interface allows you to code with ease.

RStudio Cloud is one of the primary tools you will use in this course, so being able to access it on your own will be important as you learn and practice more R skills. Since the program is accessible through the cloud, you have the flexibility of using RStudio from any computer, regardless of OS.

Optional Hands-On Activity: Get started in RStudio Desktop

Activity overview

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

In earlier activities, you explored programming with R and may have downloaded R to your computer. You also set up cloud access to RStudio, an integrated development environment for programming in R. In this activity, you will download RStudio Desktop--the offline version of RStudio--to your computer.

By the end of this activity, you will be able to use RStudio Desktop on your computer. This will give you more flexibility while programming with R, as you will be able to access everything RStudio has to offer even if you are not connected to the internet.

Download RStudio Desktop

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4

  • Note: This is an optional activity. RStudio Cloud is the primary tool we will use for this course, but you can also use RStudio Desktop if you have R installed. Please keep in mind that Chrome OS does not support the installation of R. If you are completing this course on a Chromebook, we suggest that you skip this activity or refer to the Linux workaround linked in this activity.

RStudio allows you to create and manage projects using R more efficiently. You can find more information about RStudio Desktop on the RStudio website. It is available to download with the open source edition, so it is free to use under a public license. The free trial of RStudio Pro, which has all of the features of the open-source edition and a commercial license, is also on this website.

  1. Determine which operating system (OS) you have on your computer. Some common OS’s include MacOS (Apple), Windows OS (Microsoft), and Chrome OS (Google).
  2. If you haven’t already, install R onto your computer. You can find the links to download R for Mac, Windows, and Linux on the CRAN website. For more information, refer to a previous activity, Downloading and Installing R.
  3. Once you have installed R, go to the RStudio Desktop download page.

khkWFyMNTnaZFhcjDc52OQ_33ed3cec840d410ea9a9ff8dc5029dc7_Screenshot-2021-03-10-7 32 26-PM---Display-2

  1. Download the appropriate RStudio Desktop installer for your operating system.
  2. Once you have downloaded the installer, open it and install RStudio.
  3. After installation, open the application for the first time. You should find the RStudio console you are already familiar with--but now you can access it locally.

Install and load packages

TOqxzuNFR2eqsc7jRVdnKg_a3c6611d874f403a923e10406b4f38a9_image4

You can install and load packages in your RStudio Desktop console, just like you did for RStudio Cloud. Now, you will install and load the lubridate package in the tidyverse.

As a refresher, the tidyverse is a collection of packages in R with a common design philosophy for data manipulation, exploration, and visualization. For a lot of data analysts, the tidyverse is an essential tool.

  1. To install the core tidyverse packages, type install.packages("tidyverse") into the RStudio console pane and click Run.
  2. Load the tidyverse library with the library() function. Type library(tidyverse) into the console pane and click Run.

You only need to install a package once, but you need to reload it every time you start a new session.

  1. Load the lubridate package. Type library(lubridate) into the console pane and click Run.

After you have loaded this package into your RStudio Desktop console, exit the program. Now, you will be able to use RStudio with tidyverse whether you are connected to the internet or not.

Reflection

UWFf-U9hTzKhX_lPYX8yBw_8c2e9cd211e3479a89816c7b1816ab07_image4 In this activity, you installed RStudio to your computer and loaded the tidyverse R package. In the text box below, write 2-3 sentences (40-60 words) in response to each of the following questions:

  • What are some benefits of using RStudio Desktop instead of RStudio Cloud?
  • What are some drawbacks?

Explain: Congratulations on completing this hands-on activity! A good response would include that RStudio Desktop allows you to use RStudio locally, even if you aren’t connected to the internet.

RStudio allows you to create and manage projects using R more efficiently. If you need to access RStudio without an internet connection, RStudio Desktop is a useful tool to have. On the other hand, RStudio Cloud gives you the flexibility of accessing your account from any computer. Which version you use will depend on your device as well as your preference.

When to use RStudio

As a data analyst, you will have plenty of tools to work with in each phase of your analysis. Sometimes, you will be able to meet your objectives by working in a spreadsheet program or using SQL with a database. In this reading, you will go through some examples of when working in R and RStudio might be your better option instead.

Why RStudio?

One of your core tasks as an analyst will be converting raw data into insights that are accurate, useful, and interesting. That can be tricky to do when the raw data is complex. R and RStudio are designed to handle large data sets, which spreadsheets might not be able to handle as well. RStudio also makes it easy to reproduce your work on different datasets. When you input your code, it's simple to just load a new dataset and run your scripts again. You can also create more detailed visualizations using RStudio.

When RStudio truly shines

When the data is spread across multiple categories or groups, it can be challenging to manage your analysis, visualize trends, and build graphics. And the more groups of data that you need to work with, the harder those tasks become. That’s where RStudio comes in.

For example, imagine you are analyzing sales data for every city across an entire country. That is a lot of data from a lot of different groups–in this case, each city has its own group of data.

Here are a few ways RStudio could help in this situation:

  • Using RStudio makes it easy to take a specific analysis step and perform it for each group using basic code. In this example, you could calculate the yearly average sales data for every city.
  • RStudio also allows for flexible data visualization. You can visualize differences across the cities effectively using plotting features like facets–which you’ll learn more about later on.
  • You can also use RStudio to automatically create an output of summary stats—or even your visualized plots—for each group.

As you learn more about R and RStudio moving forward in this program, you’ll get a better understanding of when RStudio should be your data analysis tool of choice.

For more information

  • The Advantages of RStudio : This web page explains some of the reasons why RStudio is many analysts’ preferred choice for interfacing with R. You’ll learn about the advantages of using RStudio for data analysis, from ease of use to accessibility of graphics and more.
  • Data analysis and R programming : This online introduction to data analysis and R programming is a good starting point for R and RStudio users. It also includes a list of detailed explanations about the advantages of using R and RStudio. You’ll also find a helpful guide for getting set up with RStudio.

R&R...Studio!

RStudio is an integrated development environment (IDE) specifically designed for use with the R programming language. RStudio offers you a single workspace where you can use R for all phases of the data analysis process. Throughout this course, you’ll continue to learn more about RStudio and what it can do.

For now, please submit a written response of two or more paragraphs (150-200 words) describing your initial thoughts about RStudio. Reflect on the following questions:

  • How do you think RStudio can help you in your future role as a data analyst?
  • What are your favorite features of RStudio?
  • If you’re new to R and RStudio, what features do you think will be the most useful to you as a learner?

Then, visit the discussion forum to read what other learners have written, engage with two or more posts, and share your feedback.

Connecting with other analysts in the R community

R is a powerful tool in your data analysis toolkit–and it also has a powerful community of users who are excited to share, collaborate, and connect with others. This reading will give you a few places where you can start to connect, online and in-person, with other analysts in the R community.

Online communities

Online communities allow you to connect with other R users no matter where you live. This list includes forums and discussion channels where you can join the conversation. It also includes social media tags you can use on your existing social media platforms to connect with other data analysts.

  • RStudio Community: The RStudio Community forum is a great place to get help and find solutions to challenges you have with R–and maybe help someone else out, too!

  • r/RLanguage : The R language subreddit is an active online community on the social media platform Reddit, where R users go to discuss R, ask questions, and share tips.

  • rOpenSci : rOpenSci has a community forum where R users can ask questions and search for solutions. It also includes links to their Best Practices guide and support pages.

  • R4DS Online Learning Community and Slack channel: This is a community with another Slack channel where R learners and mentors can gather and connect. This is a great place to chat about using R for data science.

  • Twitter #rstats : If you use Twitter, you can connect with other R users using the hashtag #rstats; a lot of R developers and analysts are active on Twitter.

Meetups

Many organizations host both in-person and online meetups for R users; you should always practice caution and be safe whenever attending meetups in-person.

  • Local Data Analytics meetups: These meetups are a great way to meet other people who are interested in data analytics and build your network. These meetups are location-based, so you can connect with other data analysts in your area.

  • R User Groups: This list contains links to regional R communities, including subreddits and meetup groups. This is a useful resource if you are interested in finding R users in your area.

  • RLadies Meetups: These are in-person and virtual meetups specifically for R enthusiasts who identify as underrepresented or marginalized. These meetups are also location-based and can help you connect with other data analysts in your area.

R can be tricky to learn, but luckily there is a strong community of R users who are interested in working together and helping each other out. These resources are a good starting point if you want to begin connecting with the larger data analyst community, so take advantage of them!

Test your knowledge on programming with RStudio

Question 1

What type of software application is RStudio?

A. Data visualization tool

B. Source editor

C. Database

D. Integrated development environment

The correct answer is D. Integrated development environment. Explain: RStudio is a type of software application known as an integrated development environment (IDE). An IDE brings together all the tools you may want to use in a single place.

Question 2

RStudio includes which of the following panes? Select all that apply.

  • Environment pane
  • Source editor pane
  • R console pane
  • Command pane

Explain: RStudio includes an R console pane for executing commands, a source editor pane for writing code, and an environment pane for managing loaded data.

Question 3

If you write code directly in the R source editor, RStudio can save your code when you close your current session. True or False?

A. True

B. False

It is true statement. Explain: If you write code directly in the R source editor, RStudio can save your code when you close your current session.