checkTrajectories.R (1413B)
1 #' Check that both arguments are trajectories with the same timecourse. 2 #' 3 #' @param trajectory1 An object to test. 4 #' @param trajectory2 Another object to test. 5 #' @return TRUE if everything works. Raises an error otherwise. 6 #' 7 #' @details There are two options for passing this test. Either both objects can 8 #' be flighttrajectories, in which case the time stamps must match, or they 9 #' can both be flattrajectories, in which case they must have the same number 10 #' of samples and origin. 11 checkTrajectories <- function(trajectory1, trajectory2) { 12 # Two flight trajectories 13 if (flightpathr::is.flighttrajectory(trajectory1)) { 14 if (!flightpathr::is.flighttrajectory(trajectory2)) { 15 stop("'trajectory1' is a flighttrajectory; 'trajectory2' must match this type") 16 } 17 if (!isTRUE(all.equal(trajectory1$timestamp, trajectory2$timestamp))) { 18 stop("flighttrajectories must have matching time stamps") 19 } 20 } else if (is.flattrajectory(trajectory1)) { 21 if (!is.flattrajectory(trajectory2)) { 22 stop("'trajectory1' is a flattrajectory; 'trajectory2' must match this type") 23 } 24 if (nrow(trajectory1$position) != nrow(trajectory2$position)) { 25 stop("flattrajectories must have the same number of samples") 26 } 27 if (!isTRUE(all.equal(trajectory1$origin, trajectory2$origin))) { 28 stop("flattrajectories must have the same origin") 29 } 30 } 31 return(TRUE) 32 }