Recommended Workflow and Examples

Package spAddins

Vilmantas Gegzna

2016-06-07

This vignettes describes a recommended workflow how functions of spAddins package should be used and gives several examples.

The workflow

Four main steps of recommended workflow can be defined. Step 1 and Step 2 should be repeated only once. Steps 3 and 4 can be repeated as many times as needed.

Step 1: Install the package

Package spAddins can be installed from CRAN:

install.packages("spAddins")

It can be also installed as a development version from GitHub:

install.packages("devtools")
devtools::install_github("GegznaV/spAddins")

Step 2: Set keyboard shortcuts

To learn how to add user defined RStudio keyboard shortcuts, visit these links: Customizing Keyboard Shortcuts and Keyboard Shorcuts.

Step 3: Place a cursor / Select text

For addins which insert text, in either R editor or in R console place a cursor at a position at which the text should be inserted.

For addins which replace text, either in R editor or in R console select a piece of text in which certain symbols should be replaced.

Step 4: Use the keyboard shortcuts

Use your keyboard shortcut to call a desired addin to insert or to replace the text.

Examples

Insert %>%

When package spAddins is already installed let’s set shortcut Ctrl + Alt + . to call function insertPipeline_Addin() which inserts forward-pipe operator %>% operator at cursor’s position. This operator is in package magrittr thus the package should be loaded first.

library(magrittr)

To learn more about the %>% operator type:

?`%>%`

Next, place your cursor at a position, where the operator should be inserted. Let’s say, between the name of a data set (iris) and the name of a function (head()):

iris  head()

Push the shortcut combination Ctrl + Alt + . and as a result the operator is inserted:

iris %>% head()

Replace \ with /

In the following example conciser having a string "c:\data\".
Again let’s define a new shortcut combination, say Ctrl + Alt + Shift + /, which calls an addin. This time addin function we need is Back2ForwardSlash(). This function replaces backslash (\) with forward slash /. Before the replacement appropriate piece of string must be selected. Thus let’s select all string and push Ctrl + Alt + Shift + /. As a result the string is converted into "c:/data/".