Skip to content

Commit

Permalink
clean up download functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aspina7 committed Sep 7, 2022
1 parent b7404fa commit 2a97f7b
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 175 deletions.
9 changes: 2 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Imports:
broom,
clipr,
cli,
rstudioapi,
dplyr (>= 0.8.0),
epitabulate (>= 0.0.0.9007),
epidict (>= 0.0.0.9001),
Expand All @@ -70,6 +69,7 @@ Imports:
rio,
rlang (>= 0.4.0),
rmarkdown,
rstudioapi,
scales,
sf,
slider,
Expand Down Expand Up @@ -109,9 +109,4 @@ Collate:
'AJS_pop_internal.R'
'shape_quartier_internal.R'
'shape_block_internal.R'
'download_survey.R'
'download_kobo.R'
'download_outbreak_linelist.R'
'download_outbreak_pop.R'
'download_shape_quartier.R'
'download_shape_block.R'
'download_datasets.R'
118 changes: 118 additions & 0 deletions R/download_datasets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#' @title Internal function (not exported - i.e. not userfacing) to reduce code duplication
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#' @param dataset The name of the file to save
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success

generic_download <- function(path = rstudioapi::selectDirectory(), dataset){

## normalise in case given manually
path <- normalizePath(path)

file_to_copy <- system.file(package = "sitrep", "extdata", dataset)

success <- lapply(file_to_copy, file.copy, to = path, overwrite = TRUE)

if(all(as.logical(success))) cli::cli_alert_success("File successfully saved here: {path}")

}


#' @title Access kobo data dictionary
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_kobo <- function(path = rstudioapi::selectDirectory()){

generic_download(path = path, dataset = "mortality_survey_dict.xlsx")

}


#' @title Access AJS outbreak linelist
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_outbreak_linelist <- function(path = rstudioapi::selectDirectory()){

generic_download(path = path, dataset = "AJS_AmTiman.xlsx")

}


#' @title Access AJS outbreak population data
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_outbreak_pop <- function(path = rstudioapi::selectDirectory()){

generic_download(path = path, dataset = "AJS_AmTiman_population.xlsx")

}


#' @title Access Am Timan blocks shapefile
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_shape_block <- function(path = rstudioapi::selectDirectory()){

included_files <- list.files(system.file(package = "sitrep", "extdata"))

dataset <- included_files[grep("Blocksshape", included_files)]

generic_download(path = path, dataset = dataset)

}


#' @title Access Am Timan quartier shapefile
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_shape_quartier <- function(path = rstudioapi::selectDirectory()){

included_files <- list.files(system.file(package = "sitrep", "extdata"))

dataset <- included_files[grep("Quartiersshape", included_files)]

generic_download(path = path, dataset = dataset)

}


#' @title Access fake mortality survey data
#'
#' @param path **Run with no arguments to pick a directory interactively**. Path on your computer where the file(s) should be saved to *string*
#'
#' @importFrom rstudioapi selectDirectory
#' @importFrom cli cli_alert_success
#'
#' @export
download_survey <- function(path = rstudioapi::selectDirectory()){

generic_download(path = path, dataset = "mortality_survey_data.xlsx")

}
22 changes: 0 additions & 22 deletions R/download_kobo.R

This file was deleted.

22 changes: 0 additions & 22 deletions R/download_outbreak_linelist.R

This file was deleted.

22 changes: 0 additions & 22 deletions R/download_outbreak_pop.R

This file was deleted.

22 changes: 0 additions & 22 deletions R/download_shape_block.R

This file was deleted.

22 changes: 0 additions & 22 deletions R/download_shape_quartier.R

This file was deleted.

22 changes: 0 additions & 22 deletions R/download_survey.R

This file was deleted.

8 changes: 2 additions & 6 deletions man/download_kobo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/download_outbreak_linelist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/download_outbreak_pop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/download_shape_block.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/download_shape_quartier.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2a97f7b

Please sign in to comment.