mt_is_track_id_cleaved {move2}R Documentation

Functions for asserting properties of a move2 object

Description

Usage

mt_is_track_id_cleaved(x)

mt_is_time_ordered(x, non_zero = FALSE)

mt_has_unique_location_time_records(x)

mt_is_time_ordered_non_empty_points(x, non_zero = FALSE)

mt_has_no_empty_points(x)

mt_is_move2(x)

Arguments

x

a move2 object

non_zero

If TRUE only intervals longer than 0 are considered ordered (i.e. no coinciding timestamps), if FALSE also 0 intervals are considered ordered

Details

For these functions an on_failure error function is defined. This results in meaningful error messages when the function is used in combination with assert_that. These functions can also be used in normal logical operations as TRUE or FALSE is returned.

Value

a logical value if the asserted property is TRUE or FALSE

Examples

## examples of what to do if assertion if FALSE
n <- 8
data <- data.frame(x = cumsum(rnorm(n)), y = cumsum(rnorm(n)),
                   time = seq(n), track = sample(c("a","b"), size=n, replace=TRUE))
data <- rbind(data, data[sample(nrow(data),2),]) # adding duplicate timestamps
mv <- mt_as_move2(data, coords = c("x", "y"),
                  time_column = "time",
                  track_id_column = "track")
mv$geometry[c(1, 3)] <- sf::st_point() # adding empty locations

mt_is_track_id_cleaved(mv)
mv <- dplyr::arrange(mv, mt_track_id(mv))

mt_is_time_ordered(mv)
mv <- dplyr::arrange(mv, mt_track_id(mv), mt_time(mv))

mt_has_unique_location_time_records(mv)
mv <- mt_filter_unique(mv)

mt_has_no_empty_points(mv)
mv <- dplyr::filter(mv, !sf::st_is_empty(mv))

## example of using the assertions with assertthat
if (requireNamespace("assertthat")) {
  m <- mt_sim_brownian_motion(t = 1:2, tracks = 2)
  assertthat::see_if(mt_is_track_id_cleaved(m))
  assertthat::see_if(mt_is_track_id_cleaved(m[c(3, 1, 2, 4), ]))
  assertthat::see_if(mt_is_time_ordered(m[c(2:1, 3, 4), ]))
  assertthat::see_if(mt_has_unique_location_time_records(m[c(1, 1, 2, 3, 4), ]))
  assertthat::see_if(mt_is_move2(m$time))
}


[Package move2 version 0.2.7 Index]