@@ -21,13 +21,13 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
21
21
c(FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_SUA_PrimaryEquivalent" ),
22
22
FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_SUA_ItemCode" ),
23
23
FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_FAO_iso_reg" ),
24
- FILE = file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_SUA_ItemCode" ),
25
24
" L105.Bal_new_all" ,
26
25
" L107.Traceable_FBS_PCe_2010Plus" ,
27
26
" L107.Traceable_FBS_Food_Calorie_Macronutrient_2010Plus" )
28
27
29
28
MODULE_OUTPUTS <-
30
29
c(CSV = " Metadata_GCAMFAOSTAT_Traceable_FBS" ,
30
+ CSV = " Nested_Mapping_SUA_To_Traceable_FBS" ,
31
31
CSV = " SUA_2010_2022" ,
32
32
CSV = " SUA_Food_Calorie_Macronutrient_2010_2022" ,
33
33
CSV = " Traceable_FBS_PCe_2010_2022" ,
@@ -58,27 +58,72 @@ module_yfaostat_Traceable_FBS_DataExport <- function(command, ...) {
58
58
# Helper functions ----
59
59
Metadata_GCAMFAOSTAT_Traceable_FBS <- NULL
60
60
add_to_output_meta <- function (.df ,
61
- .datasetname ){
62
-
63
- .df %> % gather_years() - > .df
64
- if (" year" %in% names(.df )) {
65
- YearRange = paste0(.df %> % distinct(year ) %> % min ," to " , .df %> % distinct(year ) %> % max )
66
- } else {
67
- YearRange = " BaseYears"
61
+ .datasetname ,
62
+ .skip_stat = FALSE ){
63
+
64
+ if (.skip_stat == FALSE ) {
65
+
66
+ .df %> % gather_years() - > .df
67
+ if (" year" %in% names(.df )) {
68
+ YearRange = paste0(.df %> % distinct(year ) %> % min ," to " , .df %> % distinct(year ) %> % max )
69
+ } else {
70
+ YearRange = " BaseYears"
71
+ }
72
+
73
+ Metadata_GCAMFAOSTAT_Traceable_FBS %> %
74
+ bind_rows(
75
+ data.frame (dataset = .datasetname ,
76
+ nReg = .df %> % distinct(iso ) %> % nrow ,
77
+ nItem = .df %> % distinct(item ) %> % nrow ,
78
+ Years = YearRange )
79
+ ) - > .df1
80
+ } else {
81
+
82
+ Metadata_GCAMFAOSTAT_Traceable_FBS %> %
83
+ bind_rows(
84
+ data.frame (dataset = .datasetname )
85
+ ) - > .df1
68
86
}
69
87
70
- Metadata_GCAMFAOSTAT_Traceable_FBS %> %
71
- bind_rows(
72
- data.frame (dataset = .datasetname ,
73
- nReg = .df %> % distinct(iso ) %> % nrow ,
74
- nItem = .df %> % distinct(item ) %> % nrow ,
75
- Years = YearRange )
76
- ) - > .df1
77
-
78
88
assign(" Metadata_GCAMFAOSTAT_Traceable_FBS" , .df1 , envir = Curr_Envir )
79
89
}
80
90
81
91
92
+ # * Mapping_PrimaryEquivalent_nested_SUA ----
93
+
94
+ Mapping_gcamdata_SUA_PrimaryEquivalent %> %
95
+ transmute(aggregated_PCe_item = APE_comm_Agg , PCe_item = APE_comm ,
96
+ nest_level , source_item0 = source_item , sink_item0 = sink_item ) %> %
97
+ distinct() %> %
98
+ left_join_error_no_match(
99
+ Mapping_gcamdata_SUA_ItemCode %> %
100
+ distinct(source_item0 = item , source_item_code = item_code , source_item = item_new_2024 ), by = " source_item0" ) %> %
101
+ left_join_error_no_match(
102
+ Mapping_gcamdata_SUA_ItemCode %> %
103
+ distinct(sink_item0 = item , sink_item_code = item_code , sink_item = item_new_2024 ), by = " sink_item0" ) %> %
104
+ transmute(aggregated_PCe_item , PCe_item ,
105
+ nest_level , source_item , source_item_code , sink_item , sink_item_code ) %> %
106
+ add_title(" Nested_Mapping_SUA_To_Traceable_FBS" ) %> %
107
+ add_units(" none" ) %> %
108
+ add_comments(" gcamfaostat Export CSV" ) %> %
109
+ add_precursors(file.path(DIR_RAW_DATA_FAOSTAT , " Mapping_gcamdata_SUA_PrimaryEquivalent" )) - >
110
+ Nested_Mapping_SUA_To_Traceable_FBS
111
+
112
+ output_csv_data(
113
+ gcam_dataset = Nested_Mapping_SUA_To_Traceable_FBS ,
114
+ out_filename = " Nested_Mapping_SUA_To_Traceable_FBS" ,
115
+ col_type_nonyear = " ccicici" ,
116
+ title = " Mapping of SUA items to aggregated primary commodity equivalent products by level of nestings" ,
117
+ unit = " NA" ,
118
+ code = " NA" ,
119
+ description = " Data is compiled and generated by gcamfaostat." ,
120
+ out_dir = DIR_OUTPUT_CSV ,
121
+ GZIP = F )
122
+
123
+ add_to_output_meta(.df = Nested_Mapping_SUA_To_Traceable_FBS ,
124
+ " Nested_Mapping_SUA_To_Traceable_FBS" , .skip_stat = TRUE )
125
+
126
+
82
127
# Zeros were removed in all dataset in exporting to reduce size
83
128
# We updated item names to the latest when applicable
84
129
0 commit comments