RStudio Introduction Standards of programming in R Getting to Know RStudio Veronika Bendová1, Stanislav Katina1 2, Markéta Janošova1 11nstitute of Mathematics and Statistics, Masaryk University 2Honorary Research Fellow, The University of Glasgow March 5, 2018 • RStudio is an integrated development environment (IDE) for R • Keyboard Shortcuts using - Ctrl/Alt (Win, later we use Win as an example), Cmd/Option (macOS), for details see, e.g. Rstudio-cheatsheet 9 After starting RStudio create new RSkript a File -> New File -> R Script (Ctrl+Shift+N) 9 Set R Studio appearance • Tools —> Global Options —> Appearance • Restart R Session (all manually loaded packages will be unloaded) • Session -> Restart R (Ctrl+Shift+F10) • Clear Workspace (remove all loaded datasets and defined objects) • Session —> Clear Workspace 9 Clear Console (delete all commands and outputs displayed) » Ctrl + L 1 /1 Veronika Bendová, Stanislav Katina, Markéta Janošova Standards of programming in R 2/1 Veronika Bendová, Stanislav Katina, Markéta Janošova Standards of programming in R RStudio Introduction RStudio Environment © RStudio O • Q|3 <3* - H ftí =? * Go to file/function I @ - Addín: - □ X ■ R Project: (None) • R Studio environment is divided into four sections: (£) Code editor (top left) Oj Untitledl = □ Environment History Connections o Environment for creating your own code H □ Source | C\ j£ - | Q) 1 1**1 L>Sou,ce - ^ ^ U I @» Import Dataset- I 4 List - o Click on button Run or press Ctrl + Enter for running (a part of) the code (2) Workspace (top right) 0 Environment - list of loaded datasets, defined objects (variables) and defined functions 0 History - list of all commands, which were run in the past 1 1 \ Global Environment - Environment is empty 1:1 (Top Level) i R Script i (J) Console (bottom left) 0 Environment, where executed commands and their outputs are Console -/ Files Plots Packages Help Viewer > i tS, Export - O displayed 0 Plots (bottom right) • Files - provides a list of files in selected folder 0 Plots - shows a preview of plotted graphs a Packages - allows installing new packages and displays a list of installed packages, which can also be loaded and unloaded from here a Help - interactive help environment _ -.„„„. 3/1 Veronika Bendová, Stanislav Katina, Markéta Janošova Standards of programming in R 4/1 Veronika Bendová, Stanislav Katina, Markéta Janošova Standards ot programming in R RStudio Project Useful Links Note: The above mentioned sections could be rearranged and also their number could be changed from 2 to 4 (based on your preferences). (j) Create new R project j File —> New File a File —> New File j File —> New File R Script (R) R Sweave (pdf) R Markdown (HTML, Word, pdf) 9 Set the folder, where the R Script is located, as working directory j Session —> Set Working Directory —> To Source File Location (s) A good project layout » Integrity of data • Portability of the project j Easier to pick the project back up after a break 0 Directory layout (example) o Folder "Project-name" • Subfolders "R.Scripts", "Data", "Docs", "Figures", "Outputs" Standards of programming in R ■O0.O 9 RStudio project https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects (2) Designing RStudio projects https://nicercode.github.io/blog/2013-04-05-projects/ (3) Paper about designing projects http://journals.plos.org/ploscompbiol/article?id=10.1371 /journal.pcbi. 1000424 (4) A meaningful structure for RStudio project https://www.inwt-statistics.com/read-blog/a-meaningful-file-structure-for-r-projects.html 5/1 Veronika Bendová, Stanislav Katina, Markéta Janošova 6/1 Veronika Bendová, Stanislav Katina, Markéta Janošova Standards of programming in R