Skip to content

Commit 0128566

Browse files
committed
Documentation fixes, removed unnecessary functions
Functions removed: get_data(), get_key(), quick_create_SAR()
1 parent 672a75f commit 0128566

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+167
-487
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Imports:
1717
mapdata,
1818
maps,
1919
reshape2,
20-
rgbif,
2120
segmented,
2221
stringi,
2322
tidyr
@@ -32,5 +31,6 @@ Depends:
3231
Suggests:
3332
testthat (>= 3.0.0),
3433
rmarkdown,
35-
knitr (>= 1.46)
34+
knitr (>= 1.46),
35+
rgbif
3636
Config/testthat/edition: 3

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ export(estimate_DR)
99
export(estimate_MS)
1010
export(find_areas)
1111
export(find_land)
12-
export(get_data)
1312
export(get_island_areas)
14-
export(get_key)
1513
export(get_presence_absence)
1614
export(get_sources)
17-
export(quick_create_SAR)
1815
export(remove_continents)
1916
import(mapdata)
2017
import(maps)

R/create_SAR.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#' Use segmented regression to create a species-area relationship (SAR) plot.
44
#' The X axis represents log(island area) and the Y axis represents log(number
55
#' of species)
6-
#' @param occurrences The dataframe output by `SSARP::find_areas()` (or if using
7-
#' a custom dataframe, ensure that it has the following columns: Species, areas)
6+
#' @param occurrences The dataframe output by `SSARP::find_areas()` (or if
7+
#' using a custom dataframe, ensure that it has the following columns:
8+
#' specificEpithet, areas)
89
#' @param npsi The maximum number of breakpoints to estimate for model
910
#' selection. Default: 1
1011
#' @return A list of 3 including: the summary output, the segmented regression
@@ -29,6 +30,10 @@ create_SAR <- function(occurrences, npsi = 1) {
2930
# Checkmate input validation
3031
checkmate::assertDataFrame(occurrences)
3132
checkmate::assertNumeric(npsi)
33+
checkmate::testSubset(c("specificEpithet", "areas"), names(occurrences))
34+
# Ensure columns are correct type
35+
checkmate::assertCharacter(occurrences$specificEpithet)
36+
checkmate::assertNumeric(occurrences$areas)
3237

3338
# formula Species ~ Area means to group scientific names by area
3439
# function(x) length(unique(x)) tells it to give me the number of unique

R/create_SpAR.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ create_SpAR <- function(occurrences, npsi = 1) {
2929
# Checkmate input validation
3030
checkmate::assertDataFrame(occurrences)
3131
checkmate::assertNumeric(npsi)
32+
checkmate::testSubset(c("areas", "rate"), names(occurrences))
33+
# Ensure columns are correct type
34+
checkmate::assertNumeric(occurrences$areas)
35+
checkmate::assertNumeric(occurrences$rate)
3236

3337
# The purpose of this function is to create either a linear or segmented
3438
# regression to visualize the relationship between speciation rate and

R/estimate_BAMM.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' returned occurrence dataframe.
1212
#' @param occurrences The occurrence record dataframe output from the SSARP
1313
#' pipeline. If you would like to use a custom dataframe, please make sure that
14-
#' there are columns titled "Genus" and "Species"
14+
#' there are columns titled "genericName" and "specificEpithet"
1515
#' @param edata The eventdata object created by using the
1616
#' `BAMMtools::getEventData()` function
1717
#' @return A dataframe that includes speciation rates for each species in the
@@ -51,6 +51,10 @@ estimate_BAMM <- function(label_type = "binomial", occurrences, edata) {
5151
# Checkmate input validation
5252
checkmate::assertString(label_type)
5353
checkmate::assertDataFrame(occurrences)
54+
checkmate::testSubset(c("specificEpithet", "genericName"), names(occurrences))
55+
# Ensure columns are correct type
56+
checkmate::assertCharacter(occurrences$specificEpithet)
57+
checkmate::assertCharacter(occurrences$genericName)
5458

5559
# Create a named number vector of speciation rates
5660
speciation_rates <- edata$meanTipLambda

R/find_areas.R

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
#' masses relevant to the taxon of interest.
55
#' @param occs The dataframe that is returned by `SSARP::find_land()`. If using
66
#' a custom occurrence record dataframe, ensure that it has the following
7-
#' columns in order: "SpeciesName", "Genus", "Species", "Longitude", "Latitude",
8-
#' "First", "Second", "Third", "datasetKey". The "datasetKey" column is
9-
#' important for GBIF records and identifies the dataset to which the occurrence
10-
#' record belongs. Custom dataframes without this style of data organization
11-
#' should fill the column with placeholder values.
7+
#' columns: "acceptedScientificName", "genericName", "specificEpithet",
8+
#' "decimalLongitude", "decimalLatitude", "First", "Second", "Third",
9+
#' "datasetKey". The "datasetKey" column is important for GBIF records and
10+
#' identifies the dataset to which the occurrence record belongs. Custom
11+
#' dataframes without this style of data organization should fill the column
12+
#' with placeholder values.
1213
#' @param area_custom A dataframe including names of land masses and their
1314
#' associated areas. This dataframe should be provided when the user would like
1415
#' to bypass using the built-in database of island names and areas. Please
@@ -41,7 +42,7 @@ find_areas <- function(occs, area_custom = NULL) {
4142
cli::cli_alert_warning("No data in occurrence record dataframe")
4243
break
4344
}
44-
if(is.na(occs[i,8]) && is.na(occs[i,7]) && is.na(occs[i,6])) {
45+
if(is.na(occs[i,"Third"]) && is.na(occs[i,"Second"]) && is.na(occs[i,"First"])) {
4546
minus[i] <- i
4647
}
4748
}
@@ -74,12 +75,12 @@ find_areas <- function(occs, area_custom = NULL) {
7475
cli::cli_alert_warning("No data in occurrence record dataframe")
7576
break
7677
}
77-
if(!is.na(occs[i,8])) {
78-
islands[i] <- occs[i,8]
79-
} else if (!is.na(occs[i,7])){
80-
islands[i] <- occs[i,7]
81-
} else if (!is.na(occs[i,6])){
82-
islands[i] <- occs[i,6]
78+
if(!is.na(occs[i,"Third"])) {
79+
islands[i] <- occs[i,"Third"]
80+
} else if (!is.na(occs[i,"Second"])){
81+
islands[i] <- occs[i,"Second"]
82+
} else if (!is.na(occs[i,"First"])){
83+
islands[i] <- occs[i,"First"]
8384
}
8485
}
8586

@@ -141,12 +142,12 @@ find_areas <- function(occs, area_custom = NULL) {
141142

142143
for(i in seq_len(nrow(occs))) {
143144

144-
if(!is.na(occs[i,8]) && island_dict$has(occs[i,8])){
145-
areas[i] <- island_dict$get(occs[i,8])
146-
} else if(!is.na(occs[i,7]) && island_dict$has(occs[i,7])){
147-
areas[i] <- island_dict$get(occs[i,7])
148-
} else if(!is.na(occs[i,6]) && island_dict$has(occs[i,6])){
149-
areas[i] <- island_dict$get(occs[i,6])
145+
if(!is.na(occs[i,"Third"]) && island_dict$has(occs[i,"Third"])){
146+
areas[i] <- island_dict$get(occs[i,"Third"])
147+
} else if(!is.na(occs[i,"Second"]) && island_dict$has(occs[i,"Second"])){
148+
areas[i] <- island_dict$get(occs[i,"Second"])
149+
} else if(!is.na(occs[i,"First"]) && island_dict$has(occs[i,"First"])){
150+
areas[i] <- island_dict$get(occs[i,"First"])
150151
} else {
151152
areas[i] <- NA
152153
}

R/find_land.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ find_land <- function(occurrences, fillgaps = FALSE) {
9595
cli::cli_alert_warning("Occurrence record dataframe has no entries")
9696
break
9797
}
98-
if(is.na(occs[i,6])){
98+
if(is.na(occs[i,"First"])){
9999
# Get lon and lat
100-
longitude <- occs[i,4]
101-
latitude <- occs[i,5]
100+
longitude <- occs[i,"decimalLongitude"]
101+
latitude <- occs[i,"decimalLatitude"]
102102

103103
# Create Photon URL
104104
url <- paste0("http://photon.komoot.io/reverse?lon=",

R/get_data.R

Lines changed: 0 additions & 56 deletions
This file was deleted.

R/get_key.R

Lines changed: 0 additions & 42 deletions
This file was deleted.

R/get_presence_absence.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
#' custom dataframe, ensure that it has the following named columns:
88
#' - "areas" containing the areas associated with the land masses of interest
99
#' - "Species" containing the names of the species living on those islands
10-
#' - A 6th column containing locality information. In the SSARP workflow, this
11-
#' column is called "First" and contains the country name
12-
#' - A 7th column containing locality information. In the SSARP workflow, this
13-
#' column is called "Second" and contains a province or island name
14-
#' - An 8th column containing locality information. In the SSARP workflow, this
15-
#' column is called "Third" and contains the island name if the 7th column does
16-
#' not contain the island name
10+
#' - "First" containing locality information. In the SSARP workflow, this
11+
#' column contains the country name
12+
#' - "Second" containing locality information. In the SSARP workflow, this
13+
#' column contains a province or island name
14+
#' - "Third" containing locality information. In the SSARP workflow, this
15+
#' column contains the island name if the 7th column does not contain the
16+
#' island name
1717
#' @return A dataframe with a row for each island in the given occurrence
1818
#' record dataframe and a column for each species. Within each species column,
1919
#' a 1 represents the presence of that species on the island corresponding to
@@ -59,7 +59,7 @@ get_presence_absence <- function(occs) {
5959

6060
# Pick the first occurrence of the ith area to get the name
6161
area_names <- rbind(area_names, occs[which(occs$areas == new_occs[i,1])[1],
62-
c(6:8)])
62+
c("First", "Second", "Third")])
6363
}
6464

6565
# Now cbind area_names to new_occs

0 commit comments

Comments
 (0)