-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_windows.R
61 lines (53 loc) · 2.93 KB
/
setup_windows.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
# Get data used for the shiny application
# Atlas of Seabirds at Sea in Eastern Canada 2006-2016
# https://open.canada.ca/data/en/dataset/f612e2b4-5c67-46dc-9a84-1154c649ab4e
# Declare resources
resources <- list(
gdb = list(
file = "AtlasGrid-GrilleAtlas.gdb.zip",
location = "http://data.ec.gc.ca/data/species/assess/atlas-of-seabirds-at-sea-in-eastern-canada-2006-2016/AtlasGrid-GrilleAtlas.gdb.zip",
outputdir = "data"
),
data = list(
file = "DensityData-DonneesDeDensite.xlsx",
location = "http://data.ec.gc.ca/data/species/assess/atlas-of-seabirds-at-sea-in-eastern-canada-2006-2016/DensityData-DonneesDeDensite.xlsx",
outputdir = "data"
),
dictionnary = list(
file = "DataDictionary-DictionnaireDeDonnees.xlsx",
location = "http://data.ec.gc.ca/data/species/assess/atlas-of-seabirds-at-sea-in-eastern-canada-2006-2016/DataDictionary-DictionnaireDeDonnees.xlsx",
outputdir = "data"
)
)
for (resource in resources){
if (!file.exists(resource$outputdir)) dir.create(resource$outputdir)
if (!file.exists(paste(resource$outputdir, resource$file, sep = "/"))){
download.file(resource$location, destfile = paste(resource$outputdir, resource$file, sep = "/"), mode = "wb")
}
if (grepl("zip", resource$file)){
utils::unzip(paste(resource$outputdir, resource$file, sep = "/"), exdir = resource$outputdir)
}
}
# Import species dictionary and simplify
species <- readxl::read_excel(paste(resources$dictionnary$outputdir, resources$dictionnary$file, sep = "/"), 1) %>%
dplyr::select(Species_ID, English_Name, Scientific_Name, Family_Sci)
# Import density data and simplify
densities <- readxl::read_excel(paste(resources$data$outputdir, resources$data$file, sep = "/"), "Densities") %>%
dplyr::select(Group, Month, Stratum, Density) %>%
dplyr::mutate(
Month = replace(Month, Month == "04050607", "April-July"),
Month = replace(Month, Month == "08091011", "August-November"),
Month = replace(Month, Month == "12010203", "December-March")
) %>% dplyr::filter(Group %in% species$Species_ID)
# Import effort data and simplify
effort <- readxl::read_excel(paste(resources$data$outputdir, resources$data$file, sep = "/"), "Effort") %>%
dplyr::select(Stratum, Month, nbspecies, nbobs, nbind, nbsamples, nbkm, nbcruiseID, nbdays) %>%
dplyr::mutate(
Month = replace(Month, Month == "04050607", "April-July"),
Month = replace(Month, Month == "08091011", "August-November"),
Month = replace(Month, Month == "12010203", "December-March")
) %>% tidyr::pivot_longer(cols = nbspecies:nbdays)
# Export as csv
write.csv(densities, "data/densities.csv", row.names = FALSE)
write.csv(species, "data/species.csv", row.names = FALSE)
write.csv(effort, "data/effort.csv", row.names = FALSE)