## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4)

## ----setup--------------------------------------------------------------------
library("replayr")

## ----read---------------------------------------------------------------------
path <- system.file("extdata", "sample.fm2", package = "replayr")
movie <- read_movie(path)
movie

## ----summary------------------------------------------------------------------
summary(movie)

## ----player-------------------------------------------------------------------
input <- player(movie, 1)
dim(input)
head(input[rowSums(input) > 0, ], 3)

## ----press-rate---------------------------------------------------------------
shares <- press_counts(movie, 1) / n_observations(movie)
barplot(shares, las = 2, ylab = "share of observations held",
  main = "Player 1")

## ----layout-------------------------------------------------------------------
button_layout(movie)

## ----aliases------------------------------------------------------------------
gun <- system.file("extdata", "paper", "light-gun.bk2", package = "replayr")
button_layout(read_movie(gun))[, c("id", "key", "name")]
button_layout(read_movie(gun, aliases = FALSE))[, c("id", "key", "name")]

## ----info---------------------------------------------------------------------
observation_unit(movie)
recording_info(movie)
range(observation_time(movie))

## ----mouse--------------------------------------------------------------------
mouse <- read_movie(system.file("extdata", "paper", "mouse-drag.bk2",
  package = "replayr"))
channel_layout(mouse)
held <- player(mouse)[, "a"]
head(analog_channels(mouse)[held, ], 3)

## ----sticks-------------------------------------------------------------------
dtm <- system.file("extdata", "sample.dtm", package = "replayr")
gc <- read_movie(dtm, analog = c(left = "angle+magnitude", right = "cardinal8"))
head(stick_channels(gc), 3)
grep("^right_", colnames(player(gc)), value = TRUE)

## ----polls--------------------------------------------------------------------
polls_path <- system.file("extdata", "paper", "unassigned.dtm",
  package = "replayr")
head(polls(read_movie(polls_path)), 3)

## ----formats------------------------------------------------------------------
head(supported_formats(details = TRUE))

