Skip to content

Commit

Permalink
0.0.7 sent to cran
Browse files Browse the repository at this point in the history
  • Loading branch information
guyabel committed Feb 13, 2024
1 parent 93367de commit 99fd2cd
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 128 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Expand Up @@ -2,7 +2,7 @@

* Expanded `wic_locations`, `wic_indicators` and `wic_scenarios` data frames to cover V1, V2 and V3
* Updated `get_wcde()` and `get_wcde_single()` to work with new `wic_locations`, `wic_indicators` and `wic_scenarios`data frames
* Re-coded SSP2ZM and SSP2DM as scenario numbers `22` and `23` on server to make room for SSP2-CER (`20`) and SSP2-FT (`21`) from V1
* Re-coded SSP2-ZM and SSP2-DM as scenario numbers `22` and `23` on server to make room for SSP2-CER (`20`) and SSP2-FT (`21`) from V1

# wcde 0.0.6

Expand Down
57 changes: 11 additions & 46 deletions R/get_wcde.R
Expand Up @@ -66,10 +66,10 @@
#' | `3` | Stalled Development (SSP3) | V1, V2, V3 |
#' | `4` | Inequality (SSP4) | V1, V3 |
#' | `5` | Conventional Development (SSP5) |V1, V3 |
#' | `20` | Medium - Constant Enrollment Rate (SSP2 - CER) | V1 |
#' | `21` | Medium - Fast Track Education (SSP2 - FT) | V1 |
#' | `22` | Medium - Zero Migration (SSP2 - ZM) | V2, V3 |
#' | `23` | Medium - Double Migration (SSP2 - DM) | V2, V3 |
#' | `20` | Medium - Constant Enrollment Rate (SSP2-CER) | V1 |
#' | `21` | Medium - Fast Track Education (SSP2-FT) | V1 |
#' | `22` | Medium - Zero Migration (SSP2-ZM) | V2, V3 |
#' | `23` | Medium - Double Migration (SSP2-DM) | V2, V3 |

#'
#' See `wic_scenarios` data frame for more details.
Expand Down Expand Up @@ -109,8 +109,8 @@ get_wcde <- function(
server = c("iiasa", "github", "1&1", "search-available", "iiasa-local"),
version = c("wcde-v3", "wcde-v2", "wcde-v1")
){
# scenario = 2; indicator = "tfr"; country_code = c(410, 288); country_name = NULL; include_scenario_names = FALSE; server = "search-available"; version = "wcde-v3"
# indicator = "etfr"; country_name = c("Brazil", "Albania"); country_code = NULL; server = "iiasa"
# scenario = 2; indicator = "tfr"; country_code = c(410, 288); country_name = NULL; include_scenario_names = FALSE; server = "iiasa"; version = "wcde-v3"
# indicator = "etfr"; country_name = c("Brazil", "Albania"); country_code = NULL; server = "github"
# guess country codes from name

guessed_code <- NULL
Expand Down Expand Up @@ -178,7 +178,7 @@ get_wcde <- function(
server <- dplyr::case_when(
RCurl::url.exists("https://wicshiny2023.iiasa.ac.at/wcde-data/") ~ "iiasa",
# RCurl::url.exists("https://wicshiny.iiasa.ac.at/wcde-data/") ~ "iiasa",
RCurl::url.exists("https://github.com/guyabel/wcde-data/raw/main/") ~ "github",
RCurl::url.exists("https://github.com/guyabel/wcde-data/") ~ "github",
RCurl::url.exists("https://shiny.wittgensteincentre.info/wcde-data/") ~ "1&1",
TRUE ~ "none-available"
)
Expand All @@ -189,46 +189,11 @@ get_wcde <- function(
server_url <- dplyr::case_when(
server == "iiasa" ~ "https://wicshiny2023.iiasa.ac.at/wcde-data/",
server == "iiasa-local" ~ "../wcde-data/",
server == "github" ~ "https://github.com/guyabel/wcde-data/raw/main/",
server == "github" ~ "https://github.com/guyabel/wcde-data/raw/master/",
server == "1&1" ~ "https://shiny.wittgensteincentre.info/wcde-data/",
TRUE ~ server)

vv <- ifelse(is.null(country_code), "-batch", "-single")
# # version to wcde_v3 if no version check
# if(is.null(server_check)){
# server_check <- ifelse(server == "iiasa-local", TRUE, FALSE)
# }
# v <- ifelse(server_check, NULL, "wcde-v3")
v <- NULL
# version given if available
if(is.null(v)){
uu <- paste0(server_url, version, vv)
if(RCurl::url.exists(uu)){
v <- version
}
}
# wcde-v3 if version not given and v3 is available
if(is.null(v)){
uu <- paste0(server_url, "wcde-v3", vv)
if(RCurl::url.exists(uu)){
v <- "wcde-v3"
message("Version ", version, " not available on server, using wcde-v3")
}
}
if(is.null(v)){
uu <- paste0(server_url, "wcde-v2", vv)
if(RCurl::url.exists(uu)){
v <- "wcde-v2"
message("Version ", version, " not available on server, using wcde-v2")
}
}
if(is.null(v)){
uu <- paste0(server_url, "wcde-v1", vv)
if(RCurl::url.exists(uu)){
v <- "wcde-v1"
message("Version ", version, " not available on server, using wcde-v1")
}
}
vv <- paste0(version, ifelse(is.null(country_code), "-batch", "-single"))

wic_scenarios_v <- wcde::wic_scenarios %>%
tidyr::pivot_longer(dplyr::contains("wcde"), names_to = "v", values_to = "avail") %>%
Expand All @@ -238,7 +203,7 @@ get_wcde <- function(

if(is.null(country_code)){
d2 <- tibble::tibble(scenario = scenario) %>%
dplyr::mutate(u = paste0(server_url, v, "-batch/", scenario, "/",
dplyr::mutate(u = paste0(server_url, vv, "/", scenario, "/",
indicator, ".rds")) %>%
dplyr::mutate(
d = purrr::map(
Expand All @@ -258,7 +223,7 @@ get_wcde <- function(
avail) %>%
dplyr::select(isono, name)

d2 <- get_wcde_single(indicator = indicator, scenario = scenario, country_code = country_code, version = v, server = server) %>%
d2 <- get_wcde_single(indicator = indicator, scenario = scenario, country_code = country_code, version = version, server = server) %>%
dplyr::mutate(isono = as.numeric(isono)) %>%
dplyr::left_join(wic_locations_v, by = "isono") %>%
{if(include_scenario_names) dplyr::left_join(. , wic_scenarios_v, by = "scenario") else .}
Expand Down
8 changes: 4 additions & 4 deletions R/get_wcde_single.R
Expand Up @@ -12,9 +12,9 @@
#' @export
get_wcde_single <- function(indicator = NULL, scenario = 2, country_code = NULL,
server = NULL, version = NULL){
# scenario = c(1, 3); indicator = "tfr"; country_code = c(40, 100)
# scenario = c(1, 3); indicator = "etfr"; country_code = c(40, 100)
# scenario = 2; indicator = "e0"; country_code = "900"
# server = "github"
# server = "github"; version = "wcde-v1"
if(length(indicator) > 1){
message("can only get data on one indicator at a time, taking first indicator given")
indicator <- indicator[1]
Expand Down Expand Up @@ -77,7 +77,7 @@ get_wcde_single <- function(indicator = NULL, scenario = 2, country_code = NULL,
server <- dplyr::case_when(
RCurl::url.exists("https://wicshiny2023.iiasa.ac.at/wcde-data/") ~ "iiasa",
# RCurl::url.exists("https://wicshiny.iiasa.ac.at/wcde-data/") ~ "iiasa",
RCurl::url.exists("https://github.com/guyabel/wcde-data/raw/main/") ~ "github",
RCurl::url.exists("https://github.com/guyabel/wcde-data/") ~ "github",
RCurl::url.exists("https://shiny.wittgensteincentre.info/wcde-data/") ~ "1&1",
TRUE ~ "none-available"
)
Expand All @@ -86,7 +86,7 @@ get_wcde_single <- function(indicator = NULL, scenario = 2, country_code = NULL,
server_url <- dplyr::case_when(
server == "iiasa" ~ "https://wicshiny2023.iiasa.ac.at/wcde-data/",
server == "iiasa-local" ~ "../wcde-data/",
server == "github" ~ "https://github.com/guyabel/wcde-data/raw/main/",
server == "github" ~ "https://github.com/guyabel/wcde-data/raw/master/",
server == "1&1" ~ "https://shiny.wittgensteincentre.info/wcde-data/",
TRUE ~ server)

Expand Down
1 change: 1 addition & 0 deletions R/wcde_location.R
Expand Up @@ -15,6 +15,7 @@
#' wcde_location(country_code = 3)
wcde_location <- function(country_code,
version = c("wcde-v3", "wcde-v2", "wcde-v1")){
version <- match.arg(version)
v <- wcde::wic_locations %>%
tidyr::pivot_longer(dplyr::contains("wcde"), names_to = "vv", values_to = "avail") %>%
dplyr::filter(vv == version,
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(
)
```

# wcde
# wcde <a href="https://guyabel.github.io/wcde/"><img src="man/figures/logo.png" align="right" height="138" /></a>

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/wcde)](https://CRAN.R-project.org/package=wcde)
Expand Down
3 changes: 1 addition & 2 deletions README.md
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# wcde
# wcde <a href="https://guyabel.github.io/wcde/"><img src="man/figures/logo.png" align="right" height="138" /></a>

<!-- badges: start -->

Expand Down Expand Up @@ -84,7 +84,6 @@ get_wcde(indicator = "pop", country_code = c(364, 404), pop_edu = "four")

# SSP1, 2 and 3 gender gaps in educational attainment (15+) for all countries
get_wcde(indicator = "ggapedu15", scenario = 1:3)
#> Version wcde-v3 not available on server, using wcde-v3
#> # A tibble: 69,768 × 6
#> scenario name country_code year education ggapedu15
#> <int> <chr> <dbl> <dbl> <chr> <dbl>
Expand Down
3 changes: 2 additions & 1 deletion build_package.R
Expand Up @@ -6,8 +6,9 @@ roxygen2::roxygenise()

# move data-host and data-host-bulk outside of directory whilst
# doing check https://community.rstudio.com/t/r-cmd-check-preparing-package/27151
devtools::build()
devtools::build(vignettes = FALSE)
devtools::check(vignettes = FALSE)
devtools::build()
devtools::check()
file.show("NEWS.md")

Expand Down
27 changes: 17 additions & 10 deletions data-raw/wic_scenarios.R
@@ -1,5 +1,6 @@
library(tidyverse)
library(readxl)
library(fs)

wic_scenarios <- dir_ls("./data-raw", type = "directory") %>%
as_tibble() %>%
Expand All @@ -13,16 +14,22 @@ wic_scenarios <- dir_ls("./data-raw", type = "directory") %>%
scenario_abb = sname) %>%
select(contains("scenario"), version) %>%
# arrange(scenario_abb)
mutate(scenario = case_when(
scenario_abb == "SSP1" ~ 1,
scenario_abb == "SSP2" ~ 2,
scenario_abb == "SSP3" ~ 3,
scenario_abb == "SSP4" ~ 4,
scenario_abb == "SSP5" ~ 5,
scenario_abb == "SSP2-CER" ~ 20,
scenario_abb == "SSP2-FT" ~ 21,
scenario_abb == "SSP2ZM" ~ 22,
scenario_abb == "SSP2DM" ~ 23)) %>%
mutate(scenario_name = str_replace(string = scenario_name, pattern = "-", replacement = " - "),
scenario_name = str_replace(string = scenario_name, pattern = " - ", replacement = " - "),
scenario_name = str_replace(string = scenario_name, pattern = "2 - ", replacement = "2-"),
scenario_abb = str_extract(string = scenario_name, pattern = "\\(([^)]+)\\)"),
scenario_abb = str_sub(string = scenario_abb, start = 2, end = -2),
scenario = case_when(
scenario_abb == "SSP1" ~ 1,
scenario_abb == "SSP2" ~ 2,
scenario_abb == "SSP3" ~ 3,
scenario_abb == "SSP4" ~ 4,
scenario_abb == "SSP5" ~ 5,
scenario_abb == "SSP2-CER" ~ 20,
scenario_abb == "SSP2-FT" ~ 21,
scenario_abb == "SSP2-ZM" ~ 22,
scenario_abb == "SSP2-DM" ~ 23)
) %>%
arrange(desc(version), scenario) %>%
mutate(value = TRUE) %>%
pivot_wider(names_from = "version") %>%
Expand Down
Binary file modified data/wic_scenarios.rda
Binary file not shown.

0 comments on commit 99fd2cd

Please sign in to comment.