forked from danief/eppo_db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEPPO_GBIF_taxonomy.R
41 lines (26 loc) · 1.27 KB
/
EPPO_GBIF_taxonomy.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
# EPPO DB - GBIF Taxonomic
library(tidyverse)
library(DBI)
library(RSQLite)
# script to get gbif taxonomic ids for EPPO species in the EPPO database
eppo_con <- dbConnect(SQLite(), dbname = "C:/Users/dafl/Desktop/EPPO DB/EPPO_DB.db")
con <- dbConnect(SQLite(), dbname = db_file)
db_data <- tbl(eppo_con, "EPPO") %>%
collect()
db_data <-db_data %>%
filter(codelang=="la") %>%
select(fullname) %>%
distinct()
db_data <- db_data %>% filter(!fullname=="null") %>% na.omit()
db_data$fullname <- str_replace_all(db_data$fullname, "[[:punct:]]", "")
eppo_tax <- db_data$fullname %>%
taxize::get_gbifid_(method="backbone") %>% # match names to the GBIF backbone to get taxonkeys
purrr::imap(~ .x %>% mutate(original_sciname = .y)) %>% # add original name back into data.frame
bind_rows()
as_tibble(eppo_tax)
# -----------------------------------------------------------------------------------------------------------------------------------------------
# write to db
db_file <- "C:/Users/dafl/Desktop/EPPO DB/EPPO_DB.db"
con <- dbConnect(SQLite(), dbname = db_file)
dbWriteTable(con, "EPPO_GBIF_TAX", eppo_tax, append = TRUE)
# END --------------------------------------------------------------------------------------------------------------------------------------------