This page contains information which the Transforming Publishing team think will be useful to analysts using R in their work in PHS. The contents cover coding style, RStudio projects and the tidyverse. For a comprehensive collection of resources for using R in PHS please visit this site.
The R style guide for PHS analysts is available in the PHS R-Resources repo. Analysts should follow these guidelines as closely as possible as we strive to achieve code that is reproducible, shareable and efficient (our new mantra 🙏). The style guide should be seen as an evolving document, so please share any thoughts you have about how to improve it and keep an eye on it for updates.
The tidyverse style guide by Hadley Wickham should be used in conjunction with the PHS style guide. This is a comprehensive style guide covering object names, spacing, assignment (<-
not =
being another of our mantras), functions, the pipe operator %>%
and much more.
RStudio projects are a great way to keep your R work well organised, and to enable the use of version control methods such as Git. A brief introduction to projects by RStudio can be found here and a more comprehensive guide to project orientated workflows has been written by Jenny Bryan and Jim Hester. A new project which follows the recommended structure within PHS can be created using the phstemplates package. There is also a blank R Shiny app template available to download and use on the PHS GitHub account.
Tidyverse is a suite of R packages for data manipulation and visualisation. The tidyverse style of coding is recommended within the TPP team. RStudio have published a number of cheatsheets which are useful when using the tidyverse. A few videos from the tidyverse wizard (Hadley Wickham) himself:
- "dplyr" tutorial at useR 2014: https://www.youtube.com/watch?v=8SGif63VW6E
- EdinbR lecture covering "dplyr", "purrr", "tidyr" and "broom", April 2016: http://edinbr.org/edinbr/2016/05/11/may-Hadley-Update2-PostingTalk.html
- R for Data Scienceby Garrett Grolemund and Hadley Wickham
- Advanced R by Hadley Wickham
- Efficient R programming by Colin Gillespie
- R packages by Hadley Wickham
- EdinbR: The Edinburgh R Usergroup hold local meetups (usually once a month) and training for the R programming language.