Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHeun committed Jun 6, 2023
2 parents b77433f + 703640a commit c7984c6
Show file tree
Hide file tree
Showing 29 changed files with 288 additions and 81 deletions.
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
^PFUPipelinesTools\.Rproj$
^PFUPipelineTools\.Rproj$
^\.Rproj\.user$
^data-raw$
^LICENSE\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
^README\.Rmd$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
docs
19 changes: 13 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
Package: PFUPipelinesTools
Package: PFUPipelineTools
Title: Tools for PFU Pipelines
Version: 0.0.1
Version: 0.1.1
Date: 2023-06-06
Authors@R:
person("Matthew", "Heun", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
comment = c(ORCID = "0000-0002-7438-214X"))
Description: There are several repositories that provide PFU pipelines for the PFU databases.
Several functions can be used for all pipelines.
This package hosts all common functions and constants.
Several functions can be used in common across all pipelines.
This package hosts common functions and constants.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
assertthat
dplyr,
IEATools,
lubridate,
magrittr,
parsedate,
pins,
rlang
Depends:
R (>= 2.10)
LazyData: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2023
COPYRIGHT HOLDER: PFUPipelinesTools authors
COPYRIGHT HOLDER: PFUPipelineTools authors
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 PFUPipelinesTools authors
Copyright (c) 2023 PFUPipelineTools authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 7 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(":=")
export(.data)
export(filter_countries_years)
export(release_target)
export(stash_cache)
export(trim_pipeline)
export(tar_ungroup)
importFrom(magrittr,"%>%")
importFrom(rlang,":=")
importFrom(rlang,.data)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# PFUPipelineTools 0.1.1 (2023-06-06)

* Initial release
* Added a `NEWS.md` file to track changes to the package.
* Added first tests.
* Only 2 tests, both passing.
* Test coverage is low (17 %) but will improve.
File renamed without changes.
36 changes: 31 additions & 5 deletions R/data_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#' @export
#'
#' @examples
#' IEATools::sample_iea_data_path() %>%
#' IEATools::load_tidy_iea_df() %>%
#' IEATools::sample_iea_data_path() |>
#' IEATools::load_tidy_iea_df() |>
#' filter_countries_years(countries = c("ZAF"), years = 1960:1999)
filter_countries_years <- function(.df,
countries,
Expand All @@ -32,14 +32,40 @@ filter_countries_years <- function(.df,
}
if (countries1) {
if (countries == "all") {
return(.df %>% dplyr::filter(.data[[year]] %in% years))
return(.df |> dplyr::filter(.data[[year]] %in% years))
}
}
if (years1) {
if (years == "all") {
return(.df %>% dplyr::filter(.data[[country]] %in% countries))
return(.df |> dplyr::filter(.data[[country]] %in% countries))
}
}
.df %>%
.df |>
dplyr::filter(.data[[country]] %in% countries, .data[[year]] %in% years)
}


#' Ungroups and removes tar_group column from a data frame
#'
#' The [tarchetypes::tar_group_by()] function
#' adds a column named "tar_group".
#' This function ungroups and removes the special column.
#'
#' @param .df The data frame to be ungrouped.
#' @param tar_group_colname The name of the grouping column. Default is "tar_group".
#' @param ungroup A boolean that tells whether to ungroup `.df`. Default is `TRUE`.
#'
#' @return A modified version of `.df`.
#'
#' @export
tar_ungroup <- function(.df, tar_group_colname = "tar_group", ungroup = TRUE) {
out <- .df |>
dplyr::mutate(
"{tar_group_colname}" := NULL
)
if (ungroup) {
out <- out |>
dplyr::ungroup()
}
return(out)
}
17 changes: 0 additions & 17 deletions R/how_far.R

This file was deleted.

16 changes: 8 additions & 8 deletions R/storing.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
#' # Establish the pinboard
#' pinboard <- pins::board_folder("~/Dropbox/Fellowship 1960-2015 PFU database/OutputData/PipelineReleases/")
#' # Get information about the `PSUT` target in the pinboard
#' pinboard %>%
#' pinboard |>
#' pins::pin_meta(name = "psut")
#' # Find versions of the `PSUT` target
#' pinboard %>%
#' pinboard |>
#' pins::pin_versions(name = "psut")
#' # Get the latest copy of the `PSUT` target.
#' my_psut <- pinboard %>%
#' my_psut <- pinboard |>
#' pins::pin_read(name = "psut")
#' # Retrieve a previous version of the `PSUT` target.
#' my_old_psut <- pinboard %>%
#' my_old_psut <- pinboard |>
#' pins::pin_read(name = "psut", version = "20220218T023112Z-1d9e1")}
release_target <- function(pipeline_releases_folder, targ, pin_name, type = "rds", release = FALSE) {
if (release) {
# Establish the pinboard
out <- pins::board_folder(pipeline_releases_folder, versioned = TRUE) %>%
out <- pins::board_folder(pipeline_releases_folder, versioned = TRUE) |>
# Returns the fully-qualified name of the file written to the pinboard.
pins::pin_write(targ, name = pin_name, type = type, versioned = TRUE)
} else {
Expand Down Expand Up @@ -76,12 +76,12 @@ stash_cache <- function(pipeline_caches_folder, cache_folder, file_prefix, depen
return("Release not requested.")
}
# Zip the drake cache
zipped_cache_filename <- paste0(file_prefix, parsedate::format_iso_8601(Sys.time()), ".zip") %>%
zipped_cache_filename <- paste0(file_prefix, parsedate::format_iso_8601(Sys.time()), ".zip") |>
# Change file name format to be equivalent to the pins file format.
# Eliminate "-" characters
gsub(pattern = "-", replacement = "") %>%
gsub(pattern = "-", replacement = "") |>
# Eliminate ":" characters, because they cause problems on some OSes.
gsub(pattern = ":", replacement = "") %>%
gsub(pattern = ":", replacement = "") |>
# Change "+0000" to "Z", where "Z" means Zulu time (GMT offset of 00:00)
gsub(pattern = "\\+0000", replacement = "Z")
invisible(utils::zip(zipfile = zipped_cache_filename, files = cache_folder, extras = "-q"))
Expand Down
11 changes: 11 additions & 0 deletions R/utils-.data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Data pronoun
#'
#' See [rlang::.data] for details.
#'
#' @name .data
#' @rdname data
#' @keywords internal
#' @export
#' @importFrom rlang .data
#' @usage .data
NULL
11 changes: 11 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL
11 changes: 11 additions & 0 deletions R/utils-qqassign.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Assignment
#'
#' See \code{rlang::\link[rlang]{:=}} for details.
#'
#' @name :=
#' @rdname quasi-quote-assign
#' @keywords internal
#' @export
#' @importFrom rlang :=
#' @usage x := y
NULL
49 changes: 49 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
output: github_document
---

<!-- *********** -->
<!-- Note: README.md is generated from README.Rmd. -->
<!-- Be sure to edit README.Rmd and generate the README.md file by Cmd/Ctl-shift-K -->
<!-- *********** -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# PFUPipelineTools


<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/Recca)](https://cran.r-project.org/package=Recca)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/EnergyEconomyDecoupling/PFUPipelineTools/workflows/R-CMD-check/badge.svg)](https://github.com/EnergyEconomyDecoupling/PFUPipelineTools/actions)
[![Codecov test coverage](https://codecov.io/gh/EnergyEconomyDecoupling/PFUPipelineTools/branch/master/graph/badge.svg)](https://app.codecov.io/gh/EnergyEconomyDecoupling/PFUPipelineTools?branch=main)
<!-- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5226085.svg)](https://doi.org/10.5281/zenodo.5226085) -->
<!-- badges: end -->


PFUPipelineTools provides a single package for several functions
that are used across various PFU pipelines.


## Installation

You can install the development version of PFUPipelineTools from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("EnergyEconomyDecoupling/PFUPipelineTools")
```


## More Information

Find more information, including vignettes and function documentation, at
<https://MatthewHeun.github.io/PFUPipelineTools/>.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

<!-- *********** -->
<!-- Note: README.md is generated from README.Rmd. -->
<!-- Be sure to edit README.Rmd and generate the README.md file by Cmd/Ctl-shift-K -->
<!-- *********** -->

# PFUPipelineTools

<!-- badges: start -->

[![CRAN
status](https://www.r-pkg.org/badges/version/Recca)](https://cran.r-project.org/package=Recca)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/EnergyEconomyDecoupling/PFUPipelineTools/workflows/R-CMD-check/badge.svg)](https://github.com/EnergyEconomyDecoupling/PFUPipelineTools/actions)
[![Codecov test
coverage](https://codecov.io/gh/EnergyEconomyDecoupling/PFUPipelineTools/branch/master/graph/badge.svg)](https://app.codecov.io/gh/EnergyEconomyDecoupling/PFUPipelineTools?branch=main)
<!-- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5226085.svg)](https://doi.org/10.5281/zenodo.5226085) -->
<!-- badges: end -->

PFUPipelineTools provides a single package for several functions that
are used across various PFU pipelines.

## Installation

You can install the development version of PFUPipelineTools from
[GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("EnergyEconomyDecoupling/PFUPipelineTools")
```

## More Information

Find more information, including vignettes and function documentation,
at <https://MatthewHeun.github.io/PFUPipelineTools/>.
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
template:
bootstrap: 5
bootswatch: sandstone
1 change: 0 additions & 1 deletion data-raw/create_constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# If there are any changes to these constants,
# source this script before building the package.

library(magrittr)
library(IEATools)

#
Expand Down
15 changes: 15 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
citHeader("To cite PFUPipelineTools in publications use:")

citEntry(entry = "Manual",
title = "PFUPipelineTools: Tools for PFU Pipelines",
author = personList(as.person("Matthew Kuperus Heun")),
year = "2023",
note = "R package version 0.1.1",
url = "https://github.com/EnergyEconomyDecoupling/PFUAggDatabase",

textVersion =
paste("Matthew Kuperus Heun (2023).",
"PFUAggWorkflow: Calculate Aggregations and Efficiencies For Energy Conversion Chains in PSUT Format",
"R package version 0.1.1.",
"https://github.com/EnergyEconomyDecoupling/PFUAggDatabase")
)
12 changes: 12 additions & 0 deletions man/data.Rd

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

4 changes: 2 additions & 2 deletions man/filter_countries_years.Rd

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

12 changes: 12 additions & 0 deletions man/pipe.Rd

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

Loading

0 comments on commit c7984c6

Please sign in to comment.