--- title: "Addins" author: - Josh DeClercq - Department of Biostatistics - Vanderbilt University Medical Center date: "`r Sys.Date()`" output: bookdown::html_document2: df_print: paged toc: true toc_depth: 3 toc_float: true number_sections: true number_tables: true pdf_document: default header-includes: - \usepackage{setspace} - \usepackage{relsize} --- # Addins https://rstudio.github.io/rstudioaddins/#overview RStudio addins are extensions which provide a simple mechanism for executing advanced R functions from within RStudio. ## colourpicker https://cran.rstudio.com/web/packages/colourpicker/vignettes/colourpicker.html - Write ggplot code as usual - rather than specify colors in the `scale_XXX_manual` settings, include the variable `CPCOLS` - `CPCOLS` allows the addin to access the colors in the figure - run the "Plot Colour Helper" addin to edit colors interactively - If you just need to select a color, the addin "Colour Picker" provides menu options ```{r} require(colourpicker) CPCOLS <- c("#DB3EE0A8", "#556B2F", "#e31a1c") ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_point(aes(col = Species)) + scale_colour_manual(values = CPCOLS) ``` ## ggThemeAssist https://github.com/calligross/ggthemeassist - Allows for extensive interactive editing of ggplot appearance - Can make appealing, publication-worthy graphics ```{r} install.packages("ggThemeAssist") require(ggThemeAssist) ggplot(mtcars, aes(x = hp, y = mpg, colour = factor(cyl)) )+ geom_point()+ scale_colour_manual(values = CPCOLS) + theme(axis.line = element_line(colour = "blue2", linetype = "longdash"), axis.ticks = element_line(colour = "hotpink", size = 3.1, linetype = "twodash"), panel.grid.major = element_line(linetype = "dashed"), panel.grid.minor = element_line(colour = "gray96", linetype = "dotdash"), axis.title = element_text(family = "serif"), axis.text.x = element_text(family = "mono", size = 13, vjust = 0.75, angle = 45), axis.text.y = element_text(family = "mono"), plot.title = element_text(family = "serif", size = 21, hjust = 0.5, vjust = 2), legend.text = element_text(family = "serif"), legend.title = element_text(family = "serif", colour = "brown3"), panel.background = element_rect(fill = "papayawhip", linetype = "dashed"), plot.background = element_rect(colour = "azure", size = 1.9, linetype = "dotted"), legend.key = element_rect(fill = "chartreuse4", linetype = "dotted"), legend.position = c(0.75, 0.8378)) +labs(title = "This is the title", x = "Horsey power", y = "gogo", colour = "Cylinders") ``` - Run plot, then select the "ggplot Theme Assist" addin - Select the figure options as you desire ```{r} ggplot(mtcars, aes(x = hp, y = mpg, colour = factor(cyl)) )+ geom_point()+ scale_colour_manual(values = CPCOLS) + theme(axis.ticks = element_line(colour = "lavenderblush", linetype = "dotted"), panel.grid.major = element_line(linetype = "dotdash"), panel.grid.minor = element_line(linetype = "longdash"), axis.text = element_text(hjust = 0, angle = 40), panel.background = element_rect(fill = "lightgray"), plot.background = element_rect(fill = "darkgoldenrod1")) +labs(colour = "cylinder", caption = "This is the caption") ``` ## Styler https://github.com/r-lib/styler - provides non-invasive pretty-printing of R source code while adhering to the tidyverse formatting rules - styler can be customized to format code according to other style guides too ```{r} mtcars %>% tibble::rownames_to_column() %>% separate_rows(., rowname, sep = " ") %>% group_by(mpg, wt) %>% summarise(across(everything(), first)) %>% select(car = rowname, am, mpg) %>% ungroup() %>% mutate(mpg.am = mpg * am) %>% select(1, mpg.am) %>% filter(mpg.am > 10) %>% group_by(car) %>% summarise(mpg.x = sum(mpg.am)) %>% pivot_wider(., names_from = car, values_from = mpg.x) ``` ## ViewPipeSteps https://github.com/daranzolin/ViewPipeSteps - Having trouble making sense of a lengthy pipe chain? This addin allows you to see each step along the way ```{r} require(ViewPipeSteps) mtcars %>% tibble::rownames_to_column() %>% separate_rows(., rowname, sep = " ") %>% group_by(mpg, wt) %>% summarise(across(everything(), first)) %>% select(car = rowname, am, mpg) %>% ungroup() %>% mutate(mpg.am = mpg * am) %>% select(1, mpg.am) %>% filter(mpg.am > 10) %>% group_by(car) %>% summarise(mpg.x = sum(mpg.am)) %>% pivot_wider(., names_from = car, values_from = mpg.x) ``` ## RegExplain https://www.garrickadenbuie.com/project/regexplain/ - RegExplain is an RStudio addin slash utility belt for regular expressions. - Interactively build your regexp - check the output of common string matching functions - consult the interactive help pages - use the included resources to learn regular expressions ```{r} text <- "The quick brown fox jumps over the lazy dog" pattern <- "[aeiou]" # perl=TRUE replacement <- "X" pattern <- "(The)" # perl=TRUE replacement <- "X" gsub(pattern, replacement, text) ``` ## List of addins https://github.com/daattali/addinslist#readme ## Very useful blog post https://statsandr.com/blog/rstudio-addins-or-how-to-make-your-coding-life-easier/ # Open discussion - Any volunteers to present - Recommendations for presenters - Topics of interest - What not to do, common pitfalls or aggravating errors - Partial presentations: can combine a few presenters into one meeting