Initial setup

Required set up for the course on emuR

  • In order to use emuR, you must first download and install the program R. The latest version is currently 4.3.x (September 2023).
  • Also download and install the program RStudio, which is a so-called integrated development environment.

Default browser

The EMU-webApp for visualizing sound files and editing transcriptions should in theory work with most modern browsers, but you may run into unexpected problems if you use it with other browsers than Google Chrome. For this reason, we recommend that change standard browser to ensure that the EMU-webApp is opened in Chrome.

If you install Chrome, you can do this from the Settings tab as shown below:

Start up Rstudio

Start Rstudio by clicking on the Rstudio icon – it should look like this:

Create a directory on your hard drive

Create a directory on your hard drive to be used on this course. You can do this from R. What exactly to call the directory will depend on your computer – this will create a directory called ipsR on the desktop of my machine (which runs Windows):

dir.create('C:/users/rasmu/desktop/ipsR')

If I was a Mac user, I would have done it like this:

dir.create('/Users/rasmu/Desktop/ipsR')

Alternatively you can just create a directory in the usual way – e.g. by right clicking anywhere on your desktop and selecting new directory.

Create a project

In RStudio, go to File > New Project.... Choose the directory you just created. See the figure below:

You only need to create the project once. When you start up Rstudio the next time, the system should automatically open up inside this project that you created. If not, or if you closed the project, you can open it again:

You can get back to your default directory (if you were using R before then) any time by selecting close project in the above menu.

Install packages

In the RStudio console window, run the following code to install packages needed for this course. It will take a few minutes. You only need to do this once.

install.packages(c("Rcpp", "remotes", "knitr", 
                   "tidyverse", "magrittr",
                   "rmarkdown", "emuR", "gridExtra", "emmeans", 
                   "broom", "lmerTest", "pbkrtest", "MuMIn", "wrassp"))
More information: Installation of R packages

Should the above result in the error message installation of package had non-zero exit status, then it means that installation has failed. For Windows, you might then additionally have to install Rtools. For iOS you might need to install/reset the XCode command-line tools. For this purpose, open a Mac terminal window and execute the following:

xcode-select --install

If the installation of R packages still does not work, execute the following:

xcode-select --reset
The emuhelpeR package

Throughout the book there will be some tips on how to ease your work with emuR by using the functions of another package, emuhelpeR. This package is work-in-progress and the functions have not been tested thoroughly like those of emuR, and it’s not a requirement to use it. Because it’s work-in-progress, it is not (yet) available from the Comprehensive R Archive Network or CRAN, and can’t be installed with the install.packages() command. You can however install it from GitHub using the install_github() command from the devtools package.

install.packages("devtools")
devtools::install_github("rpuggaardrode/emuhelpeR")

Loading libraries

Load in the emuR library like so:

library(emuR)

Verify that everything works by entering the following commands to the console. The command create_emuRdemoData() downloads a demo database, and load_emuDB() loads in the database, in this case saving it as the object ae.

create_emuRdemoData(dir = tempdir())
ae <- load_emuDB(file.path(tempdir(), "emuR_demoData", "ae_emuDB"))
serve(ae, useViewer=F)

The third command serve(ae, useViewer=F) should produce the following image in your browser:

Have a look around and close the window to move on.

Quitting from RStudio (and R)

You shut down RStudio by either clicking Session > Quit Session in the main Rstudio toolbar or by running q() in the R console as below:

q()

You will then be asked whether you want to save the workspace image. For this course, please never save the workspace i.e. (Don't save).

Learning R

A basic knowledge in R is a prerequisite for this course. If you are unfamiliar with R then please start by working through these two sources:

There is a very large and helpful R community online that will make learning R easier for you. Here are a few useful links and commands in case you get stuck:

  • Stack Overflow: A blog where you can often find an answer to your questions about R. The easiest way is to google your question in English; a Stack Overflow member’s answer will be included in the first search results.
  • The book R for Data Science (Wickham, Çetinkaya-Rundel, and Grolemund 2023): Hadley Wickham is the chief programmer of the tidyverse. His books are very readable, well-structured, and entertaining.
  • Cheat sheets: These are PDFs that provide an overview of functions with explanations and examples in a very compact form. You will find some cheat sheets in the main RStudio toolbar via Help > Cheat Sheets. The first three are especially useful.
  • Vignettes: For some packages there are so-called vignettes available. These are mostly HTMLs or PDFs that have been written by the package authors. You can search for vignettes using the following input to the console (this example finds a vignette for dplyr, one of the libraries from tidyverse):
vignette("dplyr")
  • You can get information about a function by entering its name in the RStudio Help toolbar. You’ll then get information about the function’s arguments and often some examples. You can also get help via the console, as follows ( e.g. here for getwd()):
?getwd
help("getwd")

ggplot2 is both a well-known and popular program for creating plots. There is plenty of help available for ggplot2 from the R community. Here are some useful links for creating graphics:

R is first and foremost an environment for developed for statistical computing. If you need more information about using statistics in R, the following are recommended:

  • Winter (2019) is a recent book with excellent explanations to all major themes in inferential statistics.
  • Gries (2021) is a recent update of a classic which gives a methodical introduction to both R data structures and statistical models, starting with the very basics. It is useful for decision making about which model to use for which kind of question.
  • Sonderegger (2023) is a very recent book which introduces regression models and discusses in depth which problems you may run into when fitting them.
  • Although the R code in Baayen (2008) is a bit out of date, the explanations and examples of statistics foundations are very helpful.