Skip to content

Commit

Permalink
Merge pull request #67 from roaldarbol/animalta_patch
Browse files Browse the repository at this point in the history
Update animalta detailed parameter
  • Loading branch information
roaldarbol authored Nov 13, 2024
2 parents bd30cde + bc7dbb0 commit f87c008
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: animovement
Type: Package
Title: An R toolbox for analysing animal movement across space and time
Version: 0.4.0
Version: 0.4.1
Authors@R:
person(
"Mikkel",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# animovement 0.4.1

Changed parameter in `read_animalta()`.

# animovement 0.4.0

Added readers for AnimalTA (`read_animalta`) and idtracker.ai (`read_idtracker`).
Expand Down
18 changes: 9 additions & 9 deletions R/read_animalta.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#' Read AnimalTA data
#'
#' @description
#' `r lifecycle::badge('experimental')`
#' @description `r lifecycle::badge('experimental')`
#'
#' @param path An AnimalTA data frame
#' @param with_roi Were one or more ROIs used?
#' @param detailed Animal export either raw (default) or detailed data files. We
#' only have limited support for detailed data.
#'
#' @import dplyr
#' @import vroom
#' @importFrom janitor clean_names
#'
#' @return a movement dataframe
#' @export
read_animalta <- function(path, with_roi = FALSE) {
read_animalta <- function(path, detailed = FALSE) {
# Inspect headers
if (with_roi == FALSE){
if (detailed == TRUE){
validate_files(
path,
expected_suffix = "csv",
expected_headers = c("X", "Y", "Time")
)
data <- read_animalta_no_roi(path)
data <- read_animalta_detailed(path)
} else {
validate_files(
path,
expected_suffix = "csv",
expected_headers = c("Time", "X_Arena0_Ind0", "Y_Arena0_Ind0")
)
data <- read_animalta_with_roi(path)
data <- read_animalta_raw(path)
}
data <- data |>
dplyr::mutate(keypoint = factor("centroid")) |>
Expand All @@ -37,7 +37,7 @@ read_animalta <- function(path, with_roi = FALSE) {

#' @inheritParams read_animalta
#' @keywords internal
read_animalta_no_roi <- function(path){
read_animalta_detailed <- function(path){
data <- vroom::vroom(
path,
delim = ";",
Expand All @@ -57,7 +57,7 @@ read_animalta_no_roi <- function(path){
#' @inheritParams read_animalta
#' @import tidyr
#' @keywords internal
read_animalta_with_roi <- function(path){
read_animalta_raw <- function(path){
data <- vroom::vroom(
path,
delim = ";",
Expand Down
5 changes: 3 additions & 2 deletions man/read_animalta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions tests/testthat/test-read_animalta.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# Test arguments
library(here)
here::i_am("tests/testthat/test-read_animalta.R")
path_roi <- here("tests", "data", "animalta", "single_individual_multi_arena.csv")
path_no_roi <- here("tests", "data", "animalta", "variable_individuals_single_arena.csv")
path_raw <- here("tests", "data", "animalta", "single_individual_multi_arena.csv")
path_detailed <- here("tests", "data", "animalta", "variable_individuals_single_arena.csv")

# File headers
test_that("File headers", {
expect_no_error(
ensure_file_has_headers(path_roi)
ensure_file_has_headers(path_raw)
)
expect_no_error(
ensure_file_has_headers(path_no_roi)
ensure_file_has_headers(path_detailed)
)
})


# Read file
test_that("Read file", {
expect_no_error(
read_animalta(path_roi, with_roi = TRUE)
read_animalta(path_raw, detailed = FALSE)
)
expect_no_error(
read_animalta(path_no_roi, with_roi = FALSE)
read_animalta(path_detailed, detailed = TRUE)
)
expect_error(
read_animalta(path_roi, with_roi = FALSE)
read_animalta(path_raw, detailed = TRUE)
)
expect_error(
read_animalta(path_no_roi, with_roi = TRUE)
read_animalta(path_detailed, detailed = FALSE)
)
expect_contains(
read_animalta(path_roi, with_roi = TRUE) |>
read_animalta(path_raw, detailed = FALSE) |>
names(),
c("time", "individual", "keypoint", "x", "y")
)
expect_contains(
read_animalta(path_no_roi, with_roi = FALSE) |>
read_animalta(path_detailed, detailed = TRUE) |>
names(),
c("time", "individual", "keypoint", "x", "y")
)
Expand Down

0 comments on commit f87c008

Please sign in to comment.