diff --git a/CHANGELOG.md b/CHANGELOG.md index 05380de..4e4f9cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Removed non-numeric/non-logical variable features from `shiny_modelbuilder` - [PR #341](https://github.com/4DModeller/fdmr/pull/341) +- Updated documentation for all functions to reflect better the inputs and outputs - [PR #332](https://github.com/4DModeller/fdmr/pull/332) +- Fixed an error in `model_viewer` description - [PR #331](https://github.com/4DModeller/fdmr/pull/331) +- Added to `retrieve_tutorial_data` an option to save tutorial data at a user-specified location or in a temporary directory as default - [PR #330](https://github.com/4DModeller/fdmr/pull/330) - Fixed `model_viewer` app to work with random effect models - [PR #317](https://github.com/4DModeller/fdmr/pull/317) - Updated `plot_map_leaflet` to feature the same selection of basemap tiles as `mapview` and fix features not appearing - [PR #310](https://github.com/4DModeller/fdmr/pull/310) diff --git a/DESCRIPTION b/DESCRIPTION index 08d1088..4ebd2bf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ BugReports: https://github.com/4DModeller/fdmr/issues License: GPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Additional_repositories: https://inla.r-inla-download.org/R/testing Imports: colorspace, diff --git a/R/meshing.R b/R/meshing.R index 9d4e704..9eb36c3 100644 --- a/R/meshing.R +++ b/R/meshing.R @@ -1,10 +1,10 @@ # This function taken from https://groups.google.com/g/r-inla-discussion-group/c/z1n1exlZrKM/m/8vYNr2D8BwAJ #' Convert an INLA mesh to a SpatialPolygonsDataFrame #' -#' @param mesh Mesh -#' @param crs Coordinate Reference System as proj4string +#' @param mesh Mesh object from INLA or fmesher (only R2 manifolds are valid) +#' @param crs Coordinate Reference System as proj4string, does not support geocentric coordinates #' -#' @return SpatialPolygonsDataFrame +#' @return SpatialPolygonsDataFrame with mesh triangles #' @export mesh_to_spatial <- function(mesh, crs) { if (!is.character(crs)) { diff --git a/R/meshing_checks.R b/R/meshing_checks.R index 78271bb..5d2a5d3 100644 --- a/R/meshing_checks.R +++ b/R/meshing_checks.R @@ -3,8 +3,8 @@ #' 2. A greater number of mesh triangles than observations #' 3. Isolated triangles in mesh #' -#' @param mesh INLA mesh -#' @param observations Observations data to be used woith model +#' @param mesh INLA/fmesher mesh +#' @param observations Observations data to be used with model (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) #' #' @return list: Named list containing errors #' @export diff --git a/R/model_parse.R b/R/model_parse.R index 2e8a9a1..786523d 100644 --- a/R/model_parse.R +++ b/R/model_parse.R @@ -1,9 +1,9 @@ #' Parses inlabru::bru model output to create a list of model parameters #' #' @param model_output Output from running inlabru::bru -#' @param measurement_data Measurement data +#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) #' -#' @return list +#' @return Creates a list of model outputs for the first timestep, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC #' @keywords internal parse_model_output_bru <- function(model_output, measurement_data) { fitted_mean_post <- model_output$summary.fitted.values$mean[seq_len(nrow(measurement_data))] @@ -33,11 +33,11 @@ parse_model_output_bru <- function(model_output, measurement_data) { #' Parse model output to create a list of model parameters #' -#' @param model_output Data returned by model -#' @param measurement_data Measurement data -#' @param model_type Type of model, we currently support inlabru +#' @param model_output Output returned by model (currently only from running inlabru::bru) +#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) +#' @param model_type Type of model, we currently only support inlabru #' -#' @return list +#' @return Creates a list of model outputs, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC #' @export parse_model_output <- function(model_output, measurement_data, model_type = "inlabru") { if (model_type == "inlabru") { @@ -48,13 +48,13 @@ parse_model_output <- function(model_output, measurement_data, model_type = "inl #' Create a prediction field from the parsed model output and the mesh #' -#' @param mesh INLA mesh -#' @param plot_type Type of plot to create, "predicted_mean_fields" etc -#' @param data_dist Type of data, "poisson" etc -#' @param var_a Data for variable a, required for "predicted_mean_fields" and "random_effect_fields" -#' @param var_b Data for variable b, required for "predicted_mean_fields" +#' @param mesh INLA/fmesher mesh +#' @param plot_type Type of plot to create, "predicted_mean_fields" or "random_mean_fields" +#' @param data_dist Type of data, "poisson" or "gaussian" +#' @param var_a Data for variable a (numeric), required for "predicted_mean_fields" and "random_effect_fields"; normally, random effect field from "summary.random$f" +#' @param var_b Data for variable b (numeric), required for "predicted_mean_fields"; normally, fixed effect from "summary.fixed" #' -#' @return data.frame +#' @return data.frame with mesh node latlong coordinates (x, y) and the selected field values at the mesh nodes (z) #' @export create_prediction_field <- function(mesh, plot_type = "predicted_mean_fields", diff --git a/R/plot_graph.R b/R/plot_graph.R index 5bc8beb..153abe2 100644 --- a/R/plot_graph.R +++ b/R/plot_graph.R @@ -1,9 +1,9 @@ #' Plot a bar chart using ggplot2 #' -#' @param data Data to plot -#' @param x x-axis data +#' @param data Data to plot (all data types recognised by ggplot2::geom_bar() like data.frame) +#' @param x x-axis data, must be a Date object #' @param y y-axis data -#' @param breaks Break points +#' @param breaks Break points, must be a sequence of dates #' @param x_label x-axis label #' @param y_label y-axis label #' @param fill Fill colour @@ -47,10 +47,10 @@ plot_barchart <- function(data, x, y, breaks, x_label, y_label, fill = "pink", c #' Plot a boxplot using ggplot2 #' -#' @param data Data to plot -#' @param x x-axis data +#' @param data Data to plot (all data types recognised by ggplot2::geom_boxplot() like data.frame) +#' @param x x-axis data, must be a Date object #' @param y y-axis data -#' @param breaks Break points +#' @param breaks Break points, must be a sequence of dates #' @param x_label x-axis label #' @param y_label y-axis label #' @@ -82,10 +82,10 @@ plot_boxplot <- function(data, x, y, breaks, x_label, y_label) { #' Plot timeseries data #' -#' @param data Data to plot -#' @param x Name of column to plot on x-axis, should be datetime, will be converted to Dates using as.Date +#' @param data Data to plot (data.frame with x-axis column a character convertible to Date) +#' @param x Name of column to plot on x-axis #' @param y Name of column to plot on y-axis -#' @param breaks Date break points +#' @param breaks Date break points, must be a sequence of dates #' @param x_label x-axis label #' @param y_label y-axis label #' @param title Figure title @@ -93,8 +93,8 @@ plot_boxplot <- function(data, x, y, breaks, x_label, y_label) { #' @param line_colour Line colour #' @param horizontal_y y-intercept for horizontal line #' @param vertical_x x-intercept for vertical line -#' @param x_lim Limits for x-axis continous scale, vector passed to scale_x_continuous -#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continous +#' @param x_lim Limits for x-axis continuous scale, vector passed to scale_x_continuous +#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continuous #' #' @return ggplot #' @export @@ -172,12 +172,12 @@ plot_timeseries <- function(data, #' Create a line plot with a confidence interval. #' -#' @param data Data to plot -#' @param x x-axis data +#' @param data Data to plot (all data types recognised by ggplot2::geom_line() like data.frame) +#' @param x x-axis data, must be a Date object #' @param y1 y1 line data - solid #' @param y2 y2 line data - dashed #' @param y3 y3 line data - dashed -#' @param breaks Breaks vector +#' @param breaks Breaks vector, must be a sequence of dates #' @param x_label x-axis label #' @param y_label y-axis label #' @param y1_colour Colour for y1 diff --git a/R/plot_mapping.R b/R/plot_mapping.R index bc79a9d..a9be946 100644 --- a/R/plot_mapping.R +++ b/R/plot_mapping.R @@ -6,10 +6,10 @@ #' The leaflet backend will work for most use cases and is recommended. #' For plotting of maps with UTM coordinates, the mapview backend is recommended. #' -#' @param polygon_data Polygon data -#' @param raster_data Raster datas -#' @param domain Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend -#' @param markers Markers to display on map. A named list with latitude, longitude and label names must be given. +#' @param polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame) +#' @param raster_data Raster data (RasterLayer or SpatialRaster) +#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend +#' @param markers Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given. #' @param palette Palette to be used for colours, defaults to viridis #' @param legend_title Title for legend #' @param add_scale_bar Add scale bar if TRUE @@ -71,10 +71,10 @@ plot_map <- function(polygon_data = NULL, #' Create a simple Leaflet map from data #' -#' @param polygon_data Polygon data -#' @param raster_data Raster data -#' @param domain Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend -#' @param markers Markers to display on map. A named list with latitude, longitude and label names must be given. +#' @param polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame) +#' @param raster_data Raster data (RasterLayer or SpatialRaster) +#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend +#' @param markers Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given. #' @param palette Palette to be used for colours, defaults to viridis #' @param legend_title Title for legend #' @param add_scale_bar Add scale bar if TRUE diff --git a/R/plot_mesh.R b/R/plot_mesh.R index 617ad9a..07fd6d5 100644 --- a/R/plot_mesh.R +++ b/R/plot_mesh.R @@ -1,14 +1,14 @@ #' Plot a mesh on a Leaflet map #' -#' @param mesh Mesh data +#' @param mesh Mesh object from INLA or fmesher #' @param spatial_data Spatial data, either a SpatialPolygonsDataFrame, SpatialPointsDataFrame or an object #' that can be converted to a data.frame with longitude and latitude columns -#' @param longitude_column Longitude column in spatial_data -#' @param latitude_column Latitude column in spatial_data name +#' @param longitude_column Longitude column name in spatial_data +#' @param latitude_column Latitude column name in spatial_data #' @param markers Markers to display on top of mesh. A named list with latitude, longitude and label names must be given. #' Expects longitude name to be longitude, latitude name to be latitude, label name to be label. #' -#' @return leaflet::leaflet +#' @return leaflet::leaflet with mesh and markers #' @export plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", latitude_column = "LAT", markers = NULL) { expected_crs <- "+proj=longlat +datum=WGS84" diff --git a/R/plot_priors.R b/R/plot_priors.R index 7c8524a..d4312b8 100644 --- a/R/plot_priors.R +++ b/R/plot_priors.R @@ -1,10 +1,11 @@ #' Plot line comparison for stdev etc #' -#' @param data Parsed model output +#' @param data List of parsed model outputs from "parse_model_output" (a list of lists) #' @param to_plot Type of data to plot, "Range for f" etc +#' @param title Title of the plot, defaults to the value of "to_plot" #' -#' @return ggplot2::ggplot -plot_line_comparison <- function(data, to_plot, title) { +#' @return ggplot2::ggplot of the selected hyperparameter posterior distribution +plot_line_comparison <- function(data, to_plot, title = to_plot) { parsed_data <- purrr::map(data, function(x) as.data.frame(x$pars[[to_plot]])) single_df <- dplyr::bind_rows(parsed_data, .id = "Run") if (nrow(single_df) == 0) { @@ -19,9 +20,9 @@ plot_line_comparison <- function(data, to_plot, title) { #' Create boxplots from priors run data #' -#' @param data +#' @param data A list of parsed model output from "parse_model_output" (a list of lists) #' -#' @return graphics::boxplot +#' @return graphics::boxplot of fitted values plot_priors_boxplot <- function(data) { # TODO - I'm sure this can be done in a nicer functional way fitted_mean_post <- purrr::map(data, function(x) x$fitted_mean_post) @@ -34,10 +35,10 @@ plot_priors_boxplot <- function(data) { #' Plot density function #' #' -#' @param data Parsed model outputs -#' @param measurement_data Measurement data +#' @param data List of parsed model outputs from "parse_model_output" (a list of lists) +#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) #' -#' @return ggplot2::ggplot +#' @return ggplot2::ggplot of measurement density by value plot_priors_density <- function(data, measurement_data) { # Can this be done in a cleaner way? Just create a dataframe from the lists? fitted_values <- unlist(purrr::map(data, function(x) x$fitted_mean_post)) @@ -56,9 +57,9 @@ plot_priors_density <- function(data, measurement_data) { #' Plot Deviance Information Criterion (DIC) values #' -#' @param data +#' @param data List of parsed model outputs from "parse_model_output" (a list of lists) #' -#' @return ggplot2::ggplot +#' @return ggplot2::ggplot with DIC values shown as points plot_dic <- function(data) { infocri <- base::cbind.data.frame( priors = unlist(purrr::map(seq(1, length(data)), function(x) paste("Run", x))), diff --git a/R/shiny_meshbuilder.R b/R/shiny_meshbuilder.R index 8a22be0..7ce5ed9 100644 --- a/R/shiny_meshbuilder.R +++ b/R/shiny_meshbuilder.R @@ -1,6 +1,6 @@ #' Mesh building shiny app #' -#' @param spatial_data Spatial data +#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame) #' @param obs_data Measurement data #' @param crs CRS as a proj4string #' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla @@ -11,7 +11,7 @@ #' #' @importFrom magrittr %>% #' -#' @return shiny::app +#' @return shiny::app with meshbuilder functionality #' @keywords internal meshbuilder_shiny <- function( spatial_data, @@ -55,10 +55,10 @@ meshbuilder_shiny <- function( stop("Cannot read latitude and longitude data from spatial data. Please ensure given names are correct.") } - default_max_edge_min <- 0.01 - default_max_edge_max <- 0.3 + default_max_edge_min <- 0.9 + default_max_edge_max <- 1.8 default_offset_min <- 0.02 - default_offset_max <- 0.2 + default_offset_max <- 2 default_cutoff <- 0.02 # TODO - these defaults need changing? if (!is.null(max_edge)) { @@ -234,7 +234,7 @@ meshbuilder_shiny <- function( spatial_data } }) - + output$map <- leaflet::renderLeaflet({ map_tiles <- c("OpenStreetMap", "Esri.WorldImagery", "OpenTopoMap") m <- mapview::mapview(mesh_spatial(), layer.name = "Mesh", col.regions = "#548C2F", map.types = map_tiles) + mapview::mapview(spatial(), layer.name = "Spatial") @@ -270,7 +270,7 @@ meshbuilder_shiny <- function( #' Mesh building shiny app. Creates and visualises a mesh from some spatial data. #' -#' @param spatial_data Spatial data +#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame) #' @param obs_data Measurement data #' @param crs CRS as a proj4string #' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla @@ -279,7 +279,7 @@ meshbuilder_shiny <- function( #' @param y_coord Name of the latitude column in the spatial data #' @param x_coord Name of the longitude column in the spatial data #' -#' @return shiny::app +#' @return shiny::app with meshbuilder functionality #' @export mesh_builder <- function(spatial_data, obs_data = NULL, crs = NULL, max_edge = NULL, offset = NULL, cutoff = NULL, y_coord = "LAT", x_coord = "LONG") { shiny::runApp(meshbuilder_shiny( diff --git a/R/shiny_modelbuilder.R b/R/shiny_modelbuilder.R index fc395d3..577fcdd 100644 --- a/R/shiny_modelbuilder.R +++ b/R/shiny_modelbuilder.R @@ -1,15 +1,15 @@ #' Interactively set and see the result of different priors #' -#' @param spatial_data Spatial data -#' @param measurement_data Measurement data -#' @param time_variable Time variable in measurement_data -#' @param mesh INLA mesh +#' @param spatial_data Spatial data (must be SpatialPoints or SpatialPointsDataFrame) +#' @param measurement_data Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements) +#' @param time_variable Time variable name in measurement_data +#' @param mesh INLA/fmesher mesh #' @param data_distribution Data distribution, Poisson or Gaussian -#' @param log_folder Folder to write out logs +#' @param log_folder Folder to write out logs (character) #' #' @importFrom INLA f #' -#' @return shiny::app +#' @return shiny::app with model builder functionality #' @keywords internal model_builder_shiny <- function(spatial_data, measurement_data, @@ -65,7 +65,7 @@ model_builder_shiny <- function(spatial_data, citation_control_group <- "Prior explanation text modified from https://www.paulamoraga.com/book-geospatial/sec-geostatisticaldataexamplest.html" initial_equation_val <- "formula <- model_var ~ 0 + Intercept(1)" - features <- names(measurement_data) + features <- names(measurement_data@data[base::sapply(measurement_data@data, is.numeric) | base::sapply(measurement_data@data, is.logical)]) if (is.null(features)) { stop("We require the columns of measurement_data to have the names of the features to use in the model.") } @@ -697,12 +697,12 @@ model_builder_shiny <- function(spatial_data, #' Interactively set and see the result of different priors #' #' @param spatial_data Spatial data -#' @param measurement_data Measurement data -#' @param time_variable Time variable in measurement_data -#' @param mesh INLA mesh -#' @param log_folder Folder to write logs to +#' @param measurement_data Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements) +#' @param time_variable Time variable name in measurement_data +#' @param mesh INLA/fmesher mesh +#' @param log_folder Folder to write logs to (character) #' -#' @return shiny::app +#' @return shiny::app with model builder functionality #' @export model_builder <- function(spatial_data, measurement_data, time_variable, mesh, data_distribution = "Poisson", log_folder = NULL) { shiny::runApp(model_builder_shiny(spatial_data = spatial_data, measurement_data = measurement_data, time_variable = time_variable, mesh = mesh, data_distribution = data_distribution, log_folder = log_folder)) diff --git a/R/shiny_modelviewer.R b/R/shiny_modelviewer.R index 1bb6a9e..d83b084 100644 --- a/R/shiny_modelviewer.R +++ b/R/shiny_modelviewer.R @@ -1,13 +1,13 @@ #' Parse inlabru model output #' -#' @param model_output INLA model output -#' @param mesh INLA mesh -#' @param measurement_data Measurement data +#' @param model_output INLA/inlabru model output +#' @param mesh INLA/fmesher mesh +#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) #' @param data_distribution Type of data, Poisson or Gaussian #' #' @importFrom magrittr %>% #' -#' @return shiny::app +#' @return shiny::app with model viewer functionality #' @keywords internal model_viewer_shiny <- function(model_output, mesh, measurement_data, data_distribution) { busy_spinner <- get_busy_spinner() @@ -295,14 +295,14 @@ model_viewer_shiny <- function(model_output, mesh, measurement_data, data_distri shiny::shinyApp(ui = ui, server = server) } -#' Mesh building shiny app. Creates and visualises a mesh from some spatial data. +#' Model viewing shiny app. Visualises INLA model output, plots the posterior distributions of model parameters and prediction statistics. #' -#' @param model_output INLA model output -#' @param mesh INLA mesh -#' @param measurement_data Measurement data -#' @param data_distribution Type of data, Poisson or Gaussian +#' @param model_output INLA/inlabru model output +#' @param mesh INLA/fmesher mesh used for the run +#' @param measurement_data Measurement data used for the run (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection) +#' @param data_distribution Type of data, Poisson or Gaussian (character) #' -#' @return shiny::app +#' @return shiny::app with model viewer functionality #' @export model_viewer <- function(model_output, mesh, measurement_data, data_distribution = "Poisson") { shiny::runApp(model_viewer_shiny(model_output = model_output, mesh = mesh, measurement_data = measurement_data, data_distribution = data_distribution)) diff --git a/R/util_paths.R b/R/util_paths.R index 5ccee5b..24c748f 100644 --- a/R/util_paths.R +++ b/R/util_paths.R @@ -2,11 +2,12 @@ #' #' @param dataset Name of dataset #' @param filename Name of file +#' @param saved Specify the location where user unpacked the data. #' #' @return fs::path Full filepath #' @export -get_tutorial_datapath <- function(dataset, filename) { - tutorial_datapath <- fs::path(get_tutorial_cache_datapath(), dataset) +get_tutorial_datapath <- function(dataset, filename, saved = FALSE) { + tutorial_datapath <- fs::path(get_tutorial_cache_datapath(saved), dataset) if (!fs::dir_exists(tutorial_datapath)) { stop("Unable to load data, the folder ", toString(tutorial_datapath), " does not exist. Have you run retrieve_tutorial_data?") @@ -26,15 +27,16 @@ get_tutorial_datapath <- function(dataset, filename) { #' #' @param dataset Name of dataset #' @param filename Name of file +#' @param saved Specify the location where user unpacked the data #' #' @return loaded object #' @export -load_tutorial_data <- function(dataset, filename) { +load_tutorial_data <- function(dataset, filename, saved = FALSE) { if (!tolower(fs::path_ext(filename)) == "rds") { stop("We can only load rds files.") } - fpath <- get_tutorial_datapath(dataset = dataset, filename = filename) + fpath <- get_tutorial_datapath(dataset = dataset, filename = filename, saved = saved) return(readRDS(fpath)) } @@ -62,30 +64,55 @@ clean_path <- function(path, check_exists = FALSE) { return(fpath) } + #' Get path to tutorial data cache folder +#' +#' @param saved Specify the location where user unpacked the data #' #' @return fs::path #' @keywords internal -get_tutorial_cache_datapath <- function() { - fs::path(fs::path_home(), "fdmr", "tutorial_data") +get_tutorial_cache_datapath <- function(saved) { + if (base::isTRUE(saved) | base::is.character(saved)){ + if (base::is.character(saved)) { + save_path <- check_path(saved) + fs::path(save_path, "fdmr", "tutorial_data") + } else{ + fs::path(fs::path_home(), "fdmr", "tutorial_data") + } + } else { + fs::path(fs::path_temp(), "fdmr", "tutorial_data") + } } #' Get path to downloaded archive cache folder +#' +#' @param saved Specify the location where user unpacked the data #' #' @return fs::path #' @keywords internal -get_archive_cache_datapath <- function() { - fs::path(fs::path_home(), "fdmr", "download_cache") +get_archive_cache_datapath <- function(saved) { + if (base::isTRUE(saved) | base::is.character(saved)){ + if (base::is.character(saved)) { + save_path <- check_path(saved) + fs::path(save_path, "fdmr", "download_cache") + } else{ + fs::path(fs::path_home(), "fdmr", "download_cache") + } + } else { + fs::path(fs::path_temp(), "fdmr", "download_cache") + } } #' Clear both tutorial data and downloaded archive caches #' +#' @param saved Specify the location where user unpacked the data +#' #' @return NULL #' @export -clear_caches <- function() { - tut_path <- get_tutorial_cache_datapath() - cache_path <- get_archive_cache_datapath() +clear_caches <- function(saved = TRUE) { + tut_path <- get_tutorial_cache_datapath(saved) + cache_path <- get_archive_cache_datapath(saved) print(paste("Deleting ", tut_path, cache_path)) fs::dir_delete(tut_path) fs::dir_delete(cache_path) diff --git a/R/util_retrieve.R b/R/util_retrieve.R index 7a284c2..1270756 100644 --- a/R/util_retrieve.R +++ b/R/util_retrieve.R @@ -1,14 +1,25 @@ -#' Retrieve a tutorial dataset and unpacks it to ~/fdmr/tutorial_data +#' Retrieves a tutorial dataset and unpacks it to a place specified by the user (~/fdmr/tutorial_data) #' #' @param dataset Name of dataset to retrieve #' @param force_update Force retrieval of metadata and dataset +#' @param save Unpack the dataset to where user specified (character), home directory (TRUE), session's temporary directory (FALSE: default). #' #' @return NULL #' @export -retrieve_tutorial_data <- function(dataset, force_update = FALSE) { +retrieve_tutorial_data <- function(dataset, force_update = FALSE, save = FALSE) { dataset <- base::tolower(dataset) - download_cache_folder <- fs::path(fs::path_home(), "fdmr", "download_cache") + if (base::isTRUE(save) | base::is.character(save)){ + if (base::is.character(save)) { + save_path <- clean_path(save, check_exists = TRUE) + download_cache_folder <- fs::path(save_path, "fdmr", "download_cache") + } else{ + download_cache_folder <- fs::path(fs::path_home(), "fdmr", "download_cache") + } + } else { + download_cache_folder <- fs::path(fs::path_temp(), "fdmr", "download_cache") + } + if (!fs::dir_exists(download_cache_folder)) { fs::dir_create(download_cache_folder, recurse = TRUE) } @@ -40,7 +51,17 @@ retrieve_tutorial_data <- function(dataset, force_update = FALSE) { jsonlite::write_json(retrieval_info, path = file_metadata_file) } - extract_path <- fs::path(fs::path_home(), "fdmr", "tutorial_data", dataset) + if (base::isTRUE(save) | base::is.character(save)){ + if (base::is.character(save)){ + save_path <- clean_path(save, check_exists = TRUE) + extract_path <- fs::path(save_path, "fdmr", "tutorial_data", dataset) + } else{ + extract_path <- fs::path(fs::path_home(), "fdmr", "tutorial_data", dataset) + } + } else { + extract_path <- fs::path(fs::path_temp(), "fdmr", "tutorial_data", dataset) + } + if (!fs::dir_exists(extract_path)) { fs::dir_create(extract_path, recurse = TRUE) @@ -72,4 +93,4 @@ retrieve_tutorial_data <- function(dataset, force_update = FALSE) { } else { stop("Invalid dataset, please see available datasets at https://github.com/4DModeller/fdmr_data") } -} +} \ No newline at end of file diff --git a/README.md b/README.md index 7a25c95..e56157b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ The easiest way to do this is to [install RStudio](https://posit.co/downloads/). Next start an R session and run ```R +install.packages("INLA", repos=c(getOption("repos"), INLA="https://inla.r-inla-download.org/R/testing"), dep=TRUE) install.packages("devtools") library(devtools) devtools::install_github("4DModeller/fdmr") @@ -37,6 +38,8 @@ devtools::install_github("4DModeller/fdmr") You should now have `fdmr` and all its dependencies installed and you can continue on [one of our tutorials](https://4dmodeller.github.io/fdmr/articles/). +If your installation of `INLA` fails, please consult the [R-INLA website](https://www.r-inla.org/download-install) for platform-specific instructions. + ## Installation On most systems the commands above should get you up and running. On some Linux systems we've found the need to diff --git a/man/clear_caches.Rd b/man/clear_caches.Rd index f5fb2f6..e05db3b 100644 --- a/man/clear_caches.Rd +++ b/man/clear_caches.Rd @@ -4,7 +4,10 @@ \alias{clear_caches} \title{Clear both tutorial data and downloaded archive caches} \usage{ -clear_caches() +clear_caches(saved = TRUE) +} +\arguments{ +\item{saved}{Specify the location where user unpacked the data} } \description{ Clear both tutorial data and downloaded archive caches diff --git a/man/create_prediction_field.Rd b/man/create_prediction_field.Rd index aa3a115..cc3dd09 100644 --- a/man/create_prediction_field.Rd +++ b/man/create_prediction_field.Rd @@ -13,18 +13,18 @@ create_prediction_field( ) } \arguments{ -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh} -\item{plot_type}{Type of plot to create, "predicted_mean_fields" etc} +\item{plot_type}{Type of plot to create, "predicted_mean_fields" or "random_mean_fields"} -\item{data_dist}{Type of data, "poisson" etc} +\item{data_dist}{Type of data, "poisson" or "gaussian"} -\item{var_a}{Data for variable a, required for "predicted_mean_fields" and "random_effect_fields"} +\item{var_a}{Data for variable a (numeric), required for "predicted_mean_fields" and "random_effect_fields"; normally, random effect field from "summary.random$f"} -\item{var_b}{Data for variable b, required for "predicted_mean_fields"} +\item{var_b}{Data for variable b (numeric), required for "predicted_mean_fields"; normally, fixed effect from "summary.fixed"} } \value{ -data.frame +data.frame with mesh node latlong coordinates (x, y) and the selected field values at the mesh nodes (z) } \description{ Create a prediction field from the parsed model output and the mesh diff --git a/man/get_archive_cache_datapath.Rd b/man/get_archive_cache_datapath.Rd index d41132d..153ab8f 100644 --- a/man/get_archive_cache_datapath.Rd +++ b/man/get_archive_cache_datapath.Rd @@ -4,7 +4,10 @@ \alias{get_archive_cache_datapath} \title{Get path to downloaded archive cache folder} \usage{ -get_archive_cache_datapath() +get_archive_cache_datapath(saved) +} +\arguments{ +\item{saved}{Specify the location where user unpacked the data} } \value{ fs::path diff --git a/man/get_tutorial_cache_datapath.Rd b/man/get_tutorial_cache_datapath.Rd index 2fa2e8a..fa6370a 100644 --- a/man/get_tutorial_cache_datapath.Rd +++ b/man/get_tutorial_cache_datapath.Rd @@ -4,7 +4,10 @@ \alias{get_tutorial_cache_datapath} \title{Get path to tutorial data cache folder} \usage{ -get_tutorial_cache_datapath() +get_tutorial_cache_datapath(saved) +} +\arguments{ +\item{saved}{Specify the location where user unpacked the data} } \value{ fs::path diff --git a/man/get_tutorial_datapath.Rd b/man/get_tutorial_datapath.Rd index b7776a8..598ceba 100644 --- a/man/get_tutorial_datapath.Rd +++ b/man/get_tutorial_datapath.Rd @@ -4,12 +4,14 @@ \alias{get_tutorial_datapath} \title{Return the filepath for a tutorial data file.} \usage{ -get_tutorial_datapath(dataset, filename) +get_tutorial_datapath(dataset, filename, saved = FALSE) } \arguments{ \item{dataset}{Name of dataset} \item{filename}{Name of file} + +\item{saved}{Specify the location where user unpacked the data.} } \value{ fs::path Full filepath diff --git a/man/load_tutorial_data.Rd b/man/load_tutorial_data.Rd index 0f8a576..74a494f 100644 --- a/man/load_tutorial_data.Rd +++ b/man/load_tutorial_data.Rd @@ -4,12 +4,14 @@ \alias{load_tutorial_data} \title{Load data from the tutorial data store} \usage{ -load_tutorial_data(dataset, filename) +load_tutorial_data(dataset, filename, saved = FALSE) } \arguments{ \item{dataset}{Name of dataset} \item{filename}{Name of file} + +\item{saved}{Specify the location where user unpacked the data} } \value{ loaded object diff --git a/man/mesh_builder.Rd b/man/mesh_builder.Rd index b8b00ee..dc88467 100644 --- a/man/mesh_builder.Rd +++ b/man/mesh_builder.Rd @@ -16,7 +16,7 @@ mesh_builder( ) } \arguments{ -\item{spatial_data}{Spatial data} +\item{spatial_data}{Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)} \item{obs_data}{Measurement data} @@ -33,7 +33,7 @@ mesh_builder( \item{x_coord}{Name of the longitude column in the spatial data} } \value{ -shiny::app +shiny::app with meshbuilder functionality } \description{ Mesh building shiny app. Creates and visualises a mesh from some spatial data. diff --git a/man/mesh_checker.Rd b/man/mesh_checker.Rd index 186009f..0300b0d 100644 --- a/man/mesh_checker.Rd +++ b/man/mesh_checker.Rd @@ -12,9 +12,9 @@ mesh_checker(mesh, observations) } \arguments{ -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh} -\item{observations}{Observations data to be used woith model} +\item{observations}{Observations data to be used with model (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} } \value{ list: Named list containing errors diff --git a/man/mesh_to_spatial.Rd b/man/mesh_to_spatial.Rd index d5b8481..160b0ec 100644 --- a/man/mesh_to_spatial.Rd +++ b/man/mesh_to_spatial.Rd @@ -7,12 +7,12 @@ mesh_to_spatial(mesh, crs) } \arguments{ -\item{mesh}{Mesh} +\item{mesh}{Mesh object from INLA or fmesher (only R2 manifolds are valid)} -\item{crs}{Coordinate Reference System as proj4string} +\item{crs}{Coordinate Reference System as proj4string, does not support geocentric coordinates} } \value{ -SpatialPolygonsDataFrame +SpatialPolygonsDataFrame with mesh triangles } \description{ Convert an INLA mesh to a SpatialPolygonsDataFrame diff --git a/man/meshbuilder_shiny.Rd b/man/meshbuilder_shiny.Rd index 27656e2..b8d5f40 100644 --- a/man/meshbuilder_shiny.Rd +++ b/man/meshbuilder_shiny.Rd @@ -17,7 +17,7 @@ meshbuilder_shiny( ) } \arguments{ -\item{spatial_data}{Spatial data} +\item{spatial_data}{Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)} \item{obs_data}{Measurement data} @@ -34,7 +34,7 @@ meshbuilder_shiny( \item{x_coord}{Name of the longitude column in the spatial data} } \value{ -shiny::app +shiny::app with meshbuilder functionality } \description{ Mesh building shiny app diff --git a/man/model_builder.Rd b/man/model_builder.Rd index c9f43df..d8b8374 100644 --- a/man/model_builder.Rd +++ b/man/model_builder.Rd @@ -16,16 +16,16 @@ model_builder( \arguments{ \item{spatial_data}{Spatial data} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements)} -\item{time_variable}{Time variable in measurement_data} +\item{time_variable}{Time variable name in measurement_data} -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh} -\item{log_folder}{Folder to write logs to} +\item{log_folder}{Folder to write logs to (character)} } \value{ -shiny::app +shiny::app with model builder functionality } \description{ Interactively set and see the result of different priors diff --git a/man/model_builder_shiny.Rd b/man/model_builder_shiny.Rd index e48b033..e728197 100644 --- a/man/model_builder_shiny.Rd +++ b/man/model_builder_shiny.Rd @@ -14,20 +14,20 @@ model_builder_shiny( ) } \arguments{ -\item{spatial_data}{Spatial data} +\item{spatial_data}{Spatial data (must be SpatialPoints or SpatialPointsDataFrame)} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (SpatialPointsDataFrame, SpatialPolygonsDataFrame with a named time column and at least 1 named feature column with measurements)} -\item{time_variable}{Time variable in measurement_data} +\item{time_variable}{Time variable name in measurement_data} -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh} \item{data_distribution}{Data distribution, Poisson or Gaussian} -\item{log_folder}{Folder to write out logs} +\item{log_folder}{Folder to write out logs (character)} } \value{ -shiny::app +shiny::app with model builder functionality } \description{ Interactively set and see the result of different priors diff --git a/man/model_viewer.Rd b/man/model_viewer.Rd index 8ea96f7..48e9e43 100644 --- a/man/model_viewer.Rd +++ b/man/model_viewer.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/shiny_modelviewer.R \name{model_viewer} \alias{model_viewer} -\title{Mesh building shiny app. Creates and visualises a mesh from some spatial data.} +\title{Model viewing shiny app. Visualises INLA model output, plots the posterior distributions of model parameters and prediction statistics.} \usage{ model_viewer( model_output, @@ -12,17 +12,17 @@ model_viewer( ) } \arguments{ -\item{model_output}{INLA model output} +\item{model_output}{INLA/inlabru model output} -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh used for the run} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data used for the run (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} -\item{data_distribution}{Type of data, Poisson or Gaussian} +\item{data_distribution}{Type of data, Poisson or Gaussian (character)} } \value{ -shiny::app +shiny::app with model viewer functionality } \description{ -Mesh building shiny app. Creates and visualises a mesh from some spatial data. +Model viewing shiny app. Visualises INLA model output, plots the posterior distributions of model parameters and prediction statistics. } diff --git a/man/model_viewer_shiny.Rd b/man/model_viewer_shiny.Rd index 1e0fbcb..471d154 100644 --- a/man/model_viewer_shiny.Rd +++ b/man/model_viewer_shiny.Rd @@ -7,16 +7,16 @@ model_viewer_shiny(model_output, mesh, measurement_data, data_distribution) } \arguments{ -\item{model_output}{INLA model output} +\item{model_output}{INLA/inlabru model output} -\item{mesh}{INLA mesh} +\item{mesh}{INLA/fmesher mesh} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} \item{data_distribution}{Type of data, Poisson or Gaussian} } \value{ -shiny::app +shiny::app with model viewer functionality } \description{ Parse inlabru model output diff --git a/man/parse_model_output.Rd b/man/parse_model_output.Rd index 9caa7b9..ca0fbee 100644 --- a/man/parse_model_output.Rd +++ b/man/parse_model_output.Rd @@ -7,14 +7,14 @@ parse_model_output(model_output, measurement_data, model_type = "inlabru") } \arguments{ -\item{model_output}{Data returned by model} +\item{model_output}{Output returned by model (currently only from running inlabru::bru)} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} -\item{model_type}{Type of model, we currently support inlabru} +\item{model_type}{Type of model, we currently only support inlabru} } \value{ -list +Creates a list of model outputs, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC } \description{ Parse model output to create a list of model parameters diff --git a/man/parse_model_output_bru.Rd b/man/parse_model_output_bru.Rd index f5439ce..42fbb43 100644 --- a/man/parse_model_output_bru.Rd +++ b/man/parse_model_output_bru.Rd @@ -9,10 +9,10 @@ parse_model_output_bru(model_output, measurement_data) \arguments{ \item{model_output}{Output from running inlabru::bru} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} } \value{ -list +Creates a list of model outputs for the first timestep, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC } \description{ Parses inlabru::bru model output to create a list of model parameters diff --git a/man/plot_barchart.Rd b/man/plot_barchart.Rd index 27832e9..b02b021 100644 --- a/man/plot_barchart.Rd +++ b/man/plot_barchart.Rd @@ -16,13 +16,13 @@ plot_barchart( ) } \arguments{ -\item{data}{Data to plot} +\item{data}{Data to plot (all data types recognised by ggplot2::geom_bar() like data.frame)} -\item{x}{x-axis data} +\item{x}{x-axis data, must be a Date object} \item{y}{y-axis data} -\item{breaks}{Break points} +\item{breaks}{Break points, must be a sequence of dates} \item{x_label}{x-axis label} diff --git a/man/plot_boxplot.Rd b/man/plot_boxplot.Rd index 6e3477e..41398dc 100644 --- a/man/plot_boxplot.Rd +++ b/man/plot_boxplot.Rd @@ -7,13 +7,13 @@ plot_boxplot(data, x, y, breaks, x_label, y_label) } \arguments{ -\item{data}{Data to plot} +\item{data}{Data to plot (all data types recognised by ggplot2::geom_boxplot() like data.frame)} -\item{x}{x-axis data} +\item{x}{x-axis data, must be a Date object} \item{y}{y-axis data} -\item{breaks}{Break points} +\item{breaks}{Break points, must be a sequence of dates} \item{x_label}{x-axis label} diff --git a/man/plot_dic.Rd b/man/plot_dic.Rd index b92fa7d..631813e 100644 --- a/man/plot_dic.Rd +++ b/man/plot_dic.Rd @@ -7,10 +7,10 @@ plot_dic(data) } \arguments{ -\item{data}{} +\item{data}{List of parsed model outputs from "parse_model_output" (a list of lists)} } \value{ -ggplot2::ggplot +ggplot2::ggplot with DIC values shown as points } \description{ Plot Deviance Information Criterion (DIC) values diff --git a/man/plot_line_average.Rd b/man/plot_line_average.Rd index 778408f..d9ee39c 100644 --- a/man/plot_line_average.Rd +++ b/man/plot_line_average.Rd @@ -21,9 +21,9 @@ plot_line_average( ) } \arguments{ -\item{data}{Data to plot} +\item{data}{Data to plot (all data types recognised by ggplot2::geom_line() like data.frame)} -\item{x}{x-axis data} +\item{x}{x-axis data, must be a Date object} \item{y1}{y1 line data - solid} @@ -31,7 +31,7 @@ plot_line_average( \item{y3}{y3 line data - dashed} -\item{breaks}{Breaks vector} +\item{breaks}{Breaks vector, must be a sequence of dates} \item{x_label}{x-axis label} diff --git a/man/plot_line_comparison.Rd b/man/plot_line_comparison.Rd index b185b7d..7846a69 100644 --- a/man/plot_line_comparison.Rd +++ b/man/plot_line_comparison.Rd @@ -4,15 +4,17 @@ \alias{plot_line_comparison} \title{Plot line comparison for stdev etc} \usage{ -plot_line_comparison(data, to_plot, title) +plot_line_comparison(data, to_plot, title = to_plot) } \arguments{ -\item{data}{Parsed model output} +\item{data}{List of parsed model outputs from "parse_model_output" (a list of lists)} \item{to_plot}{Type of data to plot, "Range for f" etc} + +\item{title}{Title of the plot, defaults to the value of "to_plot"} } \value{ -ggplot2::ggplot +ggplot2::ggplot of the selected hyperparameter posterior distribution } \description{ Plot line comparison for stdev etc diff --git a/man/plot_map.Rd b/man/plot_map.Rd index 75c2f3d..5f039cf 100644 --- a/man/plot_map.Rd +++ b/man/plot_map.Rd @@ -22,13 +22,13 @@ plot_map( ) } \arguments{ -\item{polygon_data}{Polygon data} +\item{polygon_data}{Polygon data (SpatialPolygon or SpatialPolygonDataFrame)} -\item{raster_data}{Raster datas} +\item{raster_data}{Raster data (RasterLayer or SpatialRaster)} -\item{domain}{Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend} +\item{domain}{Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend} -\item{markers}{Markers to display on map. A named list with latitude, longitude and label names must be given.} +\item{markers}{Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given.} \item{palette}{Palette to be used for colours, defaults to viridis} diff --git a/man/plot_map_leaflet.Rd b/man/plot_map_leaflet.Rd index b6e583c..cb07cfe 100644 --- a/man/plot_map_leaflet.Rd +++ b/man/plot_map_leaflet.Rd @@ -21,13 +21,13 @@ plot_map_leaflet( ) } \arguments{ -\item{polygon_data}{Polygon data} +\item{polygon_data}{Polygon data (SpatialPolygon or SpatialPolygonDataFrame)} -\item{raster_data}{Raster data} +\item{raster_data}{Raster data (RasterLayer or SpatialRaster)} -\item{domain}{Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend} +\item{domain}{Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend} -\item{markers}{Markers to display on map. A named list with latitude, longitude and label names must be given.} +\item{markers}{Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given.} \item{palette}{Palette to be used for colours, defaults to viridis} diff --git a/man/plot_mesh.Rd b/man/plot_mesh.Rd index 9656973..0bf7e75 100644 --- a/man/plot_mesh.Rd +++ b/man/plot_mesh.Rd @@ -13,20 +13,20 @@ plot_mesh( ) } \arguments{ -\item{mesh}{Mesh data} +\item{mesh}{Mesh object from INLA or fmesher} \item{spatial_data}{Spatial data, either a SpatialPolygonsDataFrame, SpatialPointsDataFrame or an object that can be converted to a data.frame with longitude and latitude columns} -\item{longitude_column}{Longitude column in spatial_data} +\item{longitude_column}{Longitude column name in spatial_data} -\item{latitude_column}{Latitude column in spatial_data name} +\item{latitude_column}{Latitude column name in spatial_data} \item{markers}{Markers to display on top of mesh. A named list with latitude, longitude and label names must be given. Expects longitude name to be longitude, latitude name to be latitude, label name to be label.} } \value{ -leaflet::leaflet +leaflet::leaflet with mesh and markers } \description{ Plot a mesh on a Leaflet map diff --git a/man/plot_priors_boxplot.Rd b/man/plot_priors_boxplot.Rd index e7ee38d..b1d9178 100644 --- a/man/plot_priors_boxplot.Rd +++ b/man/plot_priors_boxplot.Rd @@ -7,10 +7,10 @@ plot_priors_boxplot(data) } \arguments{ -\item{data}{} +\item{data}{A list of parsed model output from "parse_model_output" (a list of lists)} } \value{ -graphics::boxplot +graphics::boxplot of fitted values } \description{ Create boxplots from priors run data diff --git a/man/plot_priors_density.Rd b/man/plot_priors_density.Rd index c840ab5..8b82701 100644 --- a/man/plot_priors_density.Rd +++ b/man/plot_priors_density.Rd @@ -7,12 +7,12 @@ plot_priors_density(data, measurement_data) } \arguments{ -\item{data}{Parsed model outputs} +\item{data}{List of parsed model outputs from "parse_model_output" (a list of lists)} -\item{measurement_data}{Measurement data} +\item{measurement_data}{Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)} } \value{ -ggplot2::ggplot +ggplot2::ggplot of measurement density by value } \description{ Plot density function diff --git a/man/plot_timeseries.Rd b/man/plot_timeseries.Rd index 1c948b7..3cbb1a4 100644 --- a/man/plot_timeseries.Rd +++ b/man/plot_timeseries.Rd @@ -20,13 +20,13 @@ plot_timeseries( ) } \arguments{ -\item{data}{Data to plot} +\item{data}{Data to plot (data.frame with x-axis column a character convertible to Date)} -\item{x}{Name of column to plot on x-axis, should be datetime, will be converted to Dates using as.Date} +\item{x}{Name of column to plot on x-axis} \item{y}{Name of column to plot on y-axis} -\item{breaks}{Date break points} +\item{breaks}{Date break points, must be a sequence of dates} \item{x_label}{x-axis label} @@ -40,9 +40,9 @@ plot_timeseries( \item{vertical_x}{x-intercept for vertical line} -\item{x_lim}{Limits for x-axis continous scale, vector passed to scale_x_continuous} +\item{x_lim}{Limits for x-axis continuous scale, vector passed to scale_x_continuous} -\item{y_lim}{Limits for y-axis continuous scale, vector passed to scale_y_continous} +\item{y_lim}{Limits for y-axis continuous scale, vector passed to scale_y_continuous} \item{line_width}{Line width} } diff --git a/man/retrieve_tutorial_data.Rd b/man/retrieve_tutorial_data.Rd index 07c6d2a..d6006fb 100644 --- a/man/retrieve_tutorial_data.Rd +++ b/man/retrieve_tutorial_data.Rd @@ -2,15 +2,17 @@ % Please edit documentation in R/util_retrieve.R \name{retrieve_tutorial_data} \alias{retrieve_tutorial_data} -\title{Retrieve a tutorial dataset and unpacks it to ~/fdmr/tutorial_data} +\title{Retrieves a tutorial dataset and unpacks it to a place specified by the user (~/fdmr/tutorial_data)} \usage{ -retrieve_tutorial_data(dataset, force_update = FALSE) +retrieve_tutorial_data(dataset, force_update = FALSE, save = FALSE) } \arguments{ \item{dataset}{Name of dataset to retrieve} \item{force_update}{Force retrieval of metadata and dataset} + +\item{save}{Unpack the dataset to where user specified (character), home directory (TRUE), session's temporary directory (FALSE: default).} } \description{ -Retrieve a tutorial dataset and unpacks it to ~/fdmr/tutorial_data +Retrieves a tutorial dataset and unpacks it to a place specified by the user (~/fdmr/tutorial_data) } diff --git a/vignettes/expected_data_structure.Rmd b/vignettes/expected_data_structure.Rmd index 8a1f1ec..a0a6084 100644 --- a/vignettes/expected_data_structure.Rmd +++ b/vignettes/expected_data_structure.Rmd @@ -18,6 +18,7 @@ In this tutorial, we will show the expected data structure for running the Bayes In the [COVID-19 tutorial](https://4dmodeller.github.io/fdmr/articles/covid.html), we aim to fit a Bayesian spatio-temporal model to predict the COVID-19 infection rates across mainland England over space and time, and investigate the impacts of socioeconomic, demographic and environmental factors on COVID-19 infection. We load the dataset `covid19_data` and the type of this object is a `data.frame`. ```{r classcovidat} +fdmr::retrieve_tutorial_data(dataset = "covid") covid19_data <- fdmr::load_tutorial_data(dataset = "covid", filename = "covid19_data.rds") class(covid19_data) ``` diff --git a/vignettes/meshbuilder.Rmd b/vignettes/meshbuilder.Rmd index 7a02978..0b586d5 100644 --- a/vignettes/meshbuilder.Rmd +++ b/vignettes/meshbuilder.Rmd @@ -54,7 +54,7 @@ sp_data <- fdmr::load_tutorial_data(dataset = "covid", filename = "spatial_data. head(sp_data) ``` -The `sp_data` object is a `SpatialPolygonsDataFrame` containing 6789 features for areas of England. This object contains all the contains all the values we +The `sp_data` object is a `SpatialPolygonsDataFrame` containing 6789 features for areas of England. This object contains all the values we need to build a mesh. We can build a mesh by passing `sp_data` to the `mesh_builder` function. ```{r eval=FALSE}