Skip to content

Commit

Permalink
Do not save metadata by default
Browse files Browse the repository at this point in the history
  • Loading branch information
realxinzhao committed Oct 17, 2024
1 parent ce2cf86 commit b2b7ead
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
20 changes: 14 additions & 6 deletions R/xfaostat_helper_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' @export

gcamfaostat_metadata <- function(.DIR_RAW_DATA_FAOSTAT = file.path("inst/extdata", DIR_RAW_DATA_FAOSTAT),
OnlyReturnDatasetCodeRequired = FALSE){
OnlyReturnDatasetCodeRequired = FALSE,
Save_metadata = FALSE){

assertthat::assert_that(OnlyReturnDatasetCodeRequired == TRUE|OnlyReturnDatasetCodeRequired == FALSE)

Expand All @@ -37,14 +38,21 @@ gcamfaostat_metadata <- function(.DIR_RAW_DATA_FAOSTAT = file.path("inst/extdata
return(FAO_dataset_code_required)
}

DIR_FAOSTAT_METADATA <- file.path(.DIR_RAW_DATA_FAOSTAT, "metadata_log")
dir.create(DIR_FAOSTAT_METADATA, showWarnings = F)

# Save a table includes all FAOSTAT data info and links
fao_metadata <- FAOSTAT_metadata() %>% filter(datasetcode %in% FAO_dataset_code_required)
readr::write_csv(fao_metadata, file.path(DIR_FAOSTAT_METADATA, paste0("FAOSTAT_METADATA_", Sys.Date(),".csv")))
rlang::inform(paste0("A Full FAOSTAT metadata downloaded and updated in `",
file.path(.DIR_RAW_DATA_FAOSTAT, "metadata_log", "`")))

if (Save_metadata == TRUE) {

DIR_FAOSTAT_METADATA <- file.path(.DIR_RAW_DATA_FAOSTAT, "metadata_log")
dir.create(DIR_FAOSTAT_METADATA, showWarnings = F)

readr::write_csv(fao_metadata, file.path(DIR_FAOSTAT_METADATA, paste0("FAOSTAT_METADATA_", Sys.Date(),".csv")))
rlang::inform(paste0("A Full FAOSTAT metadata downloaded and updated in `",
file.path(.DIR_RAW_DATA_FAOSTAT, "metadata_log", "`")))
}


rlang::inform("---------------------------------------------------------")

rlang::inform(paste0("See returned table for the infomation of FAOSTAT dataset processed in this R package"))
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ articles:
vignette_processing_flow: vignette_processing_flow.html
vignette_use_cases: vignette_use_cases.html
vignette_visualization: vignette_visualization.html
last_built: 2024-10-17T17:10Z
last_built: 2024-10-17T18:29Z
urls:
reference: https://jgcri.github.io/gcamfaostat/reference
article: https://jgcri.github.io/gcamfaostat/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/FAOSTAT_metadata.html

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

3 changes: 2 additions & 1 deletion docs/reference/gcamfaostat_metadata.html

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

3 changes: 2 additions & 1 deletion man/gcamfaostat_metadata.Rd

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

0 comments on commit b2b7ead

Please sign in to comment.