Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZekeMarshall committed Dec 23, 2023
2 parents b7edc70 + 17e6a12 commit 685e464
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 132 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: MWTools
Title: Functions For Calculation of Muscle Work Within the PSUT Framework
Version: 0.2.6
Date: 2023-12-21
Version: 0.2.7
Date: 2023-12-23
Authors@R: c(person(given = "Zeke",
family = "Marshall",
role = c("aut", "cre"),
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ output: html_document
Cite all releases with doi [10.5281/zenodo.7584858](https://doi.org/10.5281/zenodo.7584858),
which always resolves to the latest release.

# MWTools 0.2.7 (2023-12-23) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.<>.svg)](https://doi.org/10.5281/zenodo.<>)

# MWTools 0.2.6 (2023-12-21)
* Fixing vignette.
* No new tests.
* Still at 453 tests, all passing.
* Test coverage remains at 100%.

# MWTools 0.2.6 (2023-12-21) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10420270.svg)](https://doi.org/10.5281/zenodo.10420270)

* Added a statement of need to the README file.
* Added a vignette, moving some example code
Expand Down
2 changes: 1 addition & 1 deletion R/calc_amw_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ tidy_fao_live_animals <- function(.df,
values_from = dplyr::all_of(value_fao_col),
names_from = dplyr::all_of(item_fao_col)) %>%
dplyr::mutate("{buffaloes}" := .data[[cattle_and_buffaloes]] - .data[[cattle]], .keep = "unused") |>
tidyr::pivot_longer(cols = buffaloes,
tidyr::pivot_longer(cols = dplyr::all_of(buffaloes),
names_to = item_fao_col,
values_to = value_fao_col)

Expand Down
6 changes: 4 additions & 2 deletions R/calc_hmw_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ prepareRawILOData <- function(ilo_working_hours_data, ilo_employment_data){
# Mean weekly hours actually worked per employed person by sex and economic activity:
# HOW_TEMP_SEX_ECO_NB_A
working_hours <- ilo_working_hours_data |>
dplyr::select("ref_area", "sex.label", "classif1.label", "time", "obs_value") |>
# dplyr::select("ref_area", "sex.label", "classif1.label", "time", "obs_value") |>
dplyr::select(dplyr::all_of(c("ref_area", "sex.label", "classif1.label", "time", "obs_value"))) |>
magrittr::set_colnames(c(country_code_col, sex_ilo_col, sector_col, year_col, yearly_working_hours_ilo_col))

# Employment by sex and economic activity (thousands): EMP_TEMP_SEX_ECO_NB_A
employment <- ilo_employment_data |>
dplyr::select("ref_area", "sex.label", "classif1.label", "time", "obs_value") |>
# dplyr::select("ref_area", "sex.label", "classif1.label", "time", "obs_value") |>
dplyr::select(dplyr::all_of(c("ref_area", "sex.label", "classif1.label", "time", "obs_value"))) |>
magrittr::set_colnames(c(country_code_col, sex_ilo_col, sector_col, year_col, employed_persons_ilo_col))

# Convert Employed persons [1000 persons] to employed persons [persons] and
Expand Down
49 changes: 0 additions & 49 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,6 @@ You can install this package from [GitHub](https://github.com/) with:
devtools::install_github("EnergyEconomyDecoupling/MWTools")
```

<!-- ## Examples -->

<!-- ### Animal Muscle Work -->

<!-- Raw data for the estimation of animal muscle work is obtained from the Food and Agriculture Organisation of the United Nations Statistical Database (FAOSTAT), via the `R` package `FAOSTAT`. The `MWTools` package provides a wrapper function for downloading data for the number of live animals, `down_fao_live_animals`, which utilises the function `FAOSTAT::get_faostat_bulk()`. Once downloaded `MWTools` provides a number of functions for the calculation of the number of working animals by species, country, year and in agriculture, transport, and in total. -->

<!-- The helper function `calc_amw_pfu` returns a tidy data frame containing data for the primary, final, and useful energy by species, country, year and in agriculture, transport, and in total. -->

<!-- ```{r get_example_data} -->
<!-- library(MWTools) -->

<!-- fao_fp <- PFUSetup::get_abs_paths(version = "v1.2")$fao_data_path -->

<!-- fao_raw_rds <- readr::read_rds(file = fao_fp) -->

<!-- amw_pfu_data <- calc_amw_pfu(.df = fao_raw_rds, -->
<!-- concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path, -->
<!-- amw_analysis_data_path = PFUSetup::get_abs_paths()$amw_analysis_data_path) -->

<!-- head(amw_pfu_data) -->

<!-- ``` -->

<!-- ### Human Muscle Work -->

<!-- Raw data for the estimation of human muscle work is obtained from the International Labor Organisation (ILO), via the `R` package `Rilostat`. The `MWTools` package includes bundled ILO data for the number of employed persons by sector and mean number of working hours by sector. -->

<!-- Using data for the number of employed persons and mean yearly working hours the primary, final, and useful energy associated with human muscle work can be estimated using the helper function `MWTools::calc_hmw_pfu`. -->

<!-- ``` {r hmw_pfu} -->
<!-- library(MWTools) -->

<!-- ilo_working_hours_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_working_hours_data_path) -->
<!-- ilo_employment_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_employment_data_path) -->

<!-- preparedILOData <- prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data, -->
<!-- ilo_employment_data = ilo_employment_data) -->

<!-- hmw_pfu_data <- calc_hmw_pfu(.df = preparedILOData, -->
<!-- concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path, -->
<!-- hmw_analysis_data_path = PFUSetup::get_abs_paths()$hmw_analysis_data_path) -->

<!-- head(hmw_pfu_data) -->
<!-- ``` -->

<!-- ### PSUT matrices -->

<!-- PFU data can be converted to PSUT matrices using `prep_psut()`. -->


## More Information

Expand Down
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,6 @@ You can install this package from [GitHub](https://github.com/) with:
devtools::install_github("EnergyEconomyDecoupling/MWTools")
```

<!-- ## Examples -->
<!-- ### Animal Muscle Work -->
<!-- Raw data for the estimation of animal muscle work is obtained from the Food and Agriculture Organisation of the United Nations Statistical Database (FAOSTAT), via the `R` package `FAOSTAT`. The `MWTools` package provides a wrapper function for downloading data for the number of live animals, `down_fao_live_animals`, which utilises the function `FAOSTAT::get_faostat_bulk()`. Once downloaded `MWTools` provides a number of functions for the calculation of the number of working animals by species, country, year and in agriculture, transport, and in total. -->
<!-- The helper function `calc_amw_pfu` returns a tidy data frame containing data for the primary, final, and useful energy by species, country, year and in agriculture, transport, and in total. -->
<!-- ```{r get_example_data} -->
<!-- library(MWTools) -->
<!-- fao_fp <- PFUSetup::get_abs_paths(version = "v1.2")$fao_data_path -->
<!-- fao_raw_rds <- readr::read_rds(file = fao_fp) -->
<!-- amw_pfu_data <- calc_amw_pfu(.df = fao_raw_rds, -->
<!-- concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path, -->
<!-- amw_analysis_data_path = PFUSetup::get_abs_paths()$amw_analysis_data_path) -->
<!-- head(amw_pfu_data) -->
<!-- ``` -->
<!-- ### Human Muscle Work -->
<!-- Raw data for the estimation of human muscle work is obtained from the International Labor Organisation (ILO), via the `R` package `Rilostat`. The `MWTools` package includes bundled ILO data for the number of employed persons by sector and mean number of working hours by sector. -->
<!-- Using data for the number of employed persons and mean yearly working hours the primary, final, and useful energy associated with human muscle work can be estimated using the helper function `MWTools::calc_hmw_pfu`. -->
<!-- ``` {r hmw_pfu} -->
<!-- library(MWTools) -->
<!-- ilo_working_hours_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_working_hours_data_path) -->
<!-- ilo_employment_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_employment_data_path) -->
<!-- preparedILOData <- prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data, -->
<!-- ilo_employment_data = ilo_employment_data) -->
<!-- hmw_pfu_data <- calc_hmw_pfu(.df = preparedILOData, -->
<!-- concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path, -->
<!-- hmw_analysis_data_path = PFUSetup::get_abs_paths()$hmw_analysis_data_path) -->
<!-- head(hmw_pfu_data) -->
<!-- ``` -->
<!-- ### PSUT matrices -->
<!-- PFU data can be converted to PSUT matrices using `prep_psut()`. -->

## More Information

Find more information, including vignettes and function documentation,
Expand Down
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ citEntry(entry = "Manual",
title = "MWTools: Functions For Calculation of Muscle Work Within the PSUT Framework",
author = personList(as.person("Zeke Marshall"), as.person("Matthew Kuperus Heun")),
year = "2023",
note = "R package version 0.2.6",
note = "R package version 0.2.7",
url = "https://doi.org/10.5281/zenodo.7584858",

textVersion =
paste("Zeke Marshall and Matthew Kuperus Heun (2023).",
"MWTools: Functions For Calculation of Muscle Work Within the PSUT Framework.",
"R package version 0.2.6.",
"R package version 0.2.7.",
"https://doi.org/10.5281/zenodo.7584858")
)
97 changes: 52 additions & 45 deletions vignettes/MWTools.Rmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: "IEATools"
title: "MWTools"
output: rmarkdown::html_vignette
bibliography: References.bib
vignette: >
%\VignetteIndexEntry{IEATools}
%\VignetteIndexEntry{MWTools}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down Expand Up @@ -35,75 +35,82 @@ Computational tools are needed to gather and shape relevant data.
The examples below show how to use `MWTools` to address
the needs described above.


## Examples

### Animal Muscle Work

Raw data for the estimation of animal muscle work
is obtained from the Food and Agriculture Organisation
of the United Nations Statistical Database (FAOSTAT),
via the `R` package `FAOSTAT`.
The `MWTools` package provides a wrapper function
for downloading data for the number of live animals,
`down_fao_live_animals()`, which utilises the function `FAOSTAT::get_faostat_bulk()`.
Once downloaded, `MWTools` provides a number of functions
for the calculation of the number of working animals
by species, country, year and in agriculture, transport, and in total.

The helper function `calc_amw_pfu()` returns a tidy data frame
containing data for the primary, final, and useful energy
by species, country, year and in agriculture, transport, and in total.

```{r get_example_data}
library(MWTools)
Raw data for the estimation of animal muscle work is obtained from the Food and
Agriculture Organisation of the United Nations Statistical Database (FAOSTAT),
via the `R` package `FAOSTAT` as follows.

fao_fp <- PFUSetup::get_abs_paths(version = "v1.2")$fao_data_path
```{r down_amw_example, eval = FALSE}
raw_amw_data <- FAOSTAT::get_faostat_bulk(code = "QCL", data_folder = tempdir())
```

fao_raw_rds <- readr::read_rds(file = fao_fp)
The helper function `calc_amw_pfu` returns a tidy data frame containing data for
the primary, final, and useful energy by species, country, year and in
the agriculture, transport, and total sectors.

amw_pfu_data <- calc_amw_pfu(.df = fao_raw_rds,
concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path,
amw_analysis_data_path = PFUSetup::get_abs_paths()$amw_analysis_data_path)
```{r calc_amw_example}
test_amw_data <- read.csv(file = MWTools::amw_test_data_path())
head(amw_pfu_data)
amw_pfu_data <- MWTools::calc_amw_pfu(.df = test_amw_data,
concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path,
amw_analysis_data_path = PFUSetup::get_abs_paths()$amw_analysis_data_path)
```

```{r amw_example_glimpse, echo=FALSE}
tibble::glimpse(amw_pfu_data)
```

### Human Muscle Work

Raw data for the estimation of human muscle work
is obtained from the International Labor Organisation (ILO),
via the `R` package `Rilostat`.
The `MWTools` package includes bundled ILO data for the number of employed persons by sector and mean number of working hours by sector.
Raw data for the estimation of human muscle work is obtained from the
International Labor Organisation (ILO), via the `R` package `Rilostat` as
follows:

Using data for the number of employed persons and
mean yearly working hours,
the primary, final, and useful energy associated
with human muscle work can be estimated
using the helper function `calc_hmw_pfu()`.
```{r down_hmw_example, eval = FALSE}
ilo_working_hours_data <- Rilostat::get_ilostat(id = MWTools::ilo_codes$working_hours_code,
quiet = TRUE) |>
Rilostat::label_ilostat(code = c("ref_area"))
``` {r hmw_pfu}
library(MWTools)
ilo_employment_data <- Rilostat::get_ilostat(id = MWTools::ilo_codes$employment_code,
quiet = TRUE) |>
Rilostat::label_ilostat(code = c("ref_area"))
```

ilo_working_hours_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_working_hours_data_path)
ilo_employment_data <- readr::read_rds(file = PFUSetup::get_abs_paths(version = "v1.2")$ilo_employment_data_path)
Using data for the number of employed persons and mean yearly working hours the
primary, final, and useful energy associated with human muscle work can be
estimated using the helper function `MWTools::calc_hmw_pfu` as below.

preparedILOData <- prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data,
ilo_employment_data = ilo_employment_data)
``` {r calc_hmw_example}
ilo_working_hours_data <- read.csv(file = MWTools::ilo_working_hours_test_data_path())
ilo_employment_data <- read.csv(file = MWTools::ilo_employment_test_data_path())
hmw_pfu_data <- calc_hmw_pfu(.df = preparedILOData,
concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path,
hmw_analysis_data_path = PFUSetup::get_abs_paths()$hmw_analysis_data_path)
preparedILOData <- MWTools::prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data,
ilo_employment_data = ilo_employment_data)
head(hmw_pfu_data)
hmw_pfu_data <- MWTools::calc_hmw_pfu(.df = preparedILOData,
concordance_path = PFUSetup::get_abs_paths()$mw_concordance_path,
hmw_analysis_data_path = PFUSetup::get_abs_paths()$hmw_analysis_data_path)
```

```{r hmw_example_glimpse, echo=FALSE}
tibble::glimpse(hmw_pfu_data)
```

### PSUT matrices

PFU data can be converted to PSUT matrices using `prep_psut()`.

```{r prep_psut_example}
mw_psut <- MWTools::prep_psut(.hmw_df = hmw_pfu_data,
.amw_df = amw_pfu_data)
```

```{r psut_example_glimpse, echo=FALSE}
tibble::glimpse(mw_psut)
```

## Conclusion

Expand Down

0 comments on commit 685e464

Please sign in to comment.