class: center, middle, inverse, title-slide .title[ # Module 02: Getting Started with Packages & Data ] .subtitle[ ## Rollins COVID-19 Epidemiology Fellowship R Training: Nov 11, 2022 ] .author[ ###
Melinda Higgins
] .date[ ### Director Biostatistics & Data Core School of Nursing - Emory University ] --- # Why Learn R? * https://www.tiobe.com/tiobe-index/r/ * https://www.tiobe.com/tiobe-index/ * https://r4stats.com/articles/popularity/ ### AND Rmarkdown... * Seamless integration of DATA + CODE + DOCUMENTATION * See examples [https://rmarkdown.rstudio.com/gallery.html](https://rmarkdown.rstudio.com/gallery.html) * Many output formats [https://rmarkdown.rstudio.com/formats.html](https://rmarkdown.rstudio.com/formats.html) * Learn more at [https://rmarkdown.rstudio.com/lesson-1.html](https://rmarkdown.rstudio.com/lesson-1.html) --- # R vs Other Stats Software .pull-left[ ## R * bare bones * takes up very little memory * powerful base packages * FREE/Open Source ] .pull-right[ ## SPSS, SAS examples * Have to buy base ($$) * AND Almost always have to buy add-ons, gets expensive $$ * Have to know what you want ahead of time * Sometimes end up with more than you need ] --- # My SAS License Includes: <img src="sas_packages.png" width="70%" /> --- # My SPSS License Includes: <img src="spss_packages.png" width="50%" /> --- # R - Base R Packages .pull-left[ ```r sessionInfo() ``` ] .pull-right[ <img src="sessionInfo01.png" width="100%" /> ] .footnote[Add package(s) as you need them...] --- # To add functionality to R - install/load Packages ### FIRST INSTALL Package(s) .pull-left[ <img src="install_packages01.png" width="60%" /> ] .pull-right[ <img src="install_packages02.png" width="90%" /> ] --- # List Packages Installed on Your Computer .pull-left[ <img src="packages_list_user.png" width="100%" /> ] .pull-right[ <img src="packages_list_system.png" width="100%" /> ] --- ### SECOND - LOAD Package(s) into Current R Session .pull-left[ Before you can use the functions in the package installed on your computer, you must load it into your current "R session" - only loaded as needed... ```r # load tidyverse library(tidyverse) # run sessionInfo() again # now how many packages are "attached" # under "other attached packages" sessionInfo() ``` ] .pull-right[ <img src="sessionInfo02.png" width="100%" /> ] --- # Where to get R Packages - CRAN <iframe src="https://cran.r-project.org/" width="100%" height="400px" data-external="1"></iframe> .footnote[[https://cran.r-project.org/](https://cran.r-project.org/)] --- # Where to get R Packages - Bioconductor <iframe src="https://www.bioconductor.org/" width="100%" height="400px" data-external="1"></iframe> .footnote[[https://www.bioconductor.org/](https://www.bioconductor.org/)] --- # Where to get R Packages - Github, Local, Others... [https://github.com/search?l=R&q=packages&type=Repositories](https://github.com/search?l=R&q=packages&type=Repositories) <img src="GithubRPackages.png" width="100%" /> --- # Do Your Research * Always research your packages - like any other "tool" * has it be validated? * has it been published? * has is it been used/accepted in your research field or application? -- * Check download stats: [https://hadley.shinyapps.io/cran-downloads/](https://hadley.shinyapps.io/cran-downloads/) -- * Check CRAN: e.g. `tidyverse` [https://cran.r-project.org/web/packages/tidyverse/index.html](https://cran.r-project.org/web/packages/tidyverse/index.html): * check date last updated * how many versions * how long has it existed -- * Check Github repo if exists, check issues: * `tidyverse` [https://github.com/tidyverse/tidyverse](https://github.com/tidyverse/tidyverse) --- class: inverse, middle, left # EXERCISE 01 - Reviewing R Packages - do together ### 1. Open "module02_Rscript.R" ### 2. Read instructions for EXERCISE 01 * Go to https://hadley.shinyapps.io/cran-downloads/ * How many downloads have there been (on average) recently: * for the `ggplot2` and `palmerpenguins` packages? * remove `ggplot2` and make plot again * compare downloads for `arsenal` and `gtsummary` packages * Go to https://cran.r-project.org/ - click on packages: * how many Packages are on CRAN today? * list by name and find `ggplot2` package * when was it last updated? * go to github repo for ggplot2 - any open issues? --- # Interactive RStudio ### 1. Open RStudio ### 2. Open "module02_Rscript.R" ### 3. Go to "DATASETS" ### - step through code steps to load data ### - save "image" close and reopen project ### 4. If time - check out [OPTIONAL] SAVING and LOADING the "abalone" dataset