## fdex database pull ## # Request only what you need, transport only what is necessary, and cache what you can. # fdex_db_pull.R v1.0 # 02 April 2026 rm(list=ls()) library(data.table) library(jsonlite) library(RCurl) #update_date <- Sys.Date() t <- Sys.time() theDate <- strftime(t,"%d_%b_%Y") alphabet_vector <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") ################################### ############ FUNCTIONS ############ ################################### fd_api_base_url <- "https://fdex.org/services/api/query.php?qText=" get_fd_record <- function(theEndpoint, queryText){ url <- paste0(fd_api_base_url, queryText, "&qField=", theEndpoint) tryCatch({ response <- getURL(url) response <- fromJSON(response) }, error = function(e) NULL) } ################################### ########### CODE BLOCK ############ ################################### the_colnames <- c("taxon", "authors", "mbNumber", "otherID", "rank", "rankCode", "taxonomicStatus", "currentTaxon", "currentMbNumber", "currentOtherID", "currentStatus", "parentTaxon", "parentMbNumber", "parentOtherID", "recordSource", "taxonomicAgreement") fdex_data_frame <- data.frame("taxon", "authors", "mbNumber", "otherID", "rank", "rankCode", "taxonomicStatus", "currentTaxon", "currentMbNumber", "currentOtherID", "currentStatus", "parentTaxon", "parentMbNumber", "parentOtherID", "recordSource", "taxonomicAgreement") colnames(fdex_data_frame) <- the_colnames fdex_data_frame <- fdex_data_frame[-1,] for(i in 1:length(alphabet_vector)){ for(j in 1:length(alphabet_vector)){ first_letter <- toupper(alphabet_vector[i]) second_letter <- alphabet_vector[j] combined_letters <- paste0(first_letter, second_letter) print(paste0("Processing genera starting : '", combined_letters, "' for i = ", i, " and j = ", j)) fdex_data <- get_fd_record("taxon", paste0(first_letter, second_letter, "%25")) fdex_data_frame <- rbind(fdex_data_frame, as.data.frame(fdex_data)) } } fdex_data_frame <- subset(fdex_data_frame, fdex_data_frame$recordSource == "Index Fungorum") #fdex_data_frame <- subset(fdex_data_frame, fdex_data_frame$recordSource == "MycoBank") dt <- setDT(fdex_data_frame) fwrite(dt, paste0(theDate, "_fdex_db.csv"))