Show R code
install.packages("tinytex")
tinytex::install_tinytex()
There are an overwhelming number of great resources for learning R; here are some recommendations:
There are several dedicated UC Davis courses on R programming:
DataLab maintains another list of courses: https://datalab.ucdavis.edu/courses/
DataLab also provides short-form workshops on R programming and data science: https://datalab.ucdavis.edu/workshops/
Demographics tables are important first steps in many data analyses and papers.
The gtsummary
package is flexible and can probably provide whatever table options you’re looking for, and if not, the developers are usually very welcoming of feature requests.
If gtsummary
is really not doing what you want, other packages I’ve used for demographics tables include:
data.frame
s and tibble
stibble
stidyverse
The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
These packages are being actively developed by Hadley Wickham and his colleagues at posit1.
Details:
See Wickham, Çetinkaya-Rundel, and Grolemund (2023) for details.
There are currently (2024) two commonly-used pipe operators in R:
%>%
: the “magrittr
pipe”, from the magrittr
package (Bache and Wickham (2022); re-exported by dplyr
and others) .
|>
: the “native pipe”, from base R (\(\geq\) 4.1.0)
Wickham, Çetinkaya-Rundel, and Grolemund (2023) recommends the native pipe:
For simple cases, |> and %>% behave identically. So why do we recommend the base pipe? Firstly, because it’s part of base R, it’s always available for you to use, even when you’re not using the tidyverse. Secondly, |> is quite a bit simpler than %>%: in the time between the invention of %>% in 2014 and the inclusion of |> in R 4.1.0 in 2021, we gained a better understanding of the pipe. This allowed the base implementation to jettison infrequently used and less important features.
ggplot2
use piping?Here’s tidyverse
creator Hadley Wickham’s answer (from 2018):
I think it’s worth unpacking this question into a few smaller pieces:
- Should ggplot2 use the pipe? IMO, yes.
- Could ggplot2 support both the pipe and plus? No
- Would it be worth it to create a ggplot3 that uses the pipe? No.
Quarto is a system for writing documents with embedded R code and/or results:
To compile Quarto documents to pdf, run these commands first:
install.packages("tinytex")
tinytex::install_tinytex()
See Knuth (1984) for additional discussion of literate programming.
One of quarto’s excellent features is the ability to convert the same source file into multiple output formats; in particular, I am using the same set of source files to generate an html website, a pdf document, and a set of revealjs slide decks.
I use ::: notes
divs to mark text chunks to omit from the revealjs format but include in the website and pdf format.
This book espouses our philosophy of package development: anything that can be automated, should be automated. Do as little as possible by hand. Do as much as possible with functions. The goal is to spend your time thinking about what you want your package to do rather than thinking about the minutiae of package structure.
https://r-pkgs.org/introduction.html#:~:text=This%20book%20espouses,of%20package%20structure.
Read this ASAP: https://r-pkgs.org/whole-game.html
Use the rest of Wickham and Bryan (2023) as a reference
94% of respondents to a 2022 Stack Overflow survey reported using git for version control.
Over time, explore all the tabs and menus; there are a lot of great quality-of-life features.
History
tab to view past commands; you can rerun them or copy them into a source code file in one click! (up-arrow in the Console also enables this process, but less easily).Many modern R packages are developed on Github, and welcome bug reports and pull requests (suggested edits to source code) through the Github interface.
To contribute to “base R” (the core systems), see https://contributor.r-project.org/