Upgrade to Pro — share decks privately, control downloads, hide ads and more …

coRps R Building Blocks Series - 1 - Motivation

Aaron
January 31, 2022

coRps R Building Blocks Series - 1 - Motivation

Part 1 of the coRps R Building Blocks Series (RBBS)

https://usaid-oha-si.github.io//learn/categories/#rbbs

Aaron

January 31, 2022
Tweet

More Decks by Aaron

Other Decks in Programming

Transcript

  1. Learning Objectives • Benefits of learning to code • Series

    roadmap • How we are currently leveraging R • Where to access resources
  2. Why learn to code? • Reproducibility • Collaboration • Automate

    routine tasks • Problem solving • Help future you • Career flexibility
  3. R Building Blocks Topics 1. Motivation 2. Data Visualization 3.

    Workflow 4. Tidy data 5. Tidyverse & Base R 6. Import 7. Transformation 8. Relational data 9. Strings and Dates 10. Functions and Iteration 11. Mapping
  4. What you will need • R + RStudio* + Rtools

    OR RStudio Cloud • GitHub Account • GitHub Desktop* • Availability every other Monday 1-2:30 See the Troubleshooting section at the end for more details * require M/CIO installation
  5. Help and Feedback Loop Take advantage of GitHub Issues to

    suggest topic areas (enhancement), general questions (question), or some help on an issue youʼre facing (help wanted).
  6. Accessing our R Building Block Series We will make all

    of our content available in a variety of source. First, you will find the raw scripts/data/etc in our GitHub repository, USAID-OHA-SI/coRps. We will also post the walk through files on our SI Blog page. And finally, we will record each session and make those recordings available on Google Drive.
  7. USAID-OHA-SI Organization on GitHub All of our code lives in

    a public space and is completely searchable
  8. Installing R To install R, an open-source statistics package, you

    can do this on your USAID GFE, by going to Start > Microsoft Endpoint manager > Software Center. Once there, you can select the Application called “R for Windows” and click “Install”. If working on a personal machine, you can install R from CRAN. Select “Download R for Windows” and then “base” and follow the instructions for installing that pop up when you launch the .exe file from your downloads.
  9. Installing RStudio RStudio used to be available in Software Center

    as well, but M/CIO removed it in the fall of 2021. To install RStudio on your GFE, you should submit a M/CIO Help Desk ticket and they will install it for you in person. If working on a personal machine, you can install RStudio from this site. Select “Download” for the free version and follow the instructions for installing that pop up when you launch the .exe file from your downloads
  10. Setting up RStudio Cloud An alternative to installing RStudio is

    to use their free, online version. To do so, you can access RStudio Cloud here. You can set this up with your email (work or personal) or link this with your GitHub account (see the following slide for details on GitHub). This is a great option if youʼre getting started. It is free so the catch is there are a limited number of processing hours (25) you can use it for in a month.
  11. Setting up GitHub Account GitHub is a version control system

    that is free and used to host code. All of our code are stored there (just not the data) under our organization, USAID-OHA-SI. You can use your work or personal email to setup an account. When you have done so, you can send us an email to get added to the organization. We will spend a session on how to use GitHub.
  12. Setting Rtools Some packages require some additional “building” and need

    something called RTools installed. You can set this up yourself by following the steps laid out here. # Download R tools from here (https://cran.r-project.org/bin/windows/Rtools/rtools40.html) Install in your Documents folder (you have to override default). Modify the code chunk below replacing USER_NAME with your local username, then run the code chunk below from within an R-studio session. # Find path for RTools Sys.setenv(PATH = paste("C:\\Users\\USER_NAME\\Documents\\Rtools\\bin", Sys.getenv("PATH"), sep = ";")) Sys.setenv(BINPREF = "C:\\Users\\USER_NAME\\Documents\\Rtools\\mingw_$(WIN)/bin/") options(buildtools.check = NULL) # Check install.packages("pkgbuild") # pkgbuild is not available (for R version 3.5.0) install.packages("devtools") # make sure you have the latest version from CRAN library(devtools) # load package devtools::install_github("r-lib/pkgbuild") # install updated version of pkgbuild from GitHub library(pkgbuild) # load package find_rtools()
  13. Installing a packages on CRAN With proprietary programs like Excel,

    Tableau, or Stata, all of your functions are built into the software. With open-source packages on the other hand, we need to load different libraries or packages that are written by other organization or individuals users. To install a package from CRAN, we use the command install.packages(). Copy and paste the code chunk into your console in R to install all the required packages. We will discuss what packages/libraries and functions are in our next session. install.packages(“tidyverse”) install.packages(“gt”) install.packages(“scales”) install.packages(“patchwork”) install.packages(“remotes”)
  14. Installing a packages on GitHub We also need to install

    packages from other locations, like GitHub, and will use a slightly different command, remotes::install_github(). You will need to enter the following command into your console. remotes::install_github(“USAID-OHA-SI/gophr”) remotes::install_github(“USAID-OHA-SI/glitr”) remotes::install_github(“USAID-OHA-SI/glamr”) remotes::install_github(“USAID-OHA-SI/gisr”)
  15. Accessing our Slack Channel We have have a #r_users Slack

    channel where people can ask questions or share useful R content. If you are interesting in joining, you can use this link to join our #r_user channel, using your work or personal email.
  16. Accessing our R Building Block Series We will make all

    of our content available in a variety of source. First, you will find the raw scripts/data/etc in our GitHub repository, USAID-OHA-SI/coRps. We will also post the walk through files on our SI Blog page. And finally, we will record each session and make those recordings available on Google Drive.