Skip to content

Commit

Permalink
quick meta data local path update
Browse files Browse the repository at this point in the history
  • Loading branch information
realxinzhao committed Oct 17, 2024
1 parent b2b7ead commit 872063c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 4 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ PACKAGE_NAME <- "gcamfaostat"
# silence package check
utils::globalVariables(c(
".", "APE_comm", "APE_comm_source", "Area", "harvested", "Closing stocks",
"Export", "FALSE", "FAO_ag_items_PRODSTAT", "Feed", "Food",
"GCAMDATA_FAOSTAT_BiTrade_194Regs_400Items_2010to2020",
"GCAMDATA_FAOSTAT_FBSH_CB_173Regs_118Items_1973to2009",
"GCAMDATA_FAOSTAT_MacroNutrientRate_179Regs_426Items_2010to2019Mean",
"GCAMDATA_FAOSTAT_ProdArea_195Regs_271Prod160AreaItems_1973to2020",
"GCAMDATA_FAOSTAT_SUA_195Regs_530Items_2010to2019", "Import",
"Export", "FALSE", "FAO_ag_items_PRODSTAT", "Feed", "Food", "Import",
"Import_Demand_Share", "Loss", "Mapping_SUA_PrimaryEquivalent", "Opening stocks",
"Opening stocks1", "Ostock", "Ostock_Demand_Share", "Ostock_demand", "Other uses",
"PREBUILT_DATA", "Processed", "Production", "Q25asMin", "Regional demand",
Expand All @@ -35,7 +30,9 @@ utils::globalVariables(c(
"FAO_an_items_PRODSTAT", "FAOupdate", "GCAM_AgLU_SUA_APE_1973_2019",
"GCAM_DATA_MAP", "GCAM_commodity", "GCAM_region_names", "GCAM_subsector",
"Localupdate", "TM", "Tourist", "consumption", "datasetname", "localfilesize",
"moving_avg", "remotefilezize", "unit", "Tourist consumption", "xml.XML_SUFFIX"))
"moving_avg", "remotefilezize", "unit", "Tourist consumption", "xml.XML_SUFFIX",
"macronutrient_value", "source_item", "region_ID", "QCL_CROP_PRIMARY",
"DS_key_coproduct_item_code", "CBH", "QCL_Cake"))

#' find_header
#'
Expand Down
15 changes: 6 additions & 9 deletions R/xfaostat_helper_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ gcamfaostat_metadata <- function(.DIR_RAW_DATA_FAOSTAT = file.path("inst/extdata

DataCodePrebuilt <-
PREBUILT_DATA %>% names() %>% strsplit(split = "_") %>% unlist %>%
setdiff(c("wide", "Roundwood", "code", "area", "bilateral", "map"))
setdiff(c("wide", "RoundwoodProducts", "code", "area", "bilateral", "map"))

FF_rawdata_info(DATA_FOLDER = .DIR_RAW_DATA_FAOSTAT,
DATASETCODE = FAO_dataset_code_required,
Expand Down Expand Up @@ -238,7 +238,10 @@ FF_rawdata_info <- function(
assertthat::assert_that(is.character(DATASETCODE))
assertthat::assert_that(is.logical(DOWNLOAD_NONEXIST))
assertthat::assert_that(FAOSTAT_or_Archive == "FAOSTAT"|FAOSTAT_or_Archive == "Archive")
assertthat::assert_that(file.exists(DATA_FOLDER))

if (!file.exists(DATA_FOLDER)) {
DATA_FOLDER <- "."
}

file.info(dir(DATA_FOLDER, full.names = T)) %>%
tibble::rownames_to_column(var = "filelocation") %>%
Expand All @@ -250,14 +253,8 @@ FF_rawdata_info <- function(
#localfilesize = utils:::format.object_size(size, "MB", digits = 0),
localfilesize = paste0(round(size/10^6, digits = 0), " MB" )) %>%
# Join the latest metadata
# Note that FAO raw data had a typo (missing space) in Trade_CropsLivestock_E_All_Data_(Normalized).zip
# Temporary fix here
# This was fixed in 2022 updates
right_join(FAOSTAT_metadata() %>% filter(datasetcode %in% DATASETCODE) %>%
mutate(filelocation = basename(filelocation)), #%>%
#mutate(filelocation = replace(filelocation,
# filelocation == "Trade_CropsLivestock_E_All_Data_(Normalized).zip",
# "Trade_Crops_Livestock_E_All_Data_(Normalized).zip")),
mutate(filelocation = basename(filelocation)),
by = "filelocation") %>%
transmute(datasetcode, datasetname,
FAOupdate = dateupdate, Localupdate = mtime,
Expand Down
2 changes: 1 addition & 1 deletion vignettes/vignette_preparing_data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When `gcamfaostat` is downloaded, preprocessed FAOSTAT data, i.e., output of the
library(gcamfaostat)
library(dplyr)
library(kableExtra)
gcamfaostat_metadata(.DIR_RAW_DATA_FAOSTAT = file.path("..", "inst/extdata/FAOSTAT")) %>%
gcamfaostat_metadata(.DIR_RAW_DATA_FAOSTAT = file.path("..", "inst/extdata/FAOSTAT"), Save_metadata = FALSE) %>%
select(-`Local file size`) -> p
p %>%
Expand Down

0 comments on commit 872063c

Please sign in to comment.