Skip to content

Commit 8b7d904

Browse files
committed
Complete docs and fix tests
1 parent 3f579f7 commit 8b7d904

5 files changed

Lines changed: 56 additions & 13 deletions

File tree

R/input_files.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ get_file_path <- function(file_alias, force_download = FALSE) {
9494
}
9595

9696
.fetch_file_info <- function(file_alias) {
97-
file_info <- dplyr::filter(.get_input_files_data(), alias == file_alias)
97+
input_files <- .read_local_csv("input/raw/input_files.csv")
98+
file_info <- dplyr::filter(input_files, alias == file_alias)
9899

99100
if (nrow(file_info) == 0) {
100101
stop(stringr::str_glue("There is no file entry with alias {file_alias}"))
@@ -114,8 +115,8 @@ get_file_path <- function(file_alias, force_download = FALSE) {
114115
c(file_info)
115116
}
116117

117-
.get_input_files_data <- function() {
118+
.read_local_csv <- function(csv_path) {
118119
"extdata" |>
119-
system.file("input/raw/input_files.csv", package = utils::packageName()) |>
120+
system.file(csv_path, package = utils::packageName()) |>
120121
readr::read_csv(show_col_types = FALSE)
121122
}

R/supply_use.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
#' It contains the following columns:
1414
#' - `year`: The year in which the recorded event occurred.
1515
#' - `area`: The name of the country where the data is from.
16-
#' - `area_code`: FAOSTAT internal code for each country. Equivalences
17-
#' with ISO 3166-1 numeric can be found in the _Area Codes_ CSV from the
18-
#' zip file that can be downloaded from
19-
#' [FAOSTAT](https://www.fao.org/faostat/en/#data/FBS). TODO: Think about
20-
#' this, would be nice to use ISO3 codes but won't be enough for our periods
21-
#' - `item`: Natural language name for the item.
22-
#' - `item_code`: FAOSTAT internal code for each item.
16+
#' - `proc`: Natural language name of the process taking place.
17+
#' - `item`: Natural language name of the item taking part in the process.
18+
#' - `type`: Can have two values:
19+
#' - `use`: The given item is an input of the process.
20+
#' - `supply`: The given item is an output of the process.
21+
#' - `value`: Quantity in tonnes.
2322
#'
2423
#' @export
2524
#'

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,36 @@
22
utils::globalVariables(
33
c(
44
"alias",
5+
"area",
56
"area_code",
67
"area_code_p",
78
"balanced_export",
89
"balanced_import",
910
"bilateral_trade",
1011
"cf",
12+
"domestic_supply",
1113
"element",
1214
"Element",
1315
"export",
16+
"final_value_processed",
1417
"from_code",
1518
"import",
1619
"Imp/Exp",
1720
"Info_Format",
1821
"item",
1922
"Item",
2023
"item_code",
24+
"item_code_to_process",
25+
"item_processed",
26+
"item_to_process",
2127
"Name",
2228
"No",
29+
"proc",
2330
"processeditem",
2431
"product_fraction",
2532
"SACO_link",
2633
"scaling",
34+
"seed",
2735
"sex",
2836
"stock_variation",
2937
"Timeline_End",
@@ -34,11 +42,13 @@ utils::globalVariables(
3442
"total_trade",
3543
"to_code",
3644
"Trade",
45+
"type",
3746
"unit",
3847
"value",
3948
"Value",
4049
"value_proc",
4150
"value_proc_raw",
51+
"value_to_process",
4252
"year",
4353
"Year"
4454
)

man/build_supply_use.Rd

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_input_files.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
testthat::test_that("get_file_path fails for non-existent file_alias", {
22
testthat::local_mocked_bindings(
3-
.get_input_files_data = function(...) {
3+
.read_local_csv = function(...) {
44
dplyr::tribble(
55
~extension, ~alias, ~drive_file_id,
66
"csv", "file_alias_1", "some_id"
@@ -18,7 +18,7 @@ testthat::test_that(
1818
"get_file_path fails for duplicated entries only in filtered rows",
1919
{
2020
testthat::local_mocked_bindings(
21-
.get_input_files_data = function(...) {
21+
.read_local_csv = function(...) {
2222
dplyr::tribble(
2323
~extension, ~alias, ~drive_file_id,
2424
"csv", "file_alias_1", "some_id",
@@ -52,7 +52,7 @@ testthat::test_that(
5252
testthat::expect_false(file.exists(destfile))
5353

5454
testthat::local_mocked_bindings(
55-
.get_input_files_data = function(...) {
55+
.read_local_csv = function(...) {
5656
dplyr::tribble(
5757
~extension, ~alias, ~drive_file_id,
5858
"csv", file_alias, "some_id",

0 commit comments

Comments
 (0)