-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoin_bee_plant_list_with_valid_names.R
65 lines (54 loc) · 1.71 KB
/
join_bee_plant_list_with_valid_names.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This script simplifies the integration of bee-plant interaction details by
# combining them with a validated plant checklist. It creates individual files
# for each bee species, utilizing the naming format `{sp_code}_valid.csv`.
# Prior execution of the `create_plant_checklist_w_countries.R` script is a
# prerequisite for the expected functionality.
library(tidyverse)
config <- config::get()
DATA_FOLDER <- config$data_folder
PLANT_CHECKLIST <- config$reviewed_plant_checklist
#Cargar listado de plantas#
Plantas <- readxl::read_xlsx(PLANT_CHECKLIST)
#Extraemos columnas de interés#
Plantas2 <- Plantas %>%
select(
searched_taxon_name,
target_taxon_name,
country_name,
`Estatus Taxonómico`,
`Nombre Válido`,
Autoridad,
`Rango Taxonómico`,
Familia,
`Forma biológica`
)
#Cargamos plantas por abeja en un data frame#
files <- fs::dir_ls(path = DATA_FOLDER, glob="*_list.csv")
lista <- files %>%
map(read_csv)
lista_w_valid_names <- lista %>%
map(\(df) left_join(df, Plantas2, by="target_taxon_name"))
variables <- c(
"source_taxon_name",
"latitude",
"longitude",
"ISO_A2",
"NAME_ES",
"searched_taxon_name",
"target_taxon_name",
"country_name",
"Estatus Taxonómico",
"Nombre Válido",
"Autoridad",
"Rango Taxonómico",
"Familia",
"Forma biológica"
)
lista_w_valid_names <- lista_w_valid_names %>%
map(\(df) select(df, any_of(variables)))
# Add bee code as name in list
names(lista_w_valid_names) <- names(lista_w_valid_names) %>%
str_extract("([:upper:]+)_list.csv$", group = 1)
lista_w_valid_names %>%
imap(\(df, sp_code) write_csv(df,
fs::path_join(c(DATA_FOLDER, paste0(sp_code, "_valid.csv")))))