.. _r_setup_guide: Getting Started with R and RStudio =================================== Quick Start: R / RStudio Setup ------------------------------------------------- - Local Install (R/RStudio): `Local Install `_ - Scholar Access (cluster): `Scholar Access `_ RStudio Orientation ------------------------------------------------- - **Console** (executes statements), **Source/Editor** (scripts, Rmd), **Environment** (objects), **Plots/Help** (graphics, docs). - Use **Projects** to lock working directory. Prefer relative paths and **never** hardcode machine-specific directories mid-script. - Keep code modular. Consider separate chunks for import, cleaning, EDA, modeling, diagnostics, and reporting. Packages / Libraries (Course Set) ------------------------------------------------- - **ggplot2** — Grammar of Graphics. Histograms, boxplots, QQ, scatter + fit lines, ribbons for intervals. - **grid**, **gridExtra** — Plot/table layout (e.g., arrange multiple graphics on a page). - **kableExtra** — Styling for ``knitr::kable`` tables (borders, alignment). - **knitr** — Report tooling; ``kable`` produces clean tables. - **latex2exp** — ``TeX()`` for LaTeX-style math in plot labels. - **magrittr** — Pipe operator ``%>%`` to chain steps. - **stats** — Inference & models: ``aov``, ``anova``, ``lm``, ``t.test``, ``TukeyHSD``, distributions (``dnorm``, ``qnorm``, ``pt``, ``qt``), etc. - **utils** — I/O like ``read.csv``, ``write.csv``. .. tip:: Install from CRAN if needed: :: install.packages(c("ggplot2","knitr","kableExtra","latex2exp","gridExtra")) Getting Started with swirl ------------------------------------------------- If you have never coded before, the computer assignments may immediately feel overwhelming. However, R is a language that is as rewarding as it is approachable, especially for statistical work. If you're new to coding, you'll find R's logical syntax is perfect for beginners. Our tutorials are tailored to gradually build your understanding, making R less daunting. The tutorials are focused on the tools needed for the Computer Assignments. However, you may feel you need to get a little more comfortable in R before you attempt the tutorials and the Computer Assignments. An R package called **swirl** may be just what you need to get started. Setup and Use swirl ~~~~~~~~~~~~~~~~~~~~~~~~ 1. Setup R and RStudio (see links above) 2. Install swirl from the command line in R: .. code-block:: r install.packages('swirl') 3. Load swirl: .. code-block:: r library('swirl') 4. Run swirl: .. code-block:: r swirl() This will start the command line interactive tutorials of swirl. You will be instructed on exercises on the command line. **swirl Commands (available anytime during lessons):** - ``skip()`` — Skip the current question - ``play()`` — Experiment with R on your own (swirl ignores your actions) - ``nxt()`` — Return swirl's attention after using play() - ``bye()`` — Exit swirl (progress is saved) - ``main()`` — Return to swirl's main menu - ``info()`` — Display these options again I recommend working through at least a few lessons to get familiarity with coding in R. Alternative R Learning Resources ------------------------------------------------- For curious students who want to explore R beyond the course requirements: Base R ~~~~~~~~~~~~~~ - **CRAN "An Introduction to R"** (official manual): Canonical, up-to-date coverage of types, subsetting, vectorization, base graphics, and the modeling API. The authoritative source. https://cran.r-project.org/doc/manuals/r-release/R-intro.html - **Deep R Programming** (free textbook): Modern, rigorous coverage of R semantics, performance, and numerical computing. Ideal after you're comfortable with basics. https://deepr.gagolewski