Skip to content

Instantly share code, notes, and snippets.

@Lextuga007
Last active April 14, 2021 17:55
Show Gist options
  • Select an option

  • Save Lextuga007/2a3bf56e6fbd56c2d24df8ef71caa5e1 to your computer and use it in GitHub Desktop.

Select an option

Save Lextuga007/2a3bf56e6fbd56c2d24df8ef71caa5e1 to your computer and use it in GitHub Desktop.
Checklist for NHS-R Introduction to R and R Studio

Trainer checks

  • Ctrl+Shift+F10 or Session/Restart R as doesn't automatically reset so all packages will be loaded

Reset R Studio Cloud Global Options

  • Save workspace to .RData on exit = Ask
  • Tick Restore .RData into workspace at startup
  • Appearance RStudio theme = Modern
  • Ambience = Clouds
  • Editor font size = 10

Training

Powerpoint 1 - introduction

Stackoverflow

  • dplyr was plyr
  • data.table
  • look for newer posts, might have fewer votes. Deprecated verbs (pivot_longer/pivot_wider was gather/spread)
  • nhsrcommunity.slack.com, R-Ladies, @miR_community

Editor

  • Do not have to highlight whole chunks to run (unlike in SQL), anywhere in chunk for Ctrl + Enter
  • Back tick ``, '', "" interchangeable and automatically does closing.
  • Highlight word and select quotes, automatic for beginning and end.

Packages

Powerpoint 2 - Projects

  • Useful for finding files when network paths are set up like: \NHS- X-XX01\Users2\X\Name
  • Avoid setwd()

Powerpoint 4 - ggplot2

  • Tibbles are a re-imagining of data frames https://blog.rstudio.com/2016/03/24/tibble-1-0-0/. Show first 10 rows in console with information on the table whereas dataframes show entirety.
  • + must come at the end of the line, not at the beginning of the next

Powerpoint 5 - dplyr

  • group_by() does not reduce a number of similar rows to 1 like SQL. Two ways to reproduce this:

group_by_all() %<% slice(1) - takes first, if you do slice(2) takes 2nd not 1 and 2

or unique()

Extension

  • summarise(uniqueNumber = n_distinct(id))

Powerpoint 7 - joins

  • When joining on column names that don't match, the order of the given names is important. c("country" = "Place") will work but c("Place", "country") will not

Powerpoint 8 - R Markdown

  • Also very useful as a proof of concept before building a Shiny app
  • Using source("example.R") is useful within R Markdown reports to split out further data wrangling from the report

Shortcuts

  • Section scripts Ctrl+Shift+R. See listed either at the bottom of the console, bottom left just above the tabs for Console/Terminal/Jobs or button next to Source top right of console.
  • R Markdown chunks are Ctrl+Alt+i (works in cloud)
  • Ctrl+Shift+1 makes the Console the prominant screen
  • Further shortcuts and set own Tools/Keyboard Shortcuts Help or Modify Keyboard Shortcuts...

Check

  • Everyone is ok for emails to be shared for certificates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment