-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtabGBIF.R
49 lines (45 loc) · 1.51 KB
/
tabGBIF.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#' @title GBIF Table
#'
#' @description Internal function--imports results from `occ_download_get()`
#' and processes them into a table for an `occCiteData` object.
#'
#' @param GBIFresults The results of a GBIF search that will be tabulated
#' into a common format for an occCite object.
#'
#' @param taxon A single species name, for tracing/error checking purposes
#' only.
#'
#' @return A list of lists containing \enumerate{ \item a data frame of
#' occurrence data \item GBIF search metadata for every GBIF download in
#' the specified directory.}
#'
#' @keywords internal
#'
#' @noRd
tabGBIF <- function(GBIFresults, taxon) {
occFromGBIF <- rgbif::occ_download_import(GBIFresults)
if (nrow(occFromGBIF) == 0) {
print(paste("Note: there are no GBIF points for ", taxon, ".", sep = ""))
return(NULL)
}
occFromGBIF <- data.frame(
occFromGBIF$gbifID, occFromGBIF$species,
occFromGBIF$decimalLongitude,
occFromGBIF$decimalLatitude,
occFromGBIF$day, occFromGBIF$month,
occFromGBIF$year, occFromGBIF$datasetName,
as.character(occFromGBIF$datasetKey)
)
dataService <- rep("GBIF", nrow(occFromGBIF))
occFromGBIF <- cbind(occFromGBIF, dataService)
# "Dataset" column excluded because not always filled out
## but useful for quick human checks
occFromGBIF <- occFromGBIF[stats::complete.cases(occFromGBIF[, -8]), ]
colnames(occFromGBIF) <- c(
"gbifID", "name", "longitude",
"latitude", "day", "month",
"year", "Dataset",
"DatasetKey", "DataService"
)
return(occFromGBIF)
}