-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mikkel Roald-Arbøl
committed
Mar 17, 2024
1 parent
f0ff1d1
commit 2cd48ea
Showing
11 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
^renv\.lock$ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
^codecov\.yml$ | ||
^LICENSE\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2024 | ||
COPYRIGHT HOLDER: trackballr authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2024 trackballr authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# trackballr | ||
|
||
<!-- badges: start --> | ||
[![Codecov test coverage](https://codecov.io/gh/roaldarbol/trackballr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/roaldarbol/trackballr?branch=main) | ||
<!-- badges: end --> | ||
|
||
The goal of {trackballr} is to make analysis of trackball data easy- | ||
|
||
## Installation | ||
|
||
You can install the development version of trackballr from [GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("roaldarbol/trackballr") | ||
``` | ||
or from my -universe: | ||
``` | ||
install.packages("trackballr", repos = c("https://roaldarbol.r-universe.dev", "https://cran.r-project.org")) | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
``` r | ||
library(trackballr) | ||
|
||
## Read all files into list | ||
data_list <- read_trackball_data(folder_path, sensors = c("Right", "Left")) | ||
|
||
# Augment all data in list | ||
data_list <- lapply(data_list, beetle_augment) | ||
|
||
# Bind list into single data frame | ||
data_df <- bind_rows(sensor_data_temp) | ||
``` | ||
|
||
Once the data has been pre-processed, it can then easily generate useful summaries - here are some examples. | ||
```r | ||
# Compute translational summary | ||
sensor_summary <- sensor_data_df |> | ||
na.omit() |> | ||
group_by(id, date) |> | ||
filter(abs(x) > 0 | abs(y) > 0) |> # Only keep rows containing movement | ||
summarise(total_translation = sum(distance), | ||
v_translation_mean = mean(v_translation), | ||
v_translation_sd = sd(v_translation), | ||
sinuosity = sqrt(last(cum_x)^2 + last(cum_y)^2)/sum(distance) | ||
) |> | ||
mutate(trial = if_else(date <= min(date), "first", "second")) |> # Each animal has been on the trackball on two days - here we assign which day/trial | ||
slice(1:2) |> | ||
filter(total_translation > 0) |> # Filter away trials with no translation | ||
filter(n() == 2) # Keep only observations where both trials are present | ||
|
||
# Compute rotational summary | ||
# Here wa are also filtering out trials with a faulty sensor/no data for one sensor | ||
rotation_summary <- sensor_data_df |> | ||
na.omit() |> | ||
group_by(id, date) |> | ||
filter(v_rotation > 0) |> | ||
summarise(total_rotation = sum(rotation, na.rm = TRUE), | ||
v_rotation_mean = mean(v_rotation, na.rm = TRUE)) |> | ||
mutate(trial = if_else(date <= min(date), "first", "second")) |> | ||
slice(1:2) |> | ||
filter(n() == 2) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
comment: false | ||
|
||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: auto | ||
threshold: 1% | ||
informational: true | ||
patch: | ||
default: | ||
target: auto | ||
threshold: 1% | ||
informational: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is part of the standard setup for testthat. | ||
# It is recommended that you do not modify it. | ||
# | ||
# Where should you do additional test configuration? | ||
# Learn more about the roles of various files in: | ||
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview | ||
# * https://testthat.r-lib.org/articles/special-files.html | ||
|
||
library(testthat) | ||
library(trackballr) | ||
|
||
test_check("trackballr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test_that("Mode works!", { | ||
|
||
# Single outcome | ||
my_single_vector <- c(1,2,3,3,4,5) | ||
expect_equal(trackballr::mode(my_single_vector), 3) | ||
|
||
# Multiple outcomes | ||
my_multi_vector <- c(1,2,3,3,4,5,5) | ||
expect_equal(trackballr::mode(my_multi_vector), 3) | ||
|
||
# Removes NA | ||
my_na_vector <- c(1,2,3,3,NA,5) | ||
expect_equal(trackballr::mode(my_na_vector), 3) | ||
}) |