Skip to content

Commit

Permalink
removed rgdal
Browse files Browse the repository at this point in the history
  • Loading branch information
GuidoMaggio committed Aug 25, 2023
1 parent c9ec928 commit 58660f5
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 448 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Imports:
grid,
leaflet,
leaflet.extras,
rgdal,
shinycssloaders,
lubridate,
sp,
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export(get_timeseries_global_data)
export(get_timeseries_province_data)
export(get_timeseries_single_data)
export(lab_percent)
export(load_countries_data_map)
export(lw_vars_calc)
export(merge_pop_data)
export(new_total_colors)
Expand Down Expand Up @@ -107,16 +106,13 @@ importFrom(leaflet,leafletOutput)
importFrom(lubridate,day)
importFrom(lubridate,hour)
importFrom(lubridate,with_tz)
importFrom(pkgload,load_all)
importFrom(plotly,ggplotly)
importFrom(plotly,layout)
importFrom(plotly,plotlyOutput)
importFrom(plotly,plotly_build)
importFrom(plotly,renderPlotly)
importFrom(plotly,style)
importFrom(rlang,sym)
importFrom(rsconnect,deployApp)
importFrom(rsconnect,setAccountInfo)
importFrom(scales,label_number)
importFrom(shiny,NS)
importFrom(shiny,selectInput)
Expand Down
8 changes: 1 addition & 7 deletions R/run_app.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#' utilities package
#'
#' @importFrom pkgload load_all
#' @importFrom rsconnect deployApp setAccountInfo
#' @noRd


#' Run the Shiny Application
#'
#' @param ... A series of options to be used inside the app.
#'
#' @export
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
#'
run_app <- function(
...
) {
Expand Down
139 changes: 0 additions & 139 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,146 +307,7 @@ new_total_colors <- c(
"new" = "#ea8b5b"
)

#' load countries data
#' @param destpath path to file
#'
#' @returns countries shapefile
#' @export
load_countries_data_map <- function(destpath = system.file("./countries_data", package = "Covid19Mirai")){
# Resource https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/
url <- "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"
zip_path <- file.path(destpath,"ne_50m_admin_0_countries.zip")
dsn_path <- file.path(destpath, "ne_50m_admin_0_countries")

if (!file.exists(zip_path)) {
download.file(url = url, destfile = zip_path)
unzip(zip_path, exdir = dsn_path)
}

countries <- rgdal::readOGR(dsn = dsn_path,
layer = "ne_50m_admin_0_countries",
encoding = "utf-8", use_iconv = T,
verbose = FALSE)
assign_new_level = function(countrymap , lev, from, to, regexpress = FALSE) {
if (regexpress) {
if (!any(grepl(from, as.character(countrymap[[lev]]))))
stop("wrong expression, not present in map: ", from)
from = grep(from, as.character(countrymap[[lev]]), value = TRUE)
}
if (!any(countrymap[[lev]] == from))
stop("wrong name, not present in map: ", from)
levels(countrymap[[lev]])[levels(countrymap[[lev]])==from] <- to
countrymap[[lev]][countrymap[[lev]] == from] = to
countrymap
}
#rename continents
countries = assign_new_level(countries, "CONTINENT", "North America", "Northern America")
countries = assign_new_level(countries, "CONTINENT", "South America", "LatAm & Carib.")
#rename NAME, i.e. countries
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
countries = assign_new_level(countries, "NAME", "Macedonia", "North Macedonia")
countries = assign_new_level(countries, "NAME", "Czechia", "Czech Republic")
countries = assign_new_level(countries, "NAME", "Dominican Rep.", "Dominican Republic")
countries = assign_new_level(countries, "NAME", "United Kingdom", "UK")
countries = assign_new_level(countries, "NAME", "United States of America", "USA")
countries = assign_new_level(countries, "NAME", "United Arab Emirates", "UAE")
countries = assign_new_level(countries, "NAME", "^St-Barth", "St. Barth", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "Faeroe Is.", "Faeroe Islands")
countries = assign_new_level(countries, "NAME", "Bosnia and Herz.", "Bosnia and Herzegovina")
countries = assign_new_level(countries, "NAME", "Vatican", "Vatican City")
countries = assign_new_level(countries, "NAME", "St. Vin. and Gren.", "St. Vincent Grenadines")
countries = assign_new_level(countries, "NAME", "Dem. Rep. Congo", "Republic of the Congo")
#countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "Ivoire", "Cote d'Ivoire", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "St-Martin", "St Martin")
countries = assign_new_level(countries, "NAME", "Cayman Is.", "Cayman Islands")
countries = assign_new_level(countries, "NAME", "Eq. Guinea", "Equatorial Guinea")
countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "eSwatini", "Eswatini")
countries = assign_new_level(countries, "NAME", "Cabo Verde", "Cape Verde")
countries = assign_new_level(countries, "NAME", "S. Sudan", "South Sudan")
countries = assign_new_level(countries, "NAME", "Fr. Polynesia", "French Polynesia")
countries = assign_new_level(countries, "NAME", "Antigua and Barb.", "Antigua and Barbuda")
countries = assign_new_level(countries, "NAME", "Cook Is.", "Cook Islands")
countries = assign_new_level(countries, "NAME", "Falkland Is.", "Falkland Islands")
countries = assign_new_level(countries, "NAME", "U.S. Virgin Is.", "U.S. Virgin Islands")

countries
}

#' load countries data to match with get_datahub
#' @param destpath path to file
#'
#' @returns countries shapefile
#' @noRd
load_countries_datahub_map <- function(destpath = system.file("./countries_data", package = "Covid19Mirai")){
# Resource https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/
url <- "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"
zip_path <- file.path(destpath,"ne_50m_admin_0_countries.zip")
dsn_path <- file.path(destpath, "ne_50m_admin_0_countries")

if (!file.exists(zip_path)) {
download.file(url = url, destfile = zip_path)
unzip(zip_path, exdir = dsn_path)
}

countries <- rgdal::readOGR(dsn = dsn_path,
layer = "ne_50m_admin_0_countries",
encoding = "utf-8", use_iconv = T,
verbose = FALSE)
assign_new_level = function(countrymap , lev, from, to, regexpress = FALSE) {
if (regexpress) {
if (!any(grepl(from, as.character(countrymap[[lev]]))))
stop("wrong expression, not present in map: ", from)
from = grep(from, as.character(countrymap[[lev]]), value = TRUE)
}
if (!any(countrymap[[lev]] == from))
stop("wrong name, not present in map: ", from)
levels(countrymap[[lev]])[levels(countrymap[[lev]])==from] <- to
countrymap[[lev]][countrymap[[lev]] == from] = to
countrymap
}
#rename continents
countries = assign_new_level(countries, "CONTINENT", "North America", "Northern America")
countries = assign_new_level(countries, "CONTINENT", "South America", "LatAm & Carib.")
#rename NAME, i.e. countries
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
countries = assign_new_level(countries, "NAME", "Macedonia", "North Macedonia")
countries = assign_new_level(countries, "NAME", "Czechia", "Czech Republic")
countries = assign_new_level(countries, "NAME", "Dominican Rep.", "Dominican Republic")
countries = assign_new_level(countries, "NAME", "United Kingdom", "UK")
countries = assign_new_level(countries, "NAME", "United States of America", "USA")
#countries = assign_new_level(countries, "NAME", "United Arab Emirates", "UAE") # now has new name
countries = assign_new_level(countries, "NAME", "^St-Barth", "St. Barth", regexpress = TRUE) # not needed but ok
countries = assign_new_level(countries, "NAME", "Faeroe Is.", "Faeroe Islands")
countries = assign_new_level(countries, "NAME", "Bosnia and Herz.", "Bosnia and Herzegovina")
countries = assign_new_level(countries, "NAME", "Vatican", "Vatican City")
countries = assign_new_level(countries, "NAME", "St. Vin. and Gren.", "St. Vincent Grenadines")
countries = assign_new_level(countries, "NAME", "Dem. Rep. Congo", "Republic of the Congo")
#countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "Ivoire", "Cote d'Ivoire", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "St-Martin", "St Martin")
countries = assign_new_level(countries, "NAME", "Cayman Is.", "Cayman Islands")
countries = assign_new_level(countries, "NAME", "Eq. Guinea", "Equatorial Guinea")
countries = assign_new_level(countries, "NAME", "Central African Rep.", "Central African Republic")
countries = assign_new_level(countries, "NAME", "eSwatini", "Swaziland")
countries = assign_new_level(countries, "NAME", "Cabo Verde", "Cape Verde")
countries = assign_new_level(countries, "NAME", "S. Sudan", "South Sudan")
countries = assign_new_level(countries, "NAME", "Fr. Polynesia", "French Polynesia")
countries = assign_new_level(countries, "NAME", "Antigua and Barb.", "Antigua and Barbuda")
countries = assign_new_level(countries, "NAME", "Cook Is.", "Cook Islands")
countries = assign_new_level(countries, "NAME", "Falkland Is.", "Falkland Islands")
countries = assign_new_level(countries, "NAME", "U.S. Virgin Is.", "U.S. Virgin Islands") # new name
countries = assign_new_level(countries, "NAME", "St. Kitts and Nevis", "Saint Kitts and Nevis" ) # new name
countries = assign_new_level(countries, "NAME", "Principe", "Sao Tome and Principe", regexpress = TRUE )
countries = assign_new_level(countries, "NAME", "N. Mariana Is.", "Northern Mariana Islands")
countries = assign_new_level(countries, "NAME", "Marshall Is.", "Marshall Iselands")
countries = assign_new_level(countries, "NAME", "St. Pierre and Miquelon", "St. Pierre and Miquelon")

countries
}

#' Sort type by max
#'
Expand Down
Loading

0 comments on commit 58660f5

Please sign in to comment.