argument

A variable that provides input to a function.

chunk

In an RMarkdown file (.Rmd), you can include a block (or “chunk”) of R code by surrounding the code as in the example below:

```{r chunk-name}

mean_age <- mean(ages) %>% round(2)

```

comment

You can annotate .R files or chunks in .Rmd files with comments by prefacing each line of the coment with one or more hash symbols (#).

# I'm demonstrating comments in this chunk
# This comment will be added to the document outline ----

Comments get added to the document outline if you put four or more dashes, equal signs, or hashes at the end. This is a great way to keep track of more complicated scripts.

concatenate

When referring to strings, concatenate means to paste them together using the function paste (adds a space between strings) or paste0 (doesn’t add anything between strings).

subject_name <- "Lisa"
paste("Hello,", subject_name)
## [1] "Hello, Lisa"

When referring to other types of variables, concatenate can mean to create a vector with those variables, usually using the c function. For example, you could concatenate the numbers 1, 3, 6, and 10 like this: c(1, 3, 6, 10). You can concatenate two vectors as well:

v1 <- 1:5
v2 <- 11:15
c(v1, v2)
##  [1]  1  2  3  4  5 11 12 13 14 15

Remember, a vector can only have one data type. So if you concatenate a string vector and a numeric vector, the numbers will get turned into their string versions. If you concatenate an integer and a double vector, the integers will be converted to doubles.

strings <- c("a", "c", "e")
integers <- c(1L, 3L, 5L)
doubles <- c(1.1, 3.3, 5.5)
c(strings, integers)
## [1] "a" "c" "e" "1" "3" "5"
c(doubles, integers)
## [1] 1.1 3.3 5.5 1.0 3.0 5.0

data type

  • integer (whole numbers like 1L, -10L, 3000L)
  • double (numbers like -0.223, 10.324, 1e4)
  • string
  • logical (TRUE or FALSE)

If you want to know what data type a variable is, use the function typeof.

typeof(10)
## [1] "double"
typeof("10")
## [1] "character"
typeof(10L)
## [1] "integer"
typeof(10 == 10)
## [1] "logical"

double

Doubles are a data type representing any type of number. Examples of doubles are 1, 1.0, -0.01, or 1e4.

function

A named section of code that can be reused. For example, sd is a function that returns the standard deviation of the vector of numbers that you provide as the input argument. Functions are set up like this: function_name(argument1 = a1, argument2 = a2). The arguments in parentheses can be named (like, x = c(1,3,5,8)) or you can skip the names if you put them in the exact same order that they’re defined in the function. You can check this by typing ?sd (or whatever function name you’re looking up) into the console and the Help pane will show you the default order under Usage.

integer

Integers are a data type representing whole numbers. In R, you specify that a number is an integer by adding an L at the end, like 1L, -36L, or 100L.

numeric

The integer and double data types are numeric.

package

Many useful functions are built into R and available by default whenever you start it up. But some of the most powerful things you can do with R require packages of functions that are written by the community. The functions in these packages aren’t available until you install the package (using install.packages("package_name") or clicking Install on the Packages pane; this only needs to be done if the package isn’t already installed). Once that package is installed (kind of like downloading an app to your phone), you can use it in any script by loading that package as a library at the top of your script (e.g., (library(ggplot2)).

You can alternatively type the package name and two colons before any function from that package to use it without loading all of its functions into the library (e.g., ggplot2::geom_histogram()). This sort of notation is also used to disambiguate function names if two packages have functions with the same names.

panes

RStudio is arranged with four window “panes”. By default, the upper left pane is the source pane, where you view and edit source code from files. The bottom left pane is usually the console pane, where you can type in commands and view output messages You can change the location of panes and what tabs are shown under Preferences > Pane Layout.

reactivity

Reactivity refers to changes in your app that occur in response to user input. Reactive features of your UI are rendered in the server.

server

The server is the part of the app that works with logic. The server is a function that processes the user’s input in the UI, and allows the app to render appropriate output. See this article for more.

shinydashboard

Shiny Dashboard or shinydashboard is a package for R that builds on Shiny for more flexible and visually appealing UIs. As with other packages, it can be installed with install.packages("shinydashboard"), and can be loaded with library(shinydashboard).

The shinydashboard Documentation is a great introduction to this package.

string

A piece of text inside of quotes. For example, "I sense the rains down in Africa" is a string. Numbers inside of quotes can be a string; "19" is a string, while 19 is not.

vector

This is a type of data structure that is basically a list of things like T/F values, numbers, or strings. It can get very complicated (see Ch 20 of R for Data Science for a thorough explanation), but at first you just need to be able to understand that the following things are examples of vectors:

# use the c() function to make a vector of strings or numbers
liit_ingredients <- c("vodka", "gin", "rum", "tequila", "triple sec", 
                      "orange juice", "coke", "sour mix")

fun_to_play_at <- c(25, 13, 3, 1)

# the colon between two integers gives you all the numbers from the first to the last integer
likert <- 1:7

The variable letters is a built-in vector with the latin letters in order. You can select part of a vector by putting the numeric location of what element you want inside of square brackets after the vector. You can even put a vector of numbers inside the square brackets to select several elements.

letters[26]
## [1] "z"
letters[1:5]
## [1] "a" "b" "c" "d" "e"
letters[fun_to_play_at]
## [1] "y" "m" "c" "a"

widget

A interactive web element, like a dropdown menu or a slider. See a great overview of widgets at the RStudio Shiny tutorial. In shiny apps, a widget is created by its function. The first argument is the name you will use in the code for referring to that widget and its value, so make sure it’s a unique, descriptive name like plot_color or group1_label. The second argument is the label, which is a string like "Plot colour" or "Label for the first group" (it can also be an empty string like "").

UI

The User Interface. This refers to the App as the user will see it (in HTML). The UI is defined as an object using (e.g.) fluidPage() or dashboardPage(). The UI is in contrast to the server object, which processes information the user inputs (e.g. via widgets) to the UI, and can reactively render the app’s UI. This means that the UI can look completely different depending on the actions of the user. See this article for more.