Skip to content

Commit

Permalink
doc: use new sample dataset in example
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Sep 6, 2024
1 parent 76730ca commit 4197837
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 326 deletions.
12 changes: 6 additions & 6 deletions R/filter_by_bbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Filter by oceans ----
#' pump_data_sub <- filter_by_bbox(pump_data, bbox = c(35, 0, 45, 30))
#' net_data_sub <- filter_by_bbox(net_data, bbox = c(45, -61, 82, -24))
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)

filter_by_bbox <- function(data, bbox) {

Expand Down
12 changes: 6 additions & 6 deletions R/filter_by_month.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Filter by months ----
#' pump_data_sub <- filter_by_month(pump_data, months = 1:2)
#' net_data_sub <- filter_by_month(net_data, months = 1:2)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)

filter_by_month <- function(data, months) {

Expand Down
12 changes: 6 additions & 6 deletions R/filter_by_ocean.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Get ocean names ----
#' get_ocean_names()
#'
#' # Filter by oceans ----
#' pump_data_sub <- filter_by_ocean(pump_data, ocean = "Indian Ocean")
#' net_data_sub <- filter_by_ocean(net_data, ocean = "Indian Ocean")
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)

filter_by_ocean <- function(data, ocean) {

Expand Down
12 changes: 6 additions & 6 deletions R/filter_by_polygon.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Import Indian Ocean spatial polygons ----
#' file_name <- system.file(file.path("extdata", "IHO_Indian_ocean_polygon.gpkg"),
Expand All @@ -35,10 +35,10 @@
#' indian_ocean <- sf::st_read(file_name)
#'
#' # Filter by polygon ----
#' pump_data_sub <- filter_by_polygon(pump_data, polygon = indian_ocean)
#' net_data_sub <- filter_by_polygon(net_data, polygon = indian_ocean)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)

filter_by_polygon <- function(data, polygon) {

Expand Down
29 changes: 15 additions & 14 deletions R/filter_by_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@
#'
#' @examples
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Select a taxonomy ----
#' pump_data <- select_taxonomy(pump_data, taxonomy = "OT")
#' net_data <- select_taxonomy(net_data, taxonomy = "VT")
#'
#' # Select only required columns (and taxa) ----
#' pump_data <- select_columns(pump_data)
#' net_data <- select_columns(net_data)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Convert data into long format ----
#' pump_data <- reshape_data(pump_data)
#' net_data <- reshape_data(net_data)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Total number of species ----
#' length(unique(pump_data$"taxa"))
#' length(unique(net_data$"taxa"))
#'
#' # Select records for three species ----
#' pump_data_sub <- filter_by_species(data = pump_data,
#' species = c("g_inflata", "g_ruber",
#' "g_glutinata"))
#' net_data_sub <- filter_by_species(data = net_data,
#' species = c("g_inflata_VT",
#' "g_elongatus_VT",
#' "g_glutinata_VT"))
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)
#'
#' # Total number of species ----
#' length(unique(pump_data_sub$"taxa"))
#' length(unique(net_data_sub$"taxa"))

filter_by_species <- function(data, species, rm_na = FALSE) {

Expand Down
12 changes: 6 additions & 6 deletions R/filter_by_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Filter by years ----
#' pump_data_sub <- filter_by_year(pump_data, years = 1985)
#' net_data_sub <- filter_by_year(net_data, years = 1992)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data_sub)
#' dim(net_data_sub)

filter_by_year <- function(data, years) {

Expand Down
10 changes: 5 additions & 5 deletions R/ggmap_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Map data (default) ----
#' ggmap_data(pump_data)
#' ggmap_data(net_data)
#'
#' # Map data ----
#' ggmap_data(pump_data, col = "black", fill = "red", shape = 21, size = 2)
#' ggmap_data(net_data, col = "black", fill = "red", shape = 21, size = 2)

ggmap_data <- function(data, col = "red", ...) {

Expand Down
16 changes: 8 additions & 8 deletions R/select_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Select a taxonomy ----
#' pump_data <- select_taxonomy(pump_data, taxonomy = "OT")
#' net_data <- select_taxonomy(net_data, taxonomy = "VT")
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Select only required columns (and taxa) ----
#' pump_data <- select_columns(pump_data)
#' net_data <- select_columns(net_data)
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)

select_columns <- function(data, cols = NULL) {

Expand Down
14 changes: 7 additions & 7 deletions R/select_taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
#' library("forcis")
#'
#' # Import example dataset ----
#' file_name <- system.file(file.path("extdata", "FORCIS_pump_sample.csv"),
#' file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"),
#' package = "forcis")
#'
#' pump_data <- vroom::vroom(file_name, delim = ";", show_col_types = FALSE)
#' net_data <- read.table(file_name, dec = ".", sep = ";")
#'
#' # Add 'data_type' column ----
#' pump_data$"data_type" <- "Pump"
#' net_data$"data_type" <- "Net"
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)
#'
#' # Select a taxonomy ----
#' pump_data <- select_taxonomy(pump_data, taxonomy = "OT")
#' net_data <- select_taxonomy(net_data, taxonomy = "VT")
#'
#' # Dimensions of the data.frame ----
#' dim(pump_data)
#' dim(net_data)

select_taxonomy <- function(data, taxonomy) {

Expand Down Expand Up @@ -69,4 +69,4 @@ select_taxonomy <- function(data, taxonomy) {
}

data
}
}
Loading

0 comments on commit 4197837

Please sign in to comment.