Skip to content

Commit

Permalink
Add check for coordinates on spatial data object
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-j committed Aug 22, 2023
1 parent 4bef5f5 commit 5c04319
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(clear_caches)
export(get_tutorial_datapath)
export(has_coords)
export(interactive_priors)
export(latlong_to_utm)
export(load_tutorial_data)
Expand Down
8 changes: 5 additions & 3 deletions R/shiny_priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ priors_shiny <- function(spatial_data,
measurement_data,
time_variable,
mesh) {
# requireNamespace("INLA")
# requireNamespace("future")
# requireNamespace("promises")
future::plan(future::multisession())

got_coords <- has_coords(spatial_data = spatial_data)
if (!got_coords) {
stop("Please make sure you have set coordinates on spatial_data using sp::coordinates.")
}

# Text for priors help
prior_range_text <- "A length 2 vector, with (range0, Prange) specifying that P(ρ < ρ_0)=p_ρ,
where ρ is the spatial range of the random field."
Expand Down
20 changes: 20 additions & 0 deletions R/util_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ latlong_to_utm <- function(lat, lon) {
# Return the UTM coordinates as a vector
return(c(output_point@coords[, 1], output_point@coords[, 2]))
}


#' Check if spatial data has coordinates set using sp::coordinates()
#' Returns TRUE if coordinates have been set
#'
#' @param spatial_data
#'
#' @return bool
#' @export
has_coords <- function(spatial_data) {
tryCatch(
{
sp::coordinates(spatial_data)
TRUE
},
error = function(err) {
FALSE
}
)
}
2 changes: 1 addition & 1 deletion vignettes/priors_app.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ First start by selecting the variable to model. In this example we'll select `ca
Click on the checkboxes to select your formula and then click the `Run Model` button to run the model see it's output plot on the right of the window.

```{r eval=FALSE}
fdmr::interactive_priors(spatial_data = sp_data, measurement_data = covid19_data, mesh=mesh)
fdmr::interactive_priors(spatial_data = sp_data, measurement_data = covid19_data, mesh=mesh, time_variable="week")
```

# Viewing model outputs and parameter sets
Expand Down

0 comments on commit 5c04319

Please sign in to comment.