Skip to content

Commit d5c051f

Browse files
committed
Renamed locality columns to "first", "second", and "third"
1 parent cc17531 commit d5c051f

File tree

10 files changed

+77
-76
lines changed

10 files changed

+77
-76
lines changed

R/find_areas.R

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' @param occs The dataframe that is returned by `ssarp::find_land()`. If using
2323
#' a custom occurrence record dataframe, ensure that it has the following
2424
#' columns: "genericName", "specificEpithet",
25-
#' "decimalLongitude", "decimalLatitude", "First", "Second", "Third",
25+
#' "decimalLongitude", "decimalLatitude", "first", "second", "third",
2626
#' "datasetKey". The "datasetKey" column is important for GBIF records and
2727
#' identifies the dataset to which the occurrence record belongs. Custom
2828
#' dataframes without this style of data organization should fill the column
@@ -65,9 +65,9 @@ find_areas <- function(
6565
c(
6666
"genericName",
6767
"specificEpithet",
68-
"First",
69-
"Second",
70-
"Third",
68+
"first",
69+
"second",
70+
"third",
7171
"datasetKey"
7272
),
7373
names(occs)
@@ -89,9 +89,9 @@ find_areas <- function(
8989
# Ensure other columns are correct type
9090
checkmate::assertCharacter(occs$genericName)
9191
checkmate::assertCharacter(occs$specificEpithet)
92-
checkmate::assertCharacter(occs$First)
93-
checkmate::assertCharacter(occs$Second)
94-
checkmate::assertCharacter(occs$Third)
92+
checkmate::assertCharacter(occs$first)
93+
checkmate::assertCharacter(occs$second)
94+
checkmate::assertCharacter(occs$third)
9595
# Not checking datasetKey because it is not relevant to the code and can be
9696
# any type, really
9797

@@ -100,7 +100,7 @@ find_areas <- function(
100100
# Remove any rows where the "specificEpithet" column is NA
101101
occs <- occs[!is.na(occs$specificEpithet), ]
102102

103-
# Remove rows where First, Second, and Third are all NA
103+
# Remove rows where first, second, and third are all NA
104104
# Create vector to hold row numbers
105105
minus <- rep(NA, nrow(occs))
106106
# Loop through dataframe
@@ -112,9 +112,9 @@ find_areas <- function(
112112
break
113113
}
114114
if (
115-
is.na(occs[i, "Third"]) &&
116-
is.na(occs[i, "Second"]) &&
117-
is.na(occs[i, "First"])
115+
is.na(occs[i, "third"]) &&
116+
is.na(occs[i, "second"]) &&
117+
is.na(occs[i, "first"])
118118
) {
119119
minus[i] <- i
120120
}
@@ -139,9 +139,10 @@ find_areas <- function(
139139
# First, create an empty list of island names
140140
islands <- list()
141141

142-
# Next, go through the occs dataframe and see if the Third column has a name.
143-
# If yes, add to the island list. If NA, go to the Second column.
144-
# If Second column is NA, go to the First column.
142+
# Next, go through the occs dataframe and see if the 'third' column
143+
# has a name.
144+
# If yes, add to the island list. If NA, go to the 'second' column.
145+
# If 'second' column is NA, go to the 'first' column.
145146
if (!getOption("ssarp.silent", FALSE)) {
146147
cli::cli_alert_info("Recording island names...")
147148
}
@@ -152,12 +153,12 @@ find_areas <- function(
152153
}
153154
break
154155
}
155-
if (!is.na(occs[i, "Third"])) {
156-
islands[i] <- occs[i, "Third"]
157-
} else if (!is.na(occs[i, "Second"])) {
158-
islands[i] <- occs[i, "Second"]
159-
} else if (!is.na(occs[i, "First"])) {
160-
islands[i] <- occs[i, "First"]
156+
if (!is.na(occs[i, "third"])) {
157+
islands[i] <- occs[i, "third"]
158+
} else if (!is.na(occs[i, "second"])) {
159+
islands[i] <- occs[i, "second"]
160+
} else if (!is.na(occs[i, "first"])) {
161+
islands[i] <- occs[i, "first"]
161162
}
162163
}
163164

@@ -230,16 +231,16 @@ find_areas <- function(
230231
areas <- rep(0, times = nrow(occs))
231232

232233
for (i in seq_len(nrow(occs))) {
233-
if (!is.na(occs[i, "Third"]) && island_dict$has(occs[i, "Third"])) {
234-
areas[i] <- island_dict$get(occs[i, "Third"])
234+
if (!is.na(occs[i, "third"]) && island_dict$has(occs[i, "third"])) {
235+
areas[i] <- island_dict$get(occs[i, "third"])
235236
} else if (
236-
!is.na(occs[i, "Second"]) && island_dict$has(occs[i, "Second"])
237+
!is.na(occs[i, "second"]) && island_dict$has(occs[i, "second"])
237238
) {
238-
areas[i] <- island_dict$get(occs[i, "Second"])
239+
areas[i] <- island_dict$get(occs[i, "second"])
239240
} else if (
240-
!is.na(occs[i, "First"]) && island_dict$has(occs[i, "First"])
241+
!is.na(occs[i, "first"]) && island_dict$has(occs[i, "first"])
241242
) {
242-
areas[i] <- island_dict$get(occs[i, "First"])
243+
areas[i] <- island_dict$get(occs[i, "first"])
243244
} else {
244245
areas[i] <- NA
245246
}

R/find_land.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#' standard location for island names in its returned information, so using it
1616
#' will likely require the returned dataframe to be cleaned by the user.
1717
#' @return A dataframe of the species name, longitude, latitude, and three parts
18-
#' of occurrence information. "First" is the name used to describe the largest
19-
#' possible area of land where the occurrence point is found. "Second" is the
18+
#' of occurrence information. "first" is the name used to describe the largest
19+
#' possible area of land where the occurrence point is found. "second" is the
2020
#' name used to describe the second-largest possible area of land that
21-
#' corresponds with the occurrence point. "Third" is the most specific area of
21+
#' corresponds with the occurrence point. "third" is the most specific area of
2222
#' land that corresponds with the occurrence point. Functions later in the ssarp
23-
#' pipeline default to checking whether "Third" has an entry, then look at
24-
#' "Second," and then "First."
23+
#' pipeline default to checking whether "third" has an entry, then look at
24+
#' "second," and then "first."
2525
#' @examples
2626
#' # The GBIF key for the Anolis genus is 8782549
2727
#' # Read in example dataset filtered from:
@@ -101,17 +101,17 @@ find_land <- function(occurrences, fillgaps = FALSE) {
101101
# But sometimes there are three...
102102
suppressWarnings(
103103
occs <- occs |>
104-
tidyr::separate(where2, c("First", "Second", "Third"), sep = ":")
104+
tidyr::separate(where2, c("first", "second", "third"), sep = ":")
105105
)
106106
colnames(occs) <- c(
107107
"acceptedScientificName",
108108
"genericName",
109109
"specificEpithet",
110110
"decimalLongitude",
111111
"decimalLatitude",
112-
"First",
113-
"Second",
114-
"Third",
112+
"first",
113+
"second",
114+
"third",
115115
"datasetKey"
116116
)
117117

@@ -128,7 +128,7 @@ find_land <- function(occurrences, fillgaps = FALSE) {
128128
}
129129
break
130130
}
131-
if (is.na(occs[i, "First"])) {
131+
if (is.na(occs[i, "first"])) {
132132
# Get lon and lat
133133
longitude <- occs[i, "decimalLongitude"]
134134
latitude <- occs[i, "decimalLatitude"]

R/find_pam_areas.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ find_pam_areas <- function(pam, area_custom = NULL) {
7777
# Fix colnames
7878
colnames(sp_df) <- c("genericName", "specificEpithet")
7979

80-
# Add island to dataframe (call it "Third" for ssarp::find_areas())
81-
sp_df$Third <- island
80+
# Add island to dataframe (call it "third" for ssarp::find_areas())
81+
sp_df$third <- island
8282

8383
# Add this small dataframe to the list
8484
dat[[length(dat) + 1]] <- sp_df
@@ -88,12 +88,12 @@ find_pam_areas <- function(pam, area_custom = NULL) {
8888
# Turn dat into a dataframe
8989
occs <- do.call(rbind.data.frame, dat)
9090

91-
# Add "First" and "Second" columns so it can be used with ssarp::find_areas()
92-
occs$First <- NA
93-
occs$Second <- NA
91+
# Add "first" and "second" columns so it can be used with ssarp::find_areas()
92+
occs$first <- NA
93+
occs$second <- NA
9494
# They also need to be characters
95-
occs$First <- as.character(occs$First)
96-
occs$Second <- as.character(occs$Second)
95+
occs$first <- as.character(occs$first)
96+
occs$second <- as.character(occs$second)
9797

9898
return(find_areas(occs, area_custom))
9999
}

R/get_presence_absence.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#' - "areas" containing the areas associated with the land masses of interest
99
#' - "specificEpithet" containing the names of the species living on those
1010
#' islands
11-
#' - "First" containing locality information. In the ssarp workflow, this
11+
#' - "first" containing locality information. In the ssarp workflow, this
1212
#' column contains the country name
13-
#' - "Second" containing locality information. In the ssarp workflow, this
13+
#' - "second" containing locality information. In the ssarp workflow, this
1414
#' column contains a province or island name
15-
#' - "Third" containing locality information. In the ssarp workflow, this
15+
#' - "third" containing locality information. In the ssarp workflow, this
1616
#' column contains the island name if the 7th column does not contain the
1717
#' island name
1818
#' @return A dataframe with a row for each island in the given occurrence
@@ -39,15 +39,15 @@ get_presence_absence <- function(occs) {
3939
# Checkmate input validation
4040
checkmate::assertDataFrame(occs)
4141
checkmate::testSubset(
42-
c("specificEpithet", "areas", "First", "Second", "Third"),
42+
c("specificEpithet", "areas", "first", "second", "third"),
4343
names(occs)
4444
)
4545
# Ensure columns are correct type
4646
checkmate::assertCharacter(occs$specificEpithet)
4747
checkmate::assertNumeric(occs$areas)
48-
checkmate::assertCharacter(occs$First)
49-
checkmate::assertCharacter(occs$Second)
50-
checkmate::assertCharacter(occs$Third)
48+
checkmate::assertCharacter(occs$first)
49+
checkmate::assertCharacter(occs$second)
50+
checkmate::assertCharacter(occs$third)
5151

5252
# Create a dataframe that counts how many records there are for each species
5353
# in each island
@@ -78,7 +78,7 @@ get_presence_absence <- function(occs) {
7878
area_names,
7979
occs[
8080
which(occs$areas == new_occs[i, 1])[1],
81-
c("First", "Second", "Third")
81+
c("first", "second", "third")
8282
]
8383
)
8484
}
@@ -87,7 +87,7 @@ get_presence_absence <- function(occs) {
8787
final_occs <- cbind(area_names, new_occs)
8888

8989
# Rownames won't make sense, so reset them to 1 to n
90-
rownames(final_occs) <- c(1:length(final_occs$First))
90+
rownames(final_occs) <- c(1:length(final_occs$first))
9191

9292
return(final_occs)
9393
}

inst/extdata/SSARP_Example_Dat.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
acceptedScientificName,genericName,specificEpithet,decimalLongitude,decimalLatitude,First,Second,Third,datasetKey,areas
1+
acceptedScientificName,genericName,specificEpithet,decimalLongitude,decimalLatitude,first,second,third,datasetKey,areas
22
"Anolis ahli Barbour, 1925",Anolis,ahli,-80.072502,21.984518,Cuba,NA,NA,50c9509d-22c7-4a22-a47d-8c48425ef4a7,1.22E+11
33
"Anolis alayoni Estrada & Hedges, 1995",Anolis,alayoni,-74.626318,20.412664,Cuba,NA,NA,50c9509d-22c7-4a22-a47d-8c48425ef4a7,1.22E+11
44
"Anolis aliniger Mertens, 1939",Anolis,aliniger,-70.590035,19.104985,Dominican Republic,NA,NA,50c9509d-22c7-4a22-a47d-8c48425ef4a7,83104562500

man/find_areas.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/find_land.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_presence_absence.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-find_areas.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Create test dataframe for find_areas occs input
22
occs <- as.data.frame(matrix(ncol = 9, nrow = 2))
33
colnames(occs) <- c("acceptedScientificName", "genericName", "specificEpithet",
4-
"decimalLongitude", "decimalLatitude", "First",
5-
"Second", "Third", "datasetKey")
4+
"decimalLongitude", "decimalLatitude", "first",
5+
"second", "third", "datasetKey")
66

77
# Test dataframe for find_areas occs input with values
88
occs_vals <- occs
@@ -20,8 +20,8 @@ colnames(custom_area) <- c("Name", "AREA")
2020
# Test matrix for find_areas occs input
2121
occ_mat <- matrix(ncol = 9, nrow = 2)
2222
colnames(occs) <- c("acceptedScientificName", "genericName", "specificEpithet",
23-
"decimalLongitude", "decimalLatitude", "First",
24-
"Second", "Third", "datasetKey")
23+
"decimalLongitude", "decimalLatitude", "first",
24+
"second", "third", "datasetKey")
2525
occ_mat[1,] <- c("Anolis first", "Anolis", "first", -81.948509, 28.028463,
2626
"USA", "Florida", "Lakeland", 1)
2727
occ_mat[2,] <- c("Anolis second", "Anolis", "second", -81.949353, 28.028047,
@@ -44,9 +44,9 @@ occ_types$genericName <- as.factor(occ_types$genericName)
4444
occ_types$specificEpithet <- as.factor(occ_types$specificEpithet)
4545
occ_types$decimalLongitude <- as.character(occ_types$decimalLongitude)
4646
occ_types$decimalLatitude <- as.character(occ_types$decimalLatitude)
47-
occ_types$First <- as.factor(occ_types$First)
48-
occ_types$Second <- as.factor(occ_types$Second)
49-
occ_types$Third <- as.factor(occ_types$Third)
47+
occ_types$first <- as.factor(occ_types$first)
48+
occ_types$second <- as.factor(occ_types$second)
49+
occ_types$third <- as.factor(occ_types$third)
5050

5151
### Spatial inputs ###
5252
# Create test SpatVector with WKT polygon

tests/testthat/test-get_presence_absence.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Create test dataframe for occs input
22
occs <- as.data.frame(matrix(ncol = 10, nrow = 2))
33
colnames(occs) <- c("acceptedScientificName", "genericName", "specificEpithet",
4-
"decimalLongitude", "decimalLatitude", "First",
5-
"Second", "Third", "datasetKey", "areas")
4+
"decimalLongitude", "decimalLatitude", "first",
5+
"second", "third", "datasetKey", "areas")
66

77
# Test dataframe for find_areas occs input with values
88
occs_vals <- occs
@@ -17,8 +17,8 @@ occs_vals[,10] <- as.numeric(occs_vals[,10])
1717
# Test matrix for occs input
1818
occ_mat <- matrix(ncol = 10, nrow = 2)
1919
colnames(occs) <- c("acceptedScientificName", "genericName", "specificEpithet",
20-
"decimalLongitude", "decimalLatitude", "First",
21-
"Second", "Third", "datasetKey", "areas")
20+
"decimalLongitude", "decimalLatitude", "first",
21+
"second", "third", "datasetKey", "areas")
2222
occ_mat[1,] <- c("Anolis first_sp", "Anolis", "first_sp", -81.948509,
2323
28.028463, "USA", "Florida", "Lakeland", 1, 100)
2424
occ_mat[2,] <- c("Anolis second_sp", "Anolis", "second_sp", -81.949353,
@@ -32,9 +32,9 @@ colnames(occ_name) <- c(1:10)
3232
occ_types <- occs_vals
3333
occ_types$specificEpithet <- as.factor(occ_types$specificEpithet)
3434
occ_types$areas <- as.character(occ_types$areas)
35-
occ_types$First <- as.factor(occ_types$First)
36-
occ_types$Second <- as.factor(occ_types$Second)
37-
occ_types$Third <- as.factor(occ_types$Third)
35+
occ_types$first <- as.factor(occ_types$first)
36+
occ_types$second <- as.factor(occ_types$second)
37+
occ_types$third <- as.factor(occ_types$third)
3838

3939
########
4040
test_that("Inputting a matrix instead of a dataframe for occurrence records

0 commit comments

Comments
 (0)