Using R Locally

Setup information for using R on your local computer.

Bryan Blanc
01-18-2021

R/RStudio Setup

How to Relocate Local R Package Folder

These steps redefine the R user packages folder in R to use a “Local” folder within your R user profile, which for me is: C:/Users/EshelO/Local/R/win-library/3.4.

  1. Relocate your existing R user library folder (which for me was in C:/Users/EshelO/Document/R/win-library/3.4 (if Documents has already been migrated, this would be C:/Users/EshelO/OneDrive - Perkins and Will/Documents) to C:/Users/EshelO/Local/R/win-library (or per above)

  2. Test the change:

Run .libPaths("C:/Users/EshelO/Local/R/win-library/3.4") (modifying as necessary) - this is only for your current R session

Run .libPaths() and you should be able to validate this worked

Run a test require() and install.packages() to verify R can both read and install to the new location

require(dplyr)  
install.packages("tidycensus") 

–>

Other Setup

Installing and Configuring Git & GitHub

Git is a version control system, a tool that tracks changes to your code and shares those changes with others. Git is most useful when combined with GitHub, a website that allows you to share your code with the world, solicit improvements via pull requests and track issues. Git + GitHub is the most popular version control system for developers of R packages (thousands of R packages are hosted on GitHub) and many other types of software.

Git and GitHub are generally useful for all software development and data analysis, not just R packages.

To use Git/GitHub with R, you will need to set up a GitHub account and configure RStudio to interface with GitHub. Detailed instructions for this can be found here.

File a help ticket with IT to have Git installed.

- To get an Enterprise P+W account: - Create your own personal github account; recommend setting up using your personal e-mail - Email Joel Register your github username and ask to be added to the Nelsonteam - “Could I request to join the enterprise GitHub account? My username is XXXXX.”

Installing RTools

RTools is a collection of development tools that are essential for writing and releasing packages. The latest RTools package can be downloaded from the CRAN website. File a help ticket to have it installed. If everything goes well, you will have a new directory on your computer called C:/Rtools. More detailed information and instructions can be found here.

Script Management

Folder Conventions

Script Titleblock Snippet

In R studio go to Tools -> global options –> code –> bottom of page “edit snippets” –> scroll to bottom and paste the below in, change your name in the Author field.

snippet header
    ## ---------------------------
    ##
    ## Script name: 
    ##
    ## Purpose of script:
    ##
    ## Project Name: 
    ##
    ## Project Number: 
    ##
    ## Author: Esther Needham
    ##
    ## Date Created: `r paste(Sys.Date())`
    ##
    ## ---------------------------
    ##
    ## Notes:
    ##   
    ##
    ## ---------------------------
    ## set working directory here or make sure there is a .Rproj file
    ## ---------------------------
    options(scipen = 6, digits = 4) # view outputs in non-scientific notation
    ## ---------------------------
    ## load up the packages we will need:  (uncomment as required)
    require(tidyverse)
    require(sf)
    ## ---------------------------
    ## load up functions from other scripts into memory
    # source("functions/summarise_data.R") #example
    ## ---------------------------

ShinyApps Web Hosting

Management Dashboard

Management Account

Password

Uploading to shinyapps.io

AWS SQL Server Hosting

Google API Access