Skip to content

Commit

Permalink
Improve function documentation and add forestry, land, and fertilizer…
Browse files Browse the repository at this point in the history
… data processing
  • Loading branch information
realxinzhao committed Aug 8, 2023
1 parent b8b071a commit 39c759a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ IEA_EnergyBalances_2019.csv.gz


# FAOSTATA raw zip
inst/extdata/aglu/FAO/FAOSTAT/*.zip
inst/extdata/aglu/FAO/FAOSTAT/*.zip
inst/extdata/aglu/FAO/temp
paper
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Suggests:
rmarkdown
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
VignetteBuilder: knitr
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ importFrom(dplyr,summarize)
importFrom(dplyr,transmute)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(gcamdata,gather_years)
importFrom(ggplot2,aes)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_line)
Expand Down
4 changes: 1 addition & 3 deletions R/xfaostat_L201_Forestry.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ module_xfaostat_L201_Forestry <- function(command, ...) {
rm(FO_area, UnitMap, FO1, F01_Prod, FO1_Import_Q_V)


## Produce output and export CSV ----
GCAMDATA_FAOSTAT_ForProdTrade_215Regs_Roundwood_1973to2020 <-
For_Balance %>% filter(element != "Demand") %>%
spread(year, value)
Expand All @@ -175,7 +176,6 @@ module_xfaostat_L201_Forestry <- function(command, ...) {
FO1_Export_Q_V %>% spread(year, value)



GCAMDATA_FAOSTAT_ForProdTrade_215Regs_Roundwood_1973to2020 %>%
add_title("FAO forestry production, export, and import (roundwood total) by country_year") %>%
add_units("m3 ") %>%
Expand All @@ -189,8 +189,6 @@ module_xfaostat_L201_Forestry <- function(command, ...) {
GCAMDATA_FAOSTAT_ForExportPrice_214Regs_Roundwood_1973to2020


## Export CSV ----

if (OUTPUT_Export_CSV == T) {
output_csv_data(
"GCAMDATA_FAOSTAT_ForProdTrade_215Regs_Roundwood_1973to2020",
Expand Down
2 changes: 1 addition & 1 deletion R/xfaostat_L301_LandCover.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module_xfaostat_L301_LandCover <- function(command, ...) {
FAOSTAT_load_raw_data(DATASETCODE = "RL", DATA_FOLDER = DIR_RAW_DATA_FAOSTAT)

## Proprocess and quick clean ----
FF_summary("RL")
#FF_summary("RL")
RL %>% distinct(element, element_code, unit)
RL %>% distinct(area, area_code)
RL %>% distinct(item, item_code)
Expand Down
2 changes: 1 addition & 1 deletion R/xfaostat_L401_Fertilizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module_xfaostatL401_Fertilizer <- function(command, ...) {
FAOSTAT_load_raw_data(DATASETCODE = "RFN", DATA_FOLDER = DIR_RAW_DATA_FAOSTAT)

## Proprocess and quick clean ----
FF_summary("RFN")
#FF_summary("RFN")
RFN %>% distinct(element, element_code, unit)
RFN %>% distinct(area, area_code)
RFN %>% distinct(item, item_code)
Expand Down
8 changes: 4 additions & 4 deletions R/xfaostat_helper_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ FAO_AREA_RM_NONEXIST <- function(.DF,
#' @param COL_CNTY Country column name
#' @param COL_ITEM Item column name
#' @importFrom dplyr summarize
#' @importFrom gcamdata gather_years
#' @importFrom magrittr %>%
#'
#' @return A data frame with summary information,
Expand All @@ -228,7 +227,8 @@ FAO_AREA_RM_NONEXIST <- function(.DF,
FF_summary <- function(DF, COL_CNTY = "area", COL_ITEM = "item"){
assert_that(is.character(DF))

get(DF) %>% gcamdata::gather_years() -> .tbl1
get(DF) %>%
gather_years() -> .tbl1
list_out<- list(
dataset_code = DF,
ncountry = length(unique(.tbl1[COL_CNTY])%>% pull()),
Expand Down Expand Up @@ -271,7 +271,8 @@ FF_FILL_NUMERATOR_DENOMINATOR <- function(.DF, NUMERATOR_c, DENOMINATOR_c,
# setting NUMERATOR to NA if both prod and area are 0; it improves NUMERATOR interpolation
mutate(NUMERATOR = if_else(NUMERATOR == 0 & DENOMINATOR == 0, NA_real_, NUMERATOR)) %>%
# linearly interpolate NUMERATOR and fill in yield down-up
mutate(NUMERATOR = gcamdata::approx_fun(year, NUMERATOR)) %>%
mutate(NUMERATOR = approx_fun(year, NUMERATOR)) %>%
#mutate(NUMERATOR = gcamdata::approx_fun(year, NUMERATOR)) %>%
tidyr::fill(NUMERATOR, .direction = NUMERATOR_FILL_DIRECTION) %>%
tidyr::fill(Yield, .direction = "downup") %>%
ungroup() %>%
Expand Down Expand Up @@ -479,7 +480,6 @@ FAOSTAT_check_count_plot <- function(.DF, .ELEMENT = c()){
#' @param out_dir output directory
#' @param GZIP IF TRUE
#'
#' @return
#' @export

output_csv_data <- function(gcam_dataset, col_type_nonyear,
Expand Down
3 changes: 0 additions & 3 deletions man/output_csv_data.Rd

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

0 comments on commit 39c759a

Please sign in to comment.