2 Loading R Packages

Three R packages have been developed for Motus users:

  1. motus: provides functions to output summary plots, and to transform (add sun rise/sun set times) and analyze Motus data.

  2. motusClient: provides functions to download and update detections data and tag and receiver deployment metadata from the Motus server.

  3. motusData: provides sample datasets used in some of the chapters of this book.

Motus users can install the latest stable versions of the R packages using the following code. As with all R packages, you only need to install the packages once; after installation, you need to load each package (using library() or require()) each time you open a new R session.

Please note that some functionalities of the devtools package may require updated versions of R and RStudio. To avoid errors, please ensure you are using the most recent releases of R and RStudio, and update your R packages using update.pacakges() in the R console.

To update your existing packages:


Begin by installing the required packages, if not already installed. Note that the motusClient package, which is required to access detection data from the Motus server, is a dependency of the broader motus package, i.e., you should only need to run the code to install the motus package, and the motusClient package will be automatically loaded. The code to install the motusClient R package independently is included below, but you should not need to run it.


# install motus for data download, data
# manipulation, visualization and analysis

# install motusClient for data download

# install motusData package which contains sample
# datasets, e.g., vanishBearing used in Chapter 7


If you need to update an existing motus or motusClient package, you need to specify ‘force = TRUE’:

# force a re-installation of motus package in case
# of required updates
install_github("MotusWTS/motus", force = TRUE)

# force a re-installation of motusClient package in
# case of required updates
install_github("MotusWTS/motusClient", force = TRUE)


Throughout the book, we use tidyverse, which is a collection of R packages for data science, including tidyr, dplyr, ggplot2, and lubridate for managing and manipulating dates. More information on tidyverse can be found at https://www.tidyverse.org/, or by browsing (or better still, thoroughly reading) ‘R for Data Science’ by Garrett Grolemund and Hadley Wickham (http://r4ds.had.co.nz/). For mapping we also use the rworldmap, and ggmap packages. These can be installed from CRAN, as follows:






We also install but do not load the plyr package; we use it directly for the handy round_any function, but loading it can cause problems with the dplyr functions:


2.1 Internal data processing

As an animal moves within the detection range of a Motus station, radio transmissions, or ‘bursts’, are detected by antenna(s) and recorded by a receiver. These raw detection data are either uploaded to the Motus database instantaneously via internet connection, or downloaded from the receiver and uploaded to Motus manually. Behind the scenes, various functions read and process the raw detections data to produce the tag detections file that users access using the R package (see Chapter 3). While most users will not need to call on the internal data processing functions, a complete list of functions within the Motus server R package can be found on GitHub (https://github.com/jbrzusto/motusServer). The code behind each function can be viewed on GitHub, or by typing the following in the R console after loading the R package, replacing ‘function.name’ with the name of the R function of interest:


In the next chapter we will examine and load some data.