From 87dd59762b7310f25c6a0d83e47a6a3961578d8e Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Mon, 29 May 2023 15:53:26 -0400 Subject: [PATCH 01/11] Better tests. --- R/how_far.R | 7 ++++++- man/trim_pipeline.Rd | 6 ++++-- tests/testthat/test-how_far.R | 8 ++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/R/how_far.R b/R/how_far.R index ba7ae95..4fc048a 100644 --- a/R/how_far.R +++ b/R/how_far.R @@ -6,11 +6,16 @@ #' #' @param .pipeline The pipeline to trim. A list. #' @param last_target_to_keep The last target to keep in the pipeline. +#' If "all_targets" (the default), +#' everything is returned. #' #' @return `.pipeline` with targets _after_ `last_target_to_keep` removed. #' #' @export -trim_pipeline <- function(.pipeline, last_target_to_keep) { +trim_pipeline <- function(.pipeline, last_target_to_keep = "all_targets") { + if (last_target_to_keep == "all_targets") { + return(.pipeline) + } last_index_to_keep <- which(names(.pipeline) == last_target_to_keep) assertthat::assert_that(length(last_index_to_keep) == 1) .pipeline[1:last_index_to_keep] diff --git a/man/trim_pipeline.Rd b/man/trim_pipeline.Rd index e44a4d9..3f19536 100644 --- a/man/trim_pipeline.Rd +++ b/man/trim_pipeline.Rd @@ -4,12 +4,14 @@ \alias{trim_pipeline} \title{Trim a pipeline to desired length} \usage{ -trim_pipeline(.pipeline, last_target_to_keep) +trim_pipeline(.pipeline, last_target_to_keep = "all_targets") } \arguments{ \item{.pipeline}{The pipeline to trim. A list.} -\item{last_target_to_keep}{The last target to keep in the pipeline.} +\item{last_target_to_keep}{The last target to keep in the pipeline. +If "all_targets" (the default), +everything is returned.} } \value{ \code{.pipeline} with targets \emph{after} \code{last_target_to_keep} removed. diff --git a/tests/testthat/test-how_far.R b/tests/testthat/test-how_far.R index 7f9f9d9..05a83b8 100644 --- a/tests/testthat/test-how_far.R +++ b/tests/testthat/test-how_far.R @@ -8,4 +8,12 @@ test_that("trim_pipeline() works as expected", { test_targets_2 |> trim_pipeline(last_target_to_keep = "A") |> expect_error("length\\(last_index_to_keep\\) not equal to 1") + + test_targets_2 |> + trim_pipeline(last_target_to_keep = "C") |> + expect_equal(list(A = 1, A = 2, C = 3)) + + test_targets_2 |> + trim_pipeline() |> + expect_equal(list(A = 1, A = 2, C = 3)) }) From 3e79f8532bdd52935a02dfad890acb022abcd268 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Mon, 29 May 2023 16:52:15 -0400 Subject: [PATCH 02/11] Debugging. --- DESCRIPTION | 3 ++- R/how_far.R | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6bdbedf..0348e65 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,8 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Imports: - assertthat + assertthat, + targets Depends: R (>= 2.10) LazyData: true diff --git a/R/how_far.R b/R/how_far.R index 4fc048a..75d3276 100644 --- a/R/how_far.R +++ b/R/how_far.R @@ -16,7 +16,7 @@ trim_pipeline <- function(.pipeline, last_target_to_keep = "all_targets") { if (last_target_to_keep == "all_targets") { return(.pipeline) } - last_index_to_keep <- which(names(.pipeline) == last_target_to_keep) + last_index_to_keep <- which(targets::tar_names(.pipeline) == last_target_to_keep) assertthat::assert_that(length(last_index_to_keep) == 1) .pipeline[1:last_index_to_keep] } From 60f49c15524b51f27ae2b6c8f519bde1d670d9c7 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 30 May 2023 08:41:37 -0400 Subject: [PATCH 03/11] Eliminate the how_far function. --- NAMESPACE | 1 - R/how_far.R | 22 ---------------------- man/trim_pipeline.Rd | 23 ----------------------- tests/testthat/test-how_far.R | 19 ------------------- 4 files changed, 65 deletions(-) delete mode 100644 R/how_far.R delete mode 100644 man/trim_pipeline.Rd delete mode 100644 tests/testthat/test-how_far.R diff --git a/NAMESPACE b/NAMESPACE index 02f4272..d2599cc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,4 +3,3 @@ export(filter_countries_years) export(release_target) export(stash_cache) -export(trim_pipeline) diff --git a/R/how_far.R b/R/how_far.R deleted file mode 100644 index 75d3276..0000000 --- a/R/how_far.R +++ /dev/null @@ -1,22 +0,0 @@ -#' Trim a pipeline to desired length -#' -#' When constructing pipelines, -#' it can be desirable to keep only a few of the targets. -#' This function trims the pipeline to the last desired target.#' -#' -#' @param .pipeline The pipeline to trim. A list. -#' @param last_target_to_keep The last target to keep in the pipeline. -#' If "all_targets" (the default), -#' everything is returned. -#' -#' @return `.pipeline` with targets _after_ `last_target_to_keep` removed. -#' -#' @export -trim_pipeline <- function(.pipeline, last_target_to_keep = "all_targets") { - if (last_target_to_keep == "all_targets") { - return(.pipeline) - } - last_index_to_keep <- which(targets::tar_names(.pipeline) == last_target_to_keep) - assertthat::assert_that(length(last_index_to_keep) == 1) - .pipeline[1:last_index_to_keep] -} diff --git a/man/trim_pipeline.Rd b/man/trim_pipeline.Rd deleted file mode 100644 index 3f19536..0000000 --- a/man/trim_pipeline.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/how_far.R -\name{trim_pipeline} -\alias{trim_pipeline} -\title{Trim a pipeline to desired length} -\usage{ -trim_pipeline(.pipeline, last_target_to_keep = "all_targets") -} -\arguments{ -\item{.pipeline}{The pipeline to trim. A list.} - -\item{last_target_to_keep}{The last target to keep in the pipeline. -If "all_targets" (the default), -everything is returned.} -} -\value{ -\code{.pipeline} with targets \emph{after} \code{last_target_to_keep} removed. -} -\description{ -When constructing pipelines, -it can be desirable to keep only a few of the targets. -This function trims the pipeline to the last desired target.#' -} diff --git a/tests/testthat/test-how_far.R b/tests/testthat/test-how_far.R deleted file mode 100644 index 05a83b8..0000000 --- a/tests/testthat/test-how_far.R +++ /dev/null @@ -1,19 +0,0 @@ -test_that("trim_pipeline() works as expected", { - test_targets <- list(A = 1, B = 2, C = 3) - test_targets |> - trim_pipeline(last_target_to_keep = "B") |> - expect_equal(list(A = 1, B = 2)) - - test_targets_2 <- list(A = 1, A = 2, C = 3) - test_targets_2 |> - trim_pipeline(last_target_to_keep = "A") |> - expect_error("length\\(last_index_to_keep\\) not equal to 1") - - test_targets_2 |> - trim_pipeline(last_target_to_keep = "C") |> - expect_equal(list(A = 1, A = 2, C = 3)) - - test_targets_2 |> - trim_pipeline() |> - expect_equal(list(A = 1, A = 2, C = 3)) -}) From f19fef779d92aed5e6f1fea345b00df7f2d54b9a Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 30 May 2023 08:44:19 -0400 Subject: [PATCH 04/11] Change name --- PFUPipelinesTools.Rproj => PFUPipelineTools.Rproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PFUPipelinesTools.Rproj => PFUPipelineTools.Rproj (100%) diff --git a/PFUPipelinesTools.Rproj b/PFUPipelineTools.Rproj similarity index 100% rename from PFUPipelinesTools.Rproj rename to PFUPipelineTools.Rproj From 94de1f0f2f1f02bdfddcc628608d7c5ee3d3cc8d Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 30 May 2023 08:46:00 -0400 Subject: [PATCH 05/11] Pipelines --> Pipeline --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0348e65..b169a13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: PFUPipelinesTools +Package: PFUPipelineTools Title: Tools for PFU Pipelines Version: 0.0.1 Authors@R: From c0453808bfdfa412b0dc4ca67cb4981902e4ae3b Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Wed, 31 May 2023 08:20:49 -0400 Subject: [PATCH 06/11] New tar_ungroup() function --- NAMESPACE | 1 + R/data_functions.R | 26 ++++++++++++++++++++++++++ man/tar_ungroup.Rd | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 man/tar_ungroup.Rd diff --git a/NAMESPACE b/NAMESPACE index d2599cc..3feb41a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,3 +3,4 @@ export(filter_countries_years) export(release_target) export(stash_cache) +export(tar_ungroup) diff --git a/R/data_functions.R b/R/data_functions.R index d7c78fd..956d408 100644 --- a/R/data_functions.R +++ b/R/data_functions.R @@ -43,3 +43,29 @@ filter_countries_years <- function(.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) +} diff --git a/man/tar_ungroup.Rd b/man/tar_ungroup.Rd new file mode 100644 index 0000000..b270389 --- /dev/null +++ b/man/tar_ungroup.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data_functions.R +\name{tar_ungroup} +\alias{tar_ungroup} +\title{Ungroups and removes tar_group column from a data frame} +\usage{ +tar_ungroup(.df, tar_group_colname = "tar_group", ungroup = TRUE) +} +\arguments{ +\item{.df}{The data frame to be ungrouped.} + +\item{tar_group_colname}{The name of the grouping column. Default is "tar_group".} + +\item{ungroup}{A boolean that tells whether to ungroup \code{.df}. Default is \code{TRUE}.} +} +\value{ +A modified version of \code{.df}. +} +\description{ +The \code{\link[tarchetypes:tar_group_by]{tarchetypes::tar_group_by()}} function +adds a column named "tar_group". +This function ungroups and removes the special column. +} From 20e3eecdf3c2d5a7da7153b47f80b2e347ab143a Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 6 Jun 2023 08:38:06 -0400 Subject: [PATCH 07/11] Add NEWS file. --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..398f70d --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# PFUPipelineTools 0.0.1 + +* Added a `NEWS.md` file to track changes to the package. From 51f1863146c61e5fee42e55528dbe4a75f7804d5 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 6 Jun 2023 08:54:35 -0400 Subject: [PATCH 08/11] Added first tests. --- .Rbuildignore | 2 +- DESCRIPTION | 9 +++++++-- LICENSE | 2 +- LICENSE.md | 2 +- NAMESPACE | 6 ++++++ R/data_functions.R | 10 +++++----- R/storing.R | 16 ++++++++-------- R/utils-.data.R | 11 +++++++++++ R/utils-pipe.R | 11 +++++++++++ R/utils-qqassign.R | 11 +++++++++++ data-raw/create_constants.R | 1 - man/data.Rd | 12 ++++++++++++ man/filter_countries_years.Rd | 4 ++-- man/pipe.Rd | 12 ++++++++++++ man/quasi-quote-assign.Rd | 12 ++++++++++++ man/release_target.Rd | 8 ++++---- tests/testthat.R | 4 ++-- tests/testthat/test-data_functions.R | 7 +++++++ 18 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 R/utils-.data.R create mode 100644 R/utils-pipe.R create mode 100644 R/utils-qqassign.R create mode 100644 man/data.Rd create mode 100644 man/pipe.Rd create mode 100644 man/quasi-quote-assign.Rd create mode 100644 tests/testthat/test-data_functions.R diff --git a/.Rbuildignore b/.Rbuildignore index bdb80d8..5ee20fe 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,4 +1,4 @@ -^PFUPipelinesTools\.Rproj$ +^PFUPipelineTools\.Rproj$ ^\.Rproj\.user$ ^data-raw$ ^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index b169a13..2d9e5b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,8 +12,13 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Imports: - assertthat, - targets + dplyr, + IEATools, + lubridate, + magrittr, + parsedate, + pins, + rlang Depends: R (>= 2.10) LazyData: true diff --git a/LICENSE b/LICENSE index 8c2a3fa..1b5176e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,2 @@ YEAR: 2023 -COPYRIGHT HOLDER: PFUPipelinesTools authors +COPYRIGHT HOLDER: PFUPipelineTools authors diff --git a/LICENSE.md b/LICENSE.md index 62e3ad2..b0973bf 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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 diff --git a/NAMESPACE b/NAMESPACE index 3feb41a..627b65b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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(tar_ungroup) +importFrom(magrittr,"%>%") +importFrom(rlang,":=") +importFrom(rlang,.data) diff --git a/R/data_functions.R b/R/data_functions.R index 956d408..5cf804c 100644 --- a/R/data_functions.R +++ b/R/data_functions.R @@ -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, @@ -32,15 +32,15 @@ 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) } diff --git a/R/storing.R b/R/storing.R index 6c17a03..00aacee 100644 --- a/R/storing.R +++ b/R/storing.R @@ -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 { @@ -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")) diff --git a/R/utils-.data.R b/R/utils-.data.R new file mode 100644 index 0000000..316d2c1 --- /dev/null +++ b/R/utils-.data.R @@ -0,0 +1,11 @@ +#' Data pronoun +#' +#' See [rlang::.data] for details. +#' +#' @name .data +#' @rdname data +#' @keywords internal +#' @export +#' @importFrom rlang .data +#' @usage .data +NULL diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..fb8c818 --- /dev/null +++ b/R/utils-pipe.R @@ -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 diff --git a/R/utils-qqassign.R b/R/utils-qqassign.R new file mode 100644 index 0000000..46609b9 --- /dev/null +++ b/R/utils-qqassign.R @@ -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 diff --git a/data-raw/create_constants.R b/data-raw/create_constants.R index 282acff..4bc6ab7 100644 --- a/data-raw/create_constants.R +++ b/data-raw/create_constants.R @@ -2,7 +2,6 @@ # If there are any changes to these constants, # source this script before building the package. -library(magrittr) library(IEATools) # diff --git a/man/data.Rd b/man/data.Rd new file mode 100644 index 0000000..80b1aa1 --- /dev/null +++ b/man/data.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-.data.R +\name{.data} +\alias{.data} +\title{Data pronoun} +\usage{ +.data +} +\description{ +See \link[rlang:dot-data]{rlang::.data} for details. +} +\keyword{internal} diff --git a/man/filter_countries_years.Rd b/man/filter_countries_years.Rd index 0f369a0..d98745c 100644 --- a/man/filter_countries_years.Rd +++ b/man/filter_countries_years.Rd @@ -31,7 +31,7 @@ in a way that is amenable to drake subtargets. \code{dplyr::filter()} does the subsetting. } \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) } diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..b7daf6a --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\description{ +See \code{magrittr::\link[magrittr]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/quasi-quote-assign.Rd b/man/quasi-quote-assign.Rd new file mode 100644 index 0000000..613b54e --- /dev/null +++ b/man/quasi-quote-assign.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-qqassign.R +\name{:=} +\alias{:=} +\title{Assignment} +\usage{ +x := y +} +\description{ +See \code{rlang::\link[rlang]{:=}} for details. +} +\keyword{internal} diff --git a/man/release_target.Rd b/man/release_target.Rd index 766f8ef..b2604a9 100644 --- a/man/release_target.Rd +++ b/man/release_target.Rd @@ -44,15 +44,15 @@ as shown in examples. # 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")} } diff --git a/tests/testthat.R b/tests/testthat.R index 2e3db6a..d777f6e 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -7,6 +7,6 @@ # * https://testthat.r-lib.org/reference/test_package.html#special-files library(testthat) -library(PFUPipelinesTools) +library(PFUPipelineTools) -test_check("PFUPipelinesTools") +test_check("PFUPipelineTools") diff --git a/tests/testthat/test-data_functions.R b/tests/testthat/test-data_functions.R new file mode 100644 index 0000000..393a2c6 --- /dev/null +++ b/tests/testthat/test-data_functions.R @@ -0,0 +1,7 @@ +test_that("filter_countries_years() works as expected", { + res <- IEATools::sample_iea_data_path() |> + IEATools::load_tidy_iea_df() |> + filter_countries_years(countries = c("ZAF"), years = 1960:1999) + expect_equal(res$Country |> unique(), "ZAF") + expect_equal(res$Year |> unique(), 1971) +}) From 6445e05a698f109a0a4a68bd58f9f3b32f4713f9 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 6 Jun 2023 10:24:26 -0400 Subject: [PATCH 09/11] Working on first release. --- DESCRIPTION | 9 +++++---- NEWS.md | 6 +++++- inst/CITATION | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 inst/CITATION diff --git a/DESCRIPTION b/DESCRIPTION index 2d9e5b7..934f474 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,13 @@ Package: PFUPipelineTools Title: Tools for PFU Pipelines -Version: 0.0.1 +Version: 0.1.1 +Date: 2023-06-06 Authors@R: person("Matthew", "Heun", , "matthew.heun@me.com", 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) diff --git a/NEWS.md b/NEWS.md index 398f70d..f6a3408 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ -# PFUPipelineTools 0.0.1 +# 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. diff --git a/inst/CITATION b/inst/CITATION new file mode 100644 index 0000000..59efc65 --- /dev/null +++ b/inst/CITATION @@ -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") +) From c3afabe8a3c2740f53140383a7402280e34babb6 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 6 Jun 2023 10:31:42 -0400 Subject: [PATCH 10/11] Add documentation. --- .Rbuildignore | 3 +++ .gitignore | 1 + _pkgdown.yml | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 _pkgdown.yml diff --git a/.Rbuildignore b/.Rbuildignore index 5ee20fe..bc67358 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,6 @@ ^\.Rproj\.user$ ^data-raw$ ^LICENSE\.md$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.gitignore b/.gitignore index 5b6a065..234f028 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData .Ruserdata +docs diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..b0a95f3 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,3 @@ +template: + bootstrap: 5 + bootswatch: sandstone From 703640a5cf928c3dcbf84ac39ec2ef1630b2e5c1 Mon Sep 17 00:00:00 2001 From: Matthew Heun Date: Tue, 6 Jun 2023 10:43:01 -0400 Subject: [PATCH 11/11] Add README.Rmd --- .Rbuildignore | 1 + README.Rmd | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 README.Rmd create mode 100644 README.md diff --git a/.Rbuildignore b/.Rbuildignore index bc67358..9acead8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^README\.Rmd$ diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..3a15fd9 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,49 @@ +--- +output: github_document +--- + + + + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# PFUPipelineTools + + + +[![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) + + + + +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 +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a37e42 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ + + + + + + +# PFUPipelineTools + + + +[![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) + + + +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 .