Skip to content

Commit

Permalink
Address Code Suggestions #9 and Usability Fixes #10
Browse files Browse the repository at this point in the history
Clear errors and warning in package checking
  • Loading branch information
realxinzhao committed Mar 16, 2024
1 parent 2005d03 commit a89a9d2
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 276 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ coverage.R
^_pkgdown\.yml$
^docs$
^pkgdown$
^.drake/
^tests/testthat/.drake/
^inst/extdata/aglu/FAO/FAOSTAT_Archive/
^inst/extdata/aglu/FAO/FAOSTAT/*.zip
^.github
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Imports:
ggplot2 (>= 3.3.2),
xml2 (>= 1.3.2),
XML (>= 3.99-0.5),
rlang
rlang,
kableExtra
Suggests:
igraph (>= 1.0.1),
testthat (>= 3.0.0),
Expand All @@ -41,6 +42,6 @@ Suggests:
rmarkdown
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Hist_MEAN_Year_NUTRIENT_MASS_CONV <- 2010:2019 # average cal per g
# decimal places in ggplot
scaleFUN <- function(x) sprintf("%.0f", x)


xml.XML_SUFFIX <- NULL



Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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"))
"moving_avg", "remotefilezize", "unit", "Tourist consumption", "xml.XML_SUFFIX"))

#' find_header
#'
Expand Down
3 changes: 2 additions & 1 deletion R/xfaostat_helper_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ FF_rawdata_info <- function(
grepl("zip$", filelocation)) %>%
transmute(filelocation = basename(filelocation),
ctime = as.Date(ctime), mtime = as.Date(mtime),
localfilesize = utils:::format.object_size(size, "MB", digits = 0)) %>%
#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
Expand Down
38 changes: 19 additions & 19 deletions R/zaglu_L100.FAO_SUA_PrimaryEquivalent.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ module_aglu_L100.FAO_SUA_PrimaryEquivalent <- function(command, ...) {
# 2.1 Helper functions for SUA primary equivalent aggregation ----


#' Get extraction rate
#' @description Gross extraction rate is calculated for domestic, traded, and lagged values.
#' By gross, it means sink items are aggregated.
#' The function is used in Proc_primarize.
#' @param DF_CURR_NEST Input supply-utilization accounting data frame with one tier of processing
#' @param DF_ALL Input supply-utilization accounting data frame with ALL the data
#' @return A data frame including regional, traded, and world extraction rates of a processing
# Get extraction rate
# @description Gross extraction rate is calculated for domestic, traded, and lagged values.
# By gross, it means sink items are aggregated.
# The function is used in Proc_primarize.
# @param DF_CURR_NEST Input supply-utilization accounting data frame with one tier of processing
# @param DF_ALL Input supply-utilization accounting data frame with ALL the data
# @return A data frame including regional, traded, and world extraction rates of a processing

Get_GROSS_EXTRACTION_RATE <- function(DF_CURR_NEST, DF_ALL) {
curr_sink_items = unique(DF_CURR_NEST$item_code)
Expand Down Expand Up @@ -248,10 +248,10 @@ module_aglu_L100.FAO_SUA_PrimaryEquivalent <- function(command, ...) {
}


#' Separate the SUA balance into domestic and imported balanced for sink_item
#' @description The function is used in Proc_primarize
#' @param DF_CURR_NEST Input supply-utilization accounting data frame with one tier of processing
#' @return SUA DF
# Separate the SUA balance into domestic and imported balanced for sink_item
# @description The function is used in Proc_primarize
# @param DF_CURR_NEST Input supply-utilization accounting data frame with one tier of processing
# @return SUA DF

Get_ARMINGTON_BALANCE <- function(DF_CURR_NEST) {
Import_Demand_Item <- factor(c("Food", "Feed", "Processed", "Other uses", "Seed", "Loss"), levels=All_Bal_element)
Expand Down Expand Up @@ -308,11 +308,11 @@ module_aglu_L100.FAO_SUA_PrimaryEquivalent <- function(command, ...) {
}


#' Separate the domestic SUA balance into current and lagged balanced for sink_item
#' @description The function is used in Proc_primarize
#' @param DF_CURR_NEST_TradeAdj Output from Get_ARMINGTON_BALANCE. Input supply-utilization accounting data frame with one tier of processing and
#' @param .SINK_ITEM Sink items or processed items in the processing
#' @return SUA DF
# Separate the domestic SUA balance into current and lagged balanced for sink_item
# @description The function is used in Proc_primarize
# @param DF_CURR_NEST_TradeAdj Output from Get_ARMINGTON_BALANCE. Input supply-utilization accounting data frame with one tier of processing and
# @param .SINK_ITEM Sink items or processed items in the processing
# @return SUA DF

Get_STOCK_BALANCE <- function(DF_CURR_NEST_TradeAdj) {
Opening_Stock_Item <- factor(c("Food", "Feed", "Processed", "Other uses", "Seed", "Loss"), levels=All_Bal_element)
Expand Down Expand Up @@ -380,9 +380,9 @@ module_aglu_L100.FAO_SUA_PrimaryEquivalent <- function(command, ...) {
}


#' Primary equivalent aggregation
#' @param DF_ALL Input supply-utilization accounting data frame with all levels of data nested which need to be primarized
#' @return A supply-utilization accounting data frame with all levels processed and aggregated to GCAM_commodity
# Primary equivalent aggregation
# @param DF_ALL Input supply-utilization accounting data frame with all levels of data nested which need to be primarized
# @return A supply-utilization accounting data frame with all levels processed and aggregated to GCAM_commodity

Proc_primarize <- function(DF_ALL){
MaxNest = max(DF_ALL$nest_level)
Expand Down
34 changes: 3 additions & 31 deletions man/module_aglu_L100.FAO_SUA_PrimaryEquivalent.Rd

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

Loading

0 comments on commit a89a9d2

Please sign in to comment.