From 8e604e9efdecbaec9aa76909d86f186d3d52372e Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 12:24:47 +0100 Subject: [PATCH 1/7] remove source dat? --- R/helpers_call_results.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index 21af323..287939a 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -135,7 +135,7 @@ clean_ar <- function(raw) { purrr::set_names(id_dat$id) %>% purrr::map_dfr(~ .x %>% tibble::as_tibble(), .id = "id") %>% dplyr::left_join(id_dat, by = "id") %>% - cbind(source_dat) %>% + # cbind(source_dat) %>% tibble::as_tibble() From f1961db3783a5fc6df74a0a4b9effbcdf2952b90 Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 12:35:58 +0100 Subject: [PATCH 2/7] check for message? --- R/helpers_call_results.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index 287939a..71e6ac0 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -190,10 +190,10 @@ add_substat_info <- function(api_results, if (!all_regions) { - suppressMessages( + # suppressMessages( api_results <- api_results %>% dplyr::left_join(meta_info) - ) + # ) if (!is.null(substat_name)) { if (!long_format) { From 4cf183308aecfa4d46307683723a4e39c0a8111d Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 12:53:27 +0100 Subject: [PATCH 3/7] add the by variable for the left join --- R/helpers_call_results.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index 71e6ac0..de5ccc8 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -192,7 +192,7 @@ add_substat_info <- function(api_results, if (!all_regions) { # suppressMessages( api_results <- api_results %>% - dplyr::left_join(meta_info) + dplyr::left_join(meta_info, by = substat_name_) # ) if (!is.null(substat_name)) { From fc8370102be4552e15b5b1e732b1e9b89d1858ab Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 13:04:19 +0100 Subject: [PATCH 4/7] error handle add_substat_info --- R/dg_call.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dg_call.R b/R/dg_call.R index 647a209..34a960e 100644 --- a/R/dg_call.R +++ b/R/dg_call.R @@ -176,7 +176,7 @@ dg_call <- function(region_id = NULL, # ## This is an if statement that handles when we need to get more info on a substat and its parameters if (!is.null(substat_name)) { - # add_substat_info <- purrr::possibly(add_substat_info, otherwise = NULL) + add_substat_info <- purrr::possibly(add_substat_info, otherwise = NULL) api_results <- add_substat_info( api_results, From b4c8caea88b49c2c6de431d26fa84c473508b95f Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 13:12:59 +0100 Subject: [PATCH 5/7] readd source dat --- R/helpers_call_results.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index de5ccc8..a500561 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -135,7 +135,7 @@ clean_ar <- function(raw) { purrr::set_names(id_dat$id) %>% purrr::map_dfr(~ .x %>% tibble::as_tibble(), .id = "id") %>% dplyr::left_join(id_dat, by = "id") %>% - # cbind(source_dat) %>% + cbind(source_dat) %>% tibble::as_tibble() @@ -190,10 +190,10 @@ add_substat_info <- function(api_results, if (!all_regions) { - # suppressMessages( + suppressMessages( api_results <- api_results %>% dplyr::left_join(meta_info, by = substat_name_) - # ) + ) if (!is.null(substat_name)) { if (!long_format) { @@ -218,7 +218,7 @@ add_substat_info <- function(api_results, } else { suppressMessages( api_results <- api_results %>% - dplyr::left_join(meta_info) %>% + dplyr::left_join(meta_info, by = substat_name_) %>% dplyr::select(-substat_name) %>% dplyr::mutate(year_id = paste0(year, "_", id)) # ) From caf6fcb4ea68a9bdb1db296fe59a995e231325ca Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 13:20:18 +0100 Subject: [PATCH 6/7] only add source dat if it doesn't have nrow = 0 --- R/helpers_call_results.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index a500561..e4e6740 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -134,9 +134,13 @@ clean_ar <- function(raw) { purrr::map(~purrr::discard(.x, is.list)) %>% purrr::set_names(id_dat$id) %>% purrr::map_dfr(~ .x %>% tibble::as_tibble(), .id = "id") %>% - dplyr::left_join(id_dat, by = "id") %>% - cbind(source_dat) %>% - tibble::as_tibble() + dplyr::left_join(id_dat, by = "id") + + if (!(nrow(source_dat)==0)) { + final <- final %>% + cbind(source_dat) %>% + tibble::as_tibble() + } return(final) From 24fd45b90f7ad440152981f4e7c9351d0df135e4 Mon Sep 17 00:00:00 2001 From: favstats Date: Sat, 9 Nov 2019 13:29:07 +0100 Subject: [PATCH 7/7] add some annotation to changes --- R/dg_call.R | 1 + R/helpers_call_results.R | 1 + 2 files changed, 2 insertions(+) diff --git a/R/dg_call.R b/R/dg_call.R index 34a960e..bd00d4e 100644 --- a/R/dg_call.R +++ b/R/dg_call.R @@ -176,6 +176,7 @@ dg_call <- function(region_id = NULL, # ## This is an if statement that handles when we need to get more info on a substat and its parameters if (!is.null(substat_name)) { + ## TODO: This is necessary because Travis (for some reason) sometimes treats API results as empty add_substat_info <- purrr::possibly(add_substat_info, otherwise = NULL) api_results <- add_substat_info( diff --git a/R/helpers_call_results.R b/R/helpers_call_results.R index e4e6740..faf2a3c 100644 --- a/R/helpers_call_results.R +++ b/R/helpers_call_results.R @@ -136,6 +136,7 @@ clean_ar <- function(raw) { purrr::map_dfr(~ .x %>% tibble::as_tibble(), .id = "id") %>% dplyr::left_join(id_dat, by = "id") + ## TODO: This is necessary because Travis (for some reason) sometimes thinks source_dat is empty if (!(nrow(source_dat)==0)) { final <- final %>% cbind(source_dat) %>%