tests/testthat/helper-vars.R

## env vars
map_token = Sys.getenv("moveVis_map_token")
if(map_token != "") run_mapbox <- TRUE else run_mapbox <- FALSE
test_maps = as.logical(Sys.getenv("moveVis_test_maps"))

n_cores <- as.numeric(Sys.getenv("moveVis_n_cores"))
if(!is.na(n_cores)) if(n_cores > 1) use_multicore(n_cores)

check_mapview <- any(grepl("mapview", installed.packages()[,1]))
check_leaflet <- any(grepl("leaflet", installed.packages()[,1]))


## which tests to run
# which_tests = Sys.getenv("moveVis_which_tests")
# if(which_tests != ""){
#   which_tests <- strsplit(which_tests, ";")[[1]]
# } else{
#   which_test <- c("add_", "align_move", "deprecated", "frames_graph", "frames_spatial", "get_maptypes", "suggest_formats")
# }

## directories
test_dir <- Sys.getenv("moveVis_test_dir")
if(test_dir != ""){
  if(!dir.exists(test_dir)) dir.create(test_dir)
}else{
  test_dir <- tempdir()
}
cat("Test directory: ", test_dir, "\n")

data("move_data", package = "moveVis", envir = environment())
data("basemap_data", package = "moveVis", envir = environment())

## movement
m <- move_data
m.aligned <- align_move(m, res = 4, unit = "mins")

# shift across dateline
l.df <- lapply(move::split(m.aligned), as.data.frame)
df <- do.call(rbind, mapply(x = names(l.df), y = l.df, function(x, y){
  y$id = x
  return(y)
}, SIMPLIFY = F))
df$x <- df$x+171.06
df$x[df$x > 180] <- df$x[df$x > 180]-360

m.shifted <- df2move(df, "+proj=longlat +datum=WGS84 +no_defs", "x", "y", "time", "id")

# transform using sf
df <- sf::st_transform(sf::st_as_sf(m.shifted), sf::st_crs("+init=epsg:3995"))
df <- cbind.data.frame(sf::st_coordinates(df), time = df$time, id = move::trackId(m.shifted))
m.shifted.repro <- df2move(df = df, proj = "+init=epsg:3995", x = "X", y = "Y", time = "time", track_id = "id")

## base map
r_grad <- basemap_data[[1]]
r_disc <- lapply(r_grad, function(x){
  y <- raster::setValues(x, round(raster::getValues(x)*10))
  return(y)
})
r_times <- basemap_data[[2]]

Try the moveVis package in your browser

Any scripts or data that you put into this service are public.

moveVis documentation built on March 31, 2020, 5:08 p.m.