library(rredlist)
library(tidyverse)

To access all data provided by this package, the user must to have an key. This token can be requested here.

As the download function only allows data to be downloaded by threat category, we will download them all and then filter for the species for which we have data.

DD<-rl_sp_category("DD", key=k)$result
DD$category<-"DD"
LC<-rl_sp_category("LC", key=k)$result
LC$category<-"LC"
NT<-rl_sp_category("NT", key=k)$result
NT$category<-"NT"
VU<-rl_sp_category("VU", key=k)$result
VU$category<-"VU"
EN<-rl_sp_category("EN", key=k)$result
EN$category<-"EN"
CR<-rl_sp_category("CR", key=k)$result
CR$category<-"CR"
EW<-rl_sp_category("EW", key=k)$result
EW$category<-"EW"
EX<-rl_sp_category("EX", key=k)$result
EX$category<-"EX"
LRlc<-rl_sp_category("LRlc", key=k)$result
LRlc$category<-"LRlc"
LRnt<-rl_sp_category("LRnt", key=k)$result
LRnt$category<-"LRnt"
LRcd<-rl_sp_category("LRcd", key=k)$result
LRcd$category<-"LRcd"

category<- rbind(DD, LC, NT, VU, EN, CR, EW, EX, LRlc, LRnt, LRcd)
any(duplicated(category$scientific_name)) 
write.csv(category, "category_IUCN.csv")

Now, let’s open our main trait tables to combine the threatened category data:

spp<-read.csv("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/Data/COMBINE_trait_data_imputed.csv")

#cleaning the category data:
category<-select(category,scientific_name, category)

Cleaning the category data

category<-select(category, scientific_name, category)

Merging and saving the data:

m<-merge(spp, category, by.x="iucn2020_binomial", by.y="scientific_name", all.x = T)

write.csv(m, "traits_category.csv")