Skip to content

Commit

Permalink
make rayshader, elevatr and fasstr suggests to the functions they are…
Browse files Browse the repository at this point in the history
… used in, adding checks within the function sto tell the user to install it if they don't have and remove from depends in Description to address #7
  • Loading branch information
NewGraphEnvironment committed Jun 27, 2024
1 parent 22436b6 commit 0a3b3cb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 14 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ Imports:
tidyselect,
fwapgr,
data.table,
elevatr,
raster,
rayshader,
readr,
stats,
generics,
Expand All @@ -45,13 +43,15 @@ Imports:
glue,
RPostgres,
rlang,
fasstr,
ggdark,
ggplot2,
tidyhydat,
cli
Remotes:
poissonconsulting/fwapgr,
Suggests:
rayshader,
elevatr,
fasstr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(fasstr,plot_data_screening)
importFrom(ggdark,dark_theme_bw)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_ribbon)
Expand Down
9 changes: 8 additions & 1 deletion R/fpr_create_hydrograph.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#' @importFrom lubridate year
#' @importFrom tidyhydat hy_daily_flows search_stn_number
#' @importFrom stringr str_to_title
#' @importFrom fasstr plot_data_screening
#' @importFrom ggdark dark_theme_bw
#' @importFrom dplyr mutate group_by summarise
#' @importFrom ggplot2 ggsave ggplot geom_ribbon scale_x_date labs geom_line scale_colour_manual
Expand All @@ -29,6 +28,14 @@ fpr_create_hydrograph <- function(
start_year = NULL,
end_year = NULL){

required_packages <- c("fasstr")

for (package in required_packages) {
if (!require(package, character.only = TRUE)) {
cli::abort(paste("Package", package, "is not installed. Please install it using install.packages(\"", package, "\").", sep = ""))
}
}

if(is.null(station)){
cli::cli_abort('Please provide a station number, for example "08EE004"')
}
Expand Down
23 changes: 19 additions & 4 deletions R/spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' in the fish_passage_skeena_2021_reporting repo for now.
#'
#' @param dat Dataframe or tibble which usually only has one row
#' @family spatial
#'
#' @return html object
#' @export
Expand All @@ -27,7 +28,7 @@ fpr_make_html_tbl <- function(dat) {
}


#' Retrieve watershed geometry using fwapg
#' Retrieve watershed geometry using fwapgr
#'
#' @param dat Dataframe with a stream_crossing_id, blue_line_key and downstream_route_measure defined. Ususally pulled from bcfishpass
#'
Expand All @@ -47,15 +48,29 @@ fpr_sp_watershed <- function(dat){
sf::st_as_sf()
}

#' Get elevation statistics
#' Get elevation statistics.
#'
#' @param dat sf object of polygons to gather elevation statistics for. Must contain `stream_crossing_id` column.
#'
#' @return sf object of polygons with elevation details (ie. p60, median, min, max) and median aspect information added.
#' @family spatial
#' @export
#'
#' @examples
#' @examples \dontrun{wshd <- fpr_sp_wshd_stats(
#' fwapgr::fwa_watershed_at_measure(
#' blue_line_key = 360746095, downstream_route_measure = 100) |>
#' dplyr::mutate(stream_crossing_id = 1)
#' )}
fpr_sp_wshd_stats <- function(dat){

required_packages <- c("elevatr", "rayshader")

for (package in required_packages) {
if (!require(package, character.only = TRUE)) {
cli::abort(paste("Package", package, "is not installed. Please install it using install.packages(\"", package, "\").", sep = ""))
}
}

directions <- tibble::tibble( degree_centre = seq(0, 360 , by=22.5),
cardinal = c("N","NNE","NE", "ENE", "E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N")) %>%
Expand Down Expand Up @@ -106,7 +121,7 @@ fpr_sp_wshd_stats <- function(dat){
arrange(stream_crossing_id)
}

#' Make geopackage in directory called
#' Make geopackage from an sf object. Create directory to burn it to if it doesn't exist.
#'
#' Names the layer the same as the name of the dataframe that is burned
#'
Expand Down
2 changes: 1 addition & 1 deletion man/fpr_make_geopackage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/fpr_make_html_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/fpr_sp_watershed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions man/fpr_sp_wshd_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a3b3cb

Please sign in to comment.