mt_is_track_id_cleaved {move2} | R Documentation |
Functions for asserting properties of a move2
object
Description
-
mt_is_track_id_cleaved()
asserts all tracks are grouped in the data set, they occur consecutively. -
mt_is_time_ordered()
checks if all tracks are groups and if timestamps within a track are ascending (i.e. the time differences between successive locations are equal or above 0). -
mt_has_unique_location_time_records()
checks if all records with a location have a unique timestamp (i.e. checks for duplicated timestamps within a track). -
mt_is_time_ordered_non_empty_points()
this assertion combines themt_is_time_ordered()
andmt_has_no_empty_points()
assertions and thus ensures that each record has a location and timestamps are ordered. -
mt_has_no_empty_points()
asserts all geometries are points and that there are no empty points. -
mt_is_move2()
assertsx
inherits the classmove2
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 |
non_zero |
If |
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))
}