Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Although I have been using RStudio for several years, I only recently discovered RStudio addins. Since then, I am using these addins almost every time I use RStudio.

What are RStudio addins? RStudio addins are extensions which provide a simple mechanism for executing advanced R functions from within RStudio. In simpler words, when executing an addin (by clicking a button in the Addins menu), the corresponding code is executed without you having to write the code. If it is still not clear, remember that for importing a dataset in RStudio, you have two options:

• import it by writing the code (thanks to the read.csv() function for instance)
• or you can import it by clicking on the “Import Dataset” button in the Environment pane, set the importing settings, then click on “Import”

A RStudio addin is exactly like the Import Dataset button but for other common functionalities. So you could write code as you can import a dataset by writing code, but thanks to RStudio addins you can execute code without actually writing the necessary code. By using the RStudio addins, RStudio will run the required code for you. RStudio addins can be as simple as a function that inserts a commonly used snippet of code, and as complex as a Shiny application that accepts input from the user to draw a plot. RStudio addins have the advantage that they allow you to execute complex and advanced code much more easily than if you would have to write it yourself.

I believe addins are worth trying for all R users. Beginners will have the possibility to use functions that they would not have used otherwise because the code is too complex, whereas advanced users may find them useful to speed up the writing of their code in some circumstances. For other tips in R, see the article “Tips and tricks in RStudio and R Markdown”.

# Installation

RStudio Addins are distributed as R packages. So before being able to use them, you need to install them. You can install an addin exactly the same way you install a package: install.packages("name_of_addin"). Once you have installed the R package that contains the addin, it will immediately become available within RStudio, via the Addins menu located at the top.

If you are still not convinced, see below a list of the addins I find most useful together with concrete examples in the following sections.

• Esquisse
• Questionr
• Remedy
• Styler
• Snakecaser
• Blogdown

Note that this list is not exhaustive and you are likely to find others useful too depending on what type of analyses you do on RStudio. Feel free to comment at the end of the article to let me know (and other readers) addins you found worth using.

## Esquisse

{esquisse} is an addin developed by a French company called dreamRs. Here is how they define it:

This addin allows you to interactively explore your data by visualizing it with the ggplot2 package. It allows you to draw bar plots, curves, scatter plots, histograms, boxplot and sf objects, then export the graph or retrieve the code to reproduce the graph.

With this addin you can easily create beautiful graphs from the {ggplot2} package and the best part according to me is that you can retrieve the code to reproduce the graph. Compared to the default {graphics} package, it is true that graphs from the {ggplot2} package look usually better but the code is also longer and more complex. With this addin, you can draw graphs from the {ggplot2} package by dragging and dropping variables of interest in an user-friendly and interactive window, and then use the generated code in your script.

For the sake of illustration, let’s say wee want to create a scatter plot of the variables Sepal.Length and Petal.Length of the dataset iris and color the points by the variable Species. For this, follow these steps:

1. load the dataset and rename it:1
dat <- iris
1. install the package {esquisse}. This must be done only once
install.packages("esquisse")
1. Select the dataset you want to work on (in this case dat) and click on “Validate imported data” after checking that the number of observations and variables are correct (green box):
1. Drag and drop the variables of interest in the corresponding areas. In this case, we would like to draw a scatter plot of the variables Sepal.Length and Petal.Length and color points based on the variable Species:
1. Click on “ Export & code” at the bottom right of the window. You can either copy the code and paste it where you want to place it in your script, or you can click on “Insert code in script” to place the code where your cursor is located in your script:

If you chose the second option, the code should appear where your cursor was located. Many different options and customizations are possible (e.g., axis labels, colors, legend position, theme, data filtering, etc.). For this, use the buttons located at the bottom of the window (“Labels & title”, “Plot options” and “Data”). You can see the changes instantly in the window, and when the plot corresponds to your needs, export the code into your script. I will not go into more details regarding the different types of plots and the customizations, but make sure to try other types of plots by moving variables and customize it to see what is possible.

## Questionr

The {questionr} addin is useful for survey analysis and when dealing with factor variables. With this addin, you can easily reorder and recode factor variables. The addin also allows to easily transform a numeric variable into factors (i.e., categorize a continuous variable) thanks to the cut() function. Like any other addin, after having installed the {questionr} package, you should see it appearing in the addins menu at the top. From the addins dropdown menu, choose whether you want to reorder or recode your factor variable, or categorize your numeric variable.

### Recoding factors

Instead of writing the recode() function from the {dplyr} package, we can use the {questionr} addin.

For this example, let’s say we want to recode the Species variable to shorten the length of the factors, and then store this new variable as Species_rec:

### Reordering factors

Similar to recoding, we can reorder factors thanks to the {questionr} addin. Let’s say we want to reorder the 3 factors of the Species variable such that the order is versicolor then virginica and finally setosa. This can be done as follows:

### Categorize a numeric variable

The {questionr} addin also allows to transform a numeric variable into a categorical variable. This is often done for the age, when age is transformed into age groups for instance. For this example, let’s say we want to create 3 categories of the variable Sepal.Length:

(Try by yourself the other cutting methods and see the results directly in the window.)

## Remedy

If you often write in R Markdown, the {remedy} addins will greatly facilitate your work. The addins allows you to add bold, creating lists, urls, italics, title (H1 to H6), footnote, etc. in an efficient way. I reckon that some of these tasks can be done faster by using the code directly rather than by going through the addins menu and then selecting the transformations you want. However, I personnaly cannot remember the code for all transformations, and it is quicker to apply it through the menu than by searching for the answer on Google or on your Markdown cheat sheet.

## Styler

The {styler} addin allows to reformat your code in a more readable format by running styler::tidyverse_style(). It works both for R scripts and R Markdown documents. You can either reformat the selected code, the active file or the active package. I find this addin particularily useful before sharing or publishing my code, so that it respects the most common styling guidelines for code.

For instance, a piece of code like this:

1+1
#this is a comment
for(i in 1:10){if(!i%%2){next}
print(i)
}

becomes much more neat and readable:

1 + 1
# this is a comment
for (i in 1:10) {
if (!i %% 2) {
next
}
print(i)
}

## Snakecaser

The {snakecaser} addins converts a character string to the snake case styling. Snake case styling is the practice of writing character strings of several words separated by space into character strings with words separated with an underscore (_). Moreover, it replaces capital letters with lowercases. For instance, the following string:

This is the Test 1

will be transformed to:

this_is_the_test_1

The snake case styling is particulary useful (and even recommended by many R users) for variables, functions and file names, etc.

## Blogdown

I put this addin at the end of the list because it will be of interest for only a limited number of RStudio users: people maintaining a blog written in R (like this blog).

The most useful functionalities in this addin are the following:

• New post: create a new post with blogdown::new_post(). It can be used to create new pages as well, not only posts
• Insert image: insert an external image into a blog post
• Update metadata: update the title, author, date, categories and tags of the current blog post
• Serve site: run blogdown::serve_site() to live preview your website locally

Thanks for reading. I hope that you will find these addins useful for your future R-related projects. See other tips and tricks in RStudio and R Markdown. As always, if you find a mistake/bug or if you have any questions do not hesitate to let me know in the comment section below, raise an issue on GitHub or contact me. Get updates every time a new article is published by subscribing to this blog.

1. You actually do not need to rename it. However, I often rename the datasets I work on with the same generic name dat so when I reuse codes from a previous project for a new project, I do not have to change the name of the dataset in the code.