diff --git a/.Rbuildignore b/.Rbuildignore index c698b0aa..dded223e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,8 @@ sandbox/ ^LICENSE\.md$ ^\.github$ .claude/ +^doc$ +^Meta$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..fe6f0526 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,126 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at sbudai.ga@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. + +For answers to common questions about this code of conduct, see the FAQ at +. Translations are available at . + +[homepage]: https://www.contributor-covenant.org diff --git a/.github/workflows/lint-project.yml b/.github/workflows/lint-project.yml index 660397c4..f1449f92 100644 --- a/.github/workflows/lint-project.yml +++ b/.github/workflows/lint-project.yml @@ -23,9 +23,10 @@ jobs: with: use-public-rspm: true - - name: Install lintr - run: install.packages("lintr") - shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, local::. + needs: lint - name: Lint root directory run: lintr::lint_package() diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 00000000..3976c0ab --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + release: + types: [published] + workflow_dispatch: + +name: pkgdown.yaml + +permissions: read-all + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + ENTSOE_PAT: ${{ secrets.ENTSOE_PAT }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index bac787f4..6412158f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ sandbox/ test-coverage.yml .claude/ +inst/doc +/doc/ +/Meta/ +docs diff --git a/DESCRIPTION b/DESCRIPTION index 5abe5933..d0b01809 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: entsoeapi Type: Package Title: An R Wrapper for the European Network of Transmission System Operators for Electricity Application Programming Interface -Version: 0.9.3.0 +Version: 0.9.4.0 Authors@R: c(person("Kenneth", "Rose", role="aut", email="kennethrose82@gmail.com"), person("Sándor", "Budai", role=c("aut", "cre"), email="sbudai.ga@gmail.com")) Description: Simple and standardized wrappers around Entso-E API's Market, Load, Generation, @@ -10,6 +10,8 @@ Description: Simple and standardized wrappers around Entso-E API's Market, Load, License: MIT + file LICENSE Imports: cachem, + cli, + checkmate, data.table, dplyr, fs, @@ -28,15 +30,20 @@ Imports: Encoding: UTF-8 Language: en-US LazyData: true -URL: https://github.com/krose/entsoeapi +URL: https://krose.github.io/entsoeapi, https://krose.github.io/entsoeapi/ BugReports: https://github.com/krose/entsoeapi/issues Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.3 Depends: R (>= 4.1.0) Suggests: - testthat (>= 3.0.0) + knitr, + rmarkdown, + testthat (>= 3.0.0), + ggplot2 +VignetteBuilder: knitr Config/testthat/edition: 3 Collate: + 'entsoeapi-package.R' 'data.R' 'utils.R' 'en_helpers.R' diff --git a/NAMESPACE b/NAMESPACE index 94aab1a2..4f80ebcb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -66,6 +66,7 @@ export(resource_object_eic) export(rr_actual_capacity) export(rr_and_frr_actual_capacity) export(shares_of_fcr_capacity) +export(sharing_of_frr_capacity) export(substation_eic) export(tie_line_eic) export(total_commercial_sched) diff --git a/NEWS.md b/NEWS.md index 2c268cce..a666dce4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,19 @@ +# entsoeapi v0.9.4.0 (2026-03-04) + +## New functionality + +- The beta version of `sharing_of_frr_capacity()` query has been introduced. + +## Miscellaneous + +- The progress bar and the console message formats standardized. +- New hex sticker has been created and added. +- A new da-price-spread-vignette.Rmd has been composed and added. +- CODE_OF_CONDUCT.md has been composed and added. +- The README.md has been updated. +- A top-level documentation has been added to the package. +- Minor under the hood improvements and fixes. + # entsoeapi v0.9.3.0 (2026-03-01) ## New functionality diff --git a/R/data.R b/R/data.R index 7b0a1f0c..cfd54118 100644 --- a/R/data.R +++ b/R/data.R @@ -1,371 +1,349 @@ +utils::globalVariables( + c( + "allocation_mode_types", + "analog_types", + "asset_types", + "auction_types", + "business_types", + "category_types", + "classification_types", + "coding_scheme_types", + "contract_types", + "coordinate_system_types", + "currency_types", + "curve_types", + "direction_types", + "document_types", + "eic_types", + "energy_product_types", + "flow_commodity_option_types", + "fuel_types", + "grid_agreement_types", + "hvdc_mode_types", + "indicator_types", + "market_product_types", + "message_types", + "object_aggregation_types", + "payment_terms_types", + "price_category_types", + "price_component_types", + "price_direction_types", + "process_types", + "quality_types", + "reason_code_types", + "rights_types", + "role_types", + "settlement_method_types", + "status_types", + "tariff_types", + "timeframe_types", + "transmission_pair_eic_dict", + "unit_multiplier", + "unit_of_measure_types", + "unit_symbol_types" + ) +) + #' @title #' List Allocation Mode Types #' #' @examples -#' #' str(entsoeapi::allocation_mode_types) #' "allocation_mode_types" - #' @title #' List Asset Types #' #' @examples -#' #' str(entsoeapi::asset_types) #' "asset_types" - #' @title #' List Auction Types #' #' @examples -#' #' str(entsoeapi::auction_types) #' "auction_types" - #' @title #' List Business Types -#' #' @examples -#' #' str(entsoeapi::business_types) #' "business_types" - #' @title #' List Category Types #' #' @examples -#' #' str(entsoeapi::category_types) #' "category_types" - #' @title #' List Classification Types #' #' @examples -#' #' str(entsoeapi::classification_types) #' "classification_types" - #' @title #' List Coding Scheme Types #' #' @examples -#' #' str(entsoeapi::coding_scheme_types) #' "coding_scheme_types" - #' @title #' List Contract Types #' #' @examples -#' #' str(entsoeapi::contract_types) #' "contract_types" - #' @title #' List Currency Types #' #' @examples -#' #' str(entsoeapi::currency_types) #' "currency_types" - #' @title #' List Curve Types #' #' @examples -#' #' str(entsoeapi::curve_types) #' "curve_types" - #' @title #' List Direction Types #' #' @examples -#' #' str(entsoeapi::direction_types) #' "direction_types" - #' @title #' List Document Types #' #' @examples -#' #' str(entsoeapi::document_types) #' "document_types" - #' @title #' List Message Types #' #' @examples -#' #' str(entsoeapi::message_types) #' "message_types" - #' @title #' List EIC Types #' #' @examples -#' #' str(entsoeapi::eic_types) #' "eic_types" - #' @title #' List Energy Product Types #' #' @examples -#' #' str(entsoeapi::energy_product_types) #' "energy_product_types" - #' @title #' List Flow Commodity Types #' #' @examples -#' #' str(entsoeapi::flow_commodity_option_types) #' "flow_commodity_option_types" - #' @title #' List Grid Agreement Types #' #' @examples -#' #' str(entsoeapi::grid_agreement_types) #' "grid_agreement_types" - #' @title #' List HVDC Mode Types #' #' @examples -#' #' str(entsoeapi::hvdc_mode_types) #' "hvdc_mode_types" - #' @title #' List Indicator Types #' #' @examples -#' #' str(entsoeapi::indicator_types) #' "indicator_types" - #' @title #' List Object Aggregation Types #' #' @examples -#' #' str(entsoeapi::object_aggregation_types) #' "object_aggregation_types" - #' @title #' List Payment Terms Types #' #' @examples -#' #' str(entsoeapi::payment_terms_types) #' "payment_terms_types" - #' @title #' List Price Category Types #' #' @examples -#' #' str(entsoeapi::price_category_types) #' "price_category_types" - #' @title #' List Price Direction Types #' #' @examples -#' #' str(entsoeapi::price_direction_types) #' "price_direction_types" - #' @title #' List Process Types #' #' @examples -#' #' str(entsoeapi::process_types) #' "process_types" - #' @title #' List Quality Types #' #' @examples -#' #' str(entsoeapi::quality_types) #' "quality_types" - #' @title #' List Reason Code Types #' #' @examples -#' #' str(entsoeapi::reason_code_types) #' "reason_code_types" - #' @title #' List Rights Types #' #' @examples -#' #' str(entsoeapi::rights_types) #' "rights_types" - #' @title #' List Role Types #' #' @examples -#' #' str(entsoeapi::role_types) #' "role_types" - #' @title #' List Settlement Method Types #' #' @examples -#' #' str(entsoeapi::settlement_method_types) #' "settlement_method_types" - #' @title #' List Status Types #' #' @examples -#' #' str(entsoeapi::status_types) #' "status_types" - #' @title #' List Tariff Types #' #' @examples -#' #' str(entsoeapi::tariff_types) #' "tariff_types" - #' @title #' List Unit of Measure Types #' #' @examples -#' #' str(entsoeapi::unit_of_measure_types) #' "unit_of_measure_types" - #' @title #' List Unit Symbol Types #' #' @examples -#' #' str(entsoeapi::unit_symbol_types) #' "unit_symbol_types" - #' @title #' List Transmission Pair EIC Dictionary #' #' @examples -#' #' str(entsoeapi::transmission_pair_eic_dict) #' "transmission_pair_eic_dict" @@ -375,7 +353,6 @@ #' List Analog Types #' #' @examples -#' #' str(entsoeapi::analog_types) #' "analog_types" @@ -385,7 +362,6 @@ #' List Coordinate System Types #' #' @examples -#' #' str(entsoeapi::coordinate_system_types) #' "coordinate_system_types" @@ -395,7 +371,6 @@ #' List Fuel Types #' #' @examples -#' #' str(entsoeapi::fuel_types) #' "fuel_types" @@ -405,7 +380,6 @@ #' List Market Product Types #' #' @examples -#' #' str(entsoeapi::market_product_types) #' "market_product_types" @@ -415,7 +389,6 @@ #' List Price Component Types #' #' @examples -#' #' str(entsoeapi::price_component_types) #' "price_component_types" @@ -425,7 +398,6 @@ #' List Timeframe Types #' #' @examples -#' #' str(entsoeapi::timeframe_types) #' "timeframe_types" @@ -435,7 +407,6 @@ #' List Unit Multiplier #' #' @examples -#' #' str(entsoeapi::unit_multiplier) #' "unit_multiplier" diff --git a/R/en_balancing.R b/R/en_balancing.R index 1e562425..aedd1ae5 100644 --- a/R/en_balancing.R +++ b/R/en_balancing.R @@ -7,7 +7,6 @@ utils::globalVariables( ) - #' @title #' Get Elastic Demands (IFs aFRR 3.4 & mFRR 3.4) #' @@ -52,23 +51,13 @@ elastic_demands <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if proper process_type provided - if (is.null(process_type) || !process_type %in% c("A47", "A51")) { - stop("The 'process_type' should be 'A47' or 'A51'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A47", "A51")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -96,7 +85,6 @@ elastic_demands <- function( } - #' @title #' Get Netted Volumes (IFs IN 3.10) #' @@ -140,18 +128,12 @@ netted_volumes <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one day if (difftime(period_end, period_start, units = "day") > 1L) { - stop("One day range limit should be applied!") + cli::cli_abort("One day range limit should be applied!") } # convert timestamps into accepted format @@ -179,7 +161,6 @@ netted_volumes <- function( } - #' @title #' Get Exchanged Volumes (aFRR 3.16, mFRR 3.17) #' @@ -241,24 +222,13 @@ exchanged_volumes <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if proper process_type provided - if (is.null(process_type) || !process_type %in% c("A51", "A60", "A61")) { - stop("The 'process_type' should be 'A51', 'A60' or 'A61'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A51", "A60", "A61")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one day if (difftime(period_end, period_start, units = "day") > 1L) { - stop("One day range limit should be applied!") + cli::cli_abort("One day range limit should be applied!") } # convert timestamps into accepted format @@ -286,7 +256,6 @@ exchanged_volumes <- function( } - #' @title #' Balancing Border Capacity Limitations (IFs 4.3 & 4.4) #' @@ -338,24 +307,14 @@ balancing_border_cap_limit <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one in and only one out eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if proper process_type provided - if (!process_type %in% c("A47", "A51", "A63")) { - stop("The 'process_type' should be 'A47', 'A51' or 'A63'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A47", "A51", "A63")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -384,7 +343,6 @@ balancing_border_cap_limit <- function( } - #' @title #' Get Netted & Exchanged Volumes Per Border (IFs 3.10, 3.16 & 3.17) #' @@ -434,33 +392,14 @@ exchanged_volumes_per_border <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one acquiring_eic provided - if (is.null(acquiring_eic)) { - stop("One acquiring EIC should be provided.") - } - if (length(acquiring_eic) > 1L) { - stop("This wrapper only supports one acquiring EIC per request.") - } - - # check if only one connecting_eic provided - if (is.null(connecting_eic)) { - stop("One connecting EIC should be provided.") - } - if (length(connecting_eic) > 1L) { - stop("This wrapper only supports one connecting EIC per request.") - } - - # check if proper process_type provided - if (is.null(process_type) || !process_type %in% c("A51", "A60", "A61")) { - stop("The 'process_type' should be 'A51', 'A60' or 'A61'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(acquiring_eic) + checkmate::assert_string(connecting_eic) + checkmate::assert_choice(process_type, choices = c("A51", "A60", "A61")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one day if (difftime(period_end, period_start, units = "day") > 1L) { - stop("One day range limit should be applied!") + cli::cli_abort("One day range limit should be applied!") } # convert timestamps into accepted format @@ -488,7 +427,6 @@ exchanged_volumes_per_border <- function( } - #' @title #' Get HVDC Link Constraints (IFs 4.5) #' @@ -540,27 +478,15 @@ hvdc_link_constrains <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' domain EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' domain EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - if (length(eic_ic) > 1L) { - stop("This wrapper only supports one interconnector EIC per request.") - } - - # check if proper process_type provided - if (!process_type %in% c("A47", "A51", "A63")) { - stop("The 'process_type' should be 'A47', 'A51' or 'A63'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(eic_ic, null.ok = TRUE) + checkmate::assert_choice(process_type, choices = c("A47", "A51", "A63")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -590,7 +516,6 @@ hvdc_link_constrains <- function( } - #' @title #' Get Changes to Bid Availability (IFs mFRR 9.9, aFRR 9.6 & 9.8) #' @@ -642,29 +567,16 @@ changes_to_bid_availability <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if proper business_type provided - if (is.null(business_type) || !business_type %in% c( - "C40", "C41", "C42", "C43", "C44", "C45", "C46" + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + business_type, + choices = c("C40", "C41", "C42", "C43", "C44", "C45", "C46") ) - ) { - stop( - "The 'business_type' should be 'C40', 'C41', ", - "'C42', 'C43', 'C44', 'C45', 'C46'." - ) - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -692,7 +604,6 @@ changes_to_bid_availability <- function( } - #' @title #' Get Current Balancing State (GL EB 12.3.A) #' @@ -733,18 +644,12 @@ current_balancing_state <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than 100 days if (difftime(period_end, period_start, units = "day") > 100L) { - stop("100 day range limit should be applied!") + cli::cli_abort("100 day range limit should be applied!") } # convert timestamps into accepted format @@ -771,7 +676,6 @@ current_balancing_state <- function( } - #' @title #' Get Balancing Energy Bids (GL EB 12.3.B&C) #' @@ -813,14 +717,8 @@ balancing_energy_bids <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One connecting domain EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one connecting domain EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -847,7 +745,6 @@ balancing_energy_bids <- function( } - #' @title #' Get Aggregated Balancing Energy Bids (GL EB 12.3.E) #' @@ -882,7 +779,7 @@ balancing_energy_bids <- function( #' #' str(df) #' -aggregated_balancing_energy_bids <- function( +aggregated_balancing_energy_bids <- function( # nolint: object_length_linter eic = NULL, process_type = NULL, period_start = lubridate::ymd( @@ -896,26 +793,16 @@ aggregated_balancing_energy_bids <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if proper process_type provided - if ( - is.null(process_type) || - !process_type %in% c("A51", "A46", "A47", "A60", "A61") - ) { - stop("The 'process_type' should be 'A51', 'A46', 'A47', 'A60' or 'A61'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + process_type, + choices = c("A51", "A46", "A47", "A60", "A61") + ) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -942,7 +829,6 @@ aggregated_balancing_energy_bids <- function( } - #' @title #' Get Procured Balancing Capacity (GL EB 12.3.F) #' @@ -989,24 +875,10 @@ procured_balancing_capacity <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if proper process_type provided - if (is.null(process_type) || !process_type %in% c("A51", "A52", "A47")) { - stop("The 'process_type' should be 'A51', 'A52' or 'A47'.") - } - - # check if none or only one type_market_agreement provided - if (!is.null(type_market_agreement) && length(type_market_agreement) > 1L) { - stop("None or one 'type_market_agreement' should be provided.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A51", "A52", "A47")) + checkmate::assert_string(type_market_agreement, null.ok = TRUE) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1040,7 +912,6 @@ procured_balancing_capacity <- function( } - #' @title #' Get Allocation of Cross-Zonal Balancing Capacity (GL EB 12.3.H&I) #' @@ -1069,7 +940,7 @@ procured_balancing_capacity <- function( #' #' str(df) #' -allocation_of_cross_zonal_balancing_cap <- function( +allocation_of_cross_zonal_balancing_cap <- function( # nolint: object_length_linter eic_acquiring = NULL, eic_connecting = NULL, type_market_agreement = NULL, @@ -1084,27 +955,14 @@ allocation_of_cross_zonal_balancing_cap <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_acquiring)) { - stop("One acquiring domain EIC should be provided.") - } - if (is.null(eic_connecting)) { - stop("One connecting domain EIC should be provided.") - } - if (length(eic_acquiring) > 1L || length(eic_connecting) > 1L) { - stop( - "This wrapper only supports one acquiring and one connecting EIC ", - "per request." - ) - } - - # check if none or only one type_market_agreement provided - if (!is.null(type_market_agreement) && length(type_market_agreement) > 1L) { - stop("None or one 'type_market_agreement' should be provided.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string( + x = eic_acquiring, n.chars = 16L, pattern = "^[A-Z0-9-]*$" + ) + checkmate::assert_string( + x = eic_connecting, n.chars = 16L, pattern = "^[A-Z0-9-]*$" + ) + checkmate::assert_string(type_market_agreement, null.ok = TRUE) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1139,7 +997,6 @@ allocation_of_cross_zonal_balancing_cap <- function( } - #' @title #' Get Contracted Reserves (17.1.B&C) #' @@ -1198,22 +1055,9 @@ contracted_reserves <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if type_market_agreement is provided - if (is.null(type_market_agreement)) { - stop("A 'type_market_agreement' value should be provided.") - } - if (length(type_market_agreement) > 1L) { - stop("Only one 'type_market_agreement' value should be provided.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(type_market_agreement) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1248,7 +1092,6 @@ contracted_reserves <- function( } - #' @title #' Get Activated Balancing Prices (TR 17.1.F, IF aFRR 3.16) #' @@ -1293,18 +1136,12 @@ activated_balancing_prices <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1336,7 +1173,6 @@ activated_balancing_prices <- function( } - #' @title #' Get Imbalance Prices (17.1.G) #' @@ -1377,18 +1213,12 @@ imbalance_prices <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1414,7 +1244,6 @@ imbalance_prices <- function( } - #' @title #' Get Imbalance Volumes (17.1.H) #' @@ -1455,18 +1284,12 @@ imbalance_volumes <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1492,7 +1315,6 @@ imbalance_volumes <- function( } - #' @title #' Get Financial Expenses and Income for Balancing (17.1.I) #' @@ -1520,7 +1342,7 @@ imbalance_volumes <- function( #' #' str(df) #' -financial_expenses_and_income_for_balancing <- function( +financial_expenses_and_income_for_balancing <- function( # nolint: object_length_linter eic = NULL, period_start = lubridate::ymd( Sys.Date() - lubridate::days(x = 7L), @@ -1533,18 +1355,12 @@ financial_expenses_and_income_for_balancing <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1570,7 +1386,6 @@ financial_expenses_and_income_for_balancing <- function( } - #' @title #' Get FCR Total Capacity (SO GL 187.2) #' @@ -1611,18 +1426,12 @@ fcr_total_capacity <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1649,7 +1458,6 @@ fcr_total_capacity <- function( } - #' @title #' Get Shares of FCR Capacity (SO GL 187.2) #' @@ -1695,23 +1503,13 @@ shares_of_fcr_capacity <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one area EIC per request.") - } - - # check if proper business_type provided - if (is.null(business_type) || !business_type %in% c("C23", "B95")) { - stop("The 'business_type' should be 'C23' or 'B95'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(business_type, choices = c("C23", "B95")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -1738,7 +1536,6 @@ shares_of_fcr_capacity <- function( } - #' @title #' Get RR and FRR Actual Capacity (SO GL 188.4 & 189.3) #' @@ -1788,24 +1585,10 @@ rr_and_frr_actual_capacity <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one area EIC per request.") - } - - # check if proper process_type provided - if (is.null(process_type) || !process_type %in% c("A56", "A46")) { - stop("The 'process_type' should be 'A56' (FRR) or 'A46' (RR).") - } - - # check if proper process_type provided - if (is.null(business_type) || !business_type %in% c("C77", "C78", "C79")) { - stop("The 'business_type' should be 'C77', 'C78' or 'C79'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A56", "A46")) + checkmate::assert_choice(business_type, choices = c("C77", "C78", "C79")) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1832,7 +1615,6 @@ rr_and_frr_actual_capacity <- function( } - #' @title #' Get RR Actual Capacity (SO GL 189.3) #' @@ -1871,14 +1653,8 @@ rr_actual_capacity <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1905,103 +1681,91 @@ rr_actual_capacity <- function( } - -#' #' @title -#' #' Get Sharing of FRR Capacity (SO GL 190.1) -#' #' -#' #' @description -#' #' Sharing of Frequency Restoration Reserve capacity between areas. -#' #' One year range limit applies. -#' #' -#' #' @param eic_acquiring Energy Identification Code of the acquiring domain -#' #' @param eic_connecting Energy Identification Code of the connecting domain -#' #' @param process_type type of reserve -#' #' "A56" FRR -#' #' "A46" RR -#' #' @param period_start POSIXct or YYYY-MM-DD HH:MM:SS format -#' #' One year range limit applies -#' #' @param period_end POSIXct or YYYY-MM-DD HH:MM:SS format -#' #' One year range limit applies -#' #' @param tidy_output Defaults to TRUE. flatten nested tables -#' #' @param security_token Security token for ENTSO-E transparency platform -#' #' -#' #' export -#' #' -#' #' @examples -#' #' df <- entsoeapi::sharing_of_frr_capacity( -#' #' eic_acquiring = "10YCB-GERMANY--8", -#' #' eic_connecting = "10YAT-APG------L", -#' #' process_type = "A56", -#' #' period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -#' #' period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -#' #' tidy_output = TRUE -#' #' ) -#' #' -#' #' str(df) -#' #' -#' sharing_of_frr_capacity <- function( -#' eic_acquiring = NULL, -#' eic_connecting = NULL, -#' process_type = NULL, -#' period_start = lubridate::ymd( -#' Sys.Date() - lubridate::days(x = 7L), -#' tz = "CET" -#' ), -#' period_end = lubridate::ymd( -#' Sys.Date(), -#' tz = "CET" -#' ), -#' tidy_output = TRUE, -#' security_token = Sys.getenv("ENTSOE_PAT") -#' ) { -#' # check if only one eic provided -#' if (is.null(eic_acquiring)) { -#' stop("One acquiring domain EIC should be provided.") -#' } -#' if (is.null(eic_connecting)) { -#' stop("One connecting domain EIC should be provided.") -#' } -#' if (length(eic_acquiring) > 1L || length(eic_connecting) > 1L) { -#' stop( -#' "This wrapper only supports one acquiring and one connecting EIC ", -#' "per request." -#' ) -#' } -#' -#' # check if proper process_type provided -#' if (is.null(process_type) || !process_type %in% c("A56", "A46")) { -#' stop("The 'process_type' should be 'A56' (FRR) or 'A46' (RR).") -#' } -#' -#' # check if valid security token is provided -#' if (security_token == "") stop("Valid security token should be provided.") -#' -#' # check if the requested period is not longer than one year -#' if (difftime(period_end, period_start, units = "day") > 365L) { -#' stop("One year range limit should be applied!") -#' } -#' -#' # convert timestamps into accepted format -#' period_start <- url_posixct_format(period_start) -#' period_end <- url_posixct_format(period_end) -#' -#' # compose GET request url -#' query_string <- paste0( -#' "documentType=A26", -#' "&BusinessType=C22", -#' "&processType=", process_type, -#' "&Acquiring_Domain=", eic_acquiring, -#' "&Connecting_Domain=", eic_connecting, -#' "&periodStart=", period_start, -#' "&periodEnd=", period_end -#' ) -#' -#' # send GET request -#' en_cont_list <- api_req_safe( -#' query_string = query_string, -#' security_token = security_token -#' ) -#' -#' # return with the extracted the response -#' extract_response(content = en_cont_list, tidy_output = tidy_output) +#' @title +#' Get Sharing of FRR Capacity (SO GL 190.1) +#' +#' @description +#' Sharing of Frequency Restoration Reserve capacity between areas. +#' One year range limit applies. +#' +#' @param eic_acquiring Energy Identification Code of the acquiring domain +#' @param eic_connecting Energy Identification Code of the connecting domain +#' @param process_type type of reserve +#' "A56" FRR +#' "A46" RR +#' @param period_start POSIXct or YYYY-MM-DD HH:MM:SS format +#' One year range limit applies +#' @param period_end POSIXct or YYYY-MM-DD HH:MM:SS format +#' One year range limit applies +#' @param tidy_output Defaults to TRUE. flatten nested tables +#' @param security_token Security token for ENTSO-E transparency platform +#' +#' @export +#' +#' @examples +#' \dontrun{ +#' df <- entsoeapi::sharing_of_frr_capacity( +#' eic_acquiring = "10YCB-GERMANY--8", +#' eic_connecting = "10YAT-APG------L", +#' process_type = "A56", +#' period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), +#' period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), +#' tidy_output = TRUE +#' ) +#' +#' str(df) #' } +#' +sharing_of_frr_capacity <- function( + eic_acquiring = NULL, + eic_connecting = NULL, + process_type = NULL, + period_start = lubridate::ymd( + Sys.Date() - lubridate::days(x = 7L), + tz = "CET" + ), + period_end = lubridate::ymd( + Sys.Date(), + tz = "CET" + ), + tidy_output = TRUE, + security_token = Sys.getenv("ENTSOE_PAT") +) { + checkmate::assert_string( + x = eic_acquiring, n.chars = 16L, pattern = "^[A-Z0-9-]*$" + ) + checkmate::assert_string( + x = eic_connecting, n.chars = 16L, pattern = "^[A-Z0-9-]*$" + ) + checkmate::assert_choice(process_type, choices = c("A56", "A46")) + checkmate::assert_string(security_token, min.chars = 1L) + + # check if the requested period is not longer than one year + if (difftime(period_end, period_start, units = "day") > 365L) { + cli::cli_abort("One year range limit should be applied!") + } + + # convert timestamps into accepted format + period_start <- url_posixct_format(period_start) + period_end <- url_posixct_format(period_end) + + # compose GET request url + query_string <- paste0( + "documentType=A26", + "&BusinessType=C22", + "&processType=", process_type, + "&Acquiring_Domain=", eic_acquiring, + "&Connecting_Domain=", eic_connecting, + "&periodStart=", period_start, + "&periodEnd=", period_end + ) + + # send GET request + en_cont_list <- api_req_safe( + query_string = query_string, + security_token = security_token + ) + + # return with the extracted the response + extract_response(content = en_cont_list, tidy_output = tidy_output) +} diff --git a/R/en_generation.R b/R/en_generation.R index 4894be53..719ba68a 100644 --- a/R/en_generation.R +++ b/R/en_generation.R @@ -10,7 +10,6 @@ utils::globalVariables( ) - #' @title #' Get Installed Generation Capacity per Production Type (14.1.A) #' @@ -42,17 +41,9 @@ gen_installed_capacity_per_pt <- function( year = lubridate::year(Sys.Date()), security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided!") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") - - # check if year is an integer number or not - if (year %% 1 > 0) stop("One valid integer year value should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_integerish(year, len = 1L) # convert year into the accepted format period_start <- paste0(year, "01010000") @@ -62,10 +53,15 @@ gen_installed_capacity_per_pt <- function( query_string <- paste0( "documentType=A68", "&processType=A33", - "&in_Domain=", eic, - {if (!is.null(psr_type)) paste0("&psrType=", psr_type)}, - "&periodStart=", period_start, - "&periodEnd=", period_end + "&in_Domain=", + eic, + { + if (!is.null(psr_type)) paste0("&psrType=", psr_type) + }, + "&periodStart=", + period_start, + "&periodEnd=", + period_end ) # send GET request @@ -79,7 +75,6 @@ gen_installed_capacity_per_pt <- function( } - #' @title #' Get Installed Generation Capacity per Production Unit (14.1.B) #' @@ -111,21 +106,15 @@ gen_installed_capacity_per_pu <- function( psr_type = NULL, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided!") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") - - # check if year is an integer number or not - if (year %% 1 > 0) stop("One valid integer year value should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_integerish(year, len = 1L) # check if year is within the legal limit if (year > lubridate::year(x = Sys.Date()) + 3L) { - stop("Cannot be shown more than 3 years ahead as required by the law!") + cli::cli_abort( + "Cannot be shown more than 3 years ahead as required by the law!" + ) } # convert year into the accepted format @@ -136,10 +125,15 @@ gen_installed_capacity_per_pu <- function( query_string <- paste0( "documentType=A71", "&processType=A33", - "&in_Domain=", eic, - {if (!is.null(psr_type)) paste0("&psrType=", psr_type)}, - "&periodStart=", period_start, - "&periodEnd=", period_end + "&in_Domain=", + eic, + { + if (!is.null(psr_type)) paste0("&psrType=", psr_type) + }, + "&periodStart=", + period_start, + "&periodEnd=", + period_end ) # send GET request @@ -153,7 +147,6 @@ gen_installed_capacity_per_pu <- function( } - #' @title #' Get Aggregated Generation per Production Type (16.1.B&C) #' @@ -188,24 +181,19 @@ gen_installed_capacity_per_pu <- function( gen_per_prod_type <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), gen_type = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided!") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -216,9 +204,12 @@ gen_per_prod_type <- function( query_string <- paste0( "documentType=A75", "&processType=A16", - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end, + "&in_Domain=", + eic, + "&periodStart=", + period_start, + "&periodEnd=", + period_end, { if (!is.null(gen_type)) paste0("&psrType=", gen_type) } @@ -235,7 +226,6 @@ gen_per_prod_type <- function( } - #' @title #' Get Weekly Average Filling Rate of Water Reservoirs #' and Hydro Storage Plants (16.1.D) @@ -262,29 +252,25 @@ gen_per_prod_type <- function( #' eic = "10YFR-RTE------C", #' period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), #' period_end = lubridate::ymd(x = "2021-02-15", tz = "CET"), -#' tidy_output = TRUE) +#' tidy_output = TRUE +#' ) #' str(df) #' gen_storage_mean_filling_rate <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 7L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided!") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 380L) { - stop("Maximum 380 days range limit should be applied!") + cli::cli_abort("Maximum 380 days range limit should be applied!") } # convert timestamps into accepted format @@ -344,36 +330,38 @@ gen_storage_mean_filling_rate <- function( gen_per_gen_unit <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), gen_type = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided!") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) period_end <- url_posixct_format(period_end) # break time interval of period_start into 24 hour long parts - to_time <- difftime(time1 = strptime(x = period_end, - format = "%Y%m%d%H%M", - tz = "UTC") |> - as.POSIXct(tz = "UTC"), - time2 = strptime(x = period_start, - format = "%Y%m%d%H%M", - tz = "UTC") |> - as.POSIXct(tz = "UTC"), - units = "days") |> + to_time <- difftime( + time1 = strptime( + x = period_end, + format = "%Y%m%d%H%M", + tz = "UTC" + ) |> + as.POSIXct(tz = "UTC"), + time2 = strptime( + x = period_start, + format = "%Y%m%d%H%M", + tz = "UTC" + ) |> + as.POSIXct(tz = "UTC"), + units = "days" + ) |> ceiling() - 1L period_start_list <- as.POSIXct( x = period_start, @@ -390,8 +378,9 @@ gen_per_gen_unit <- function( # create combination matrix dataframe par_matrix <- expand.grid(par_list, - stringsAsFactors = FALSE, - KEEP.OUT.ATTRS = FALSE) + stringsAsFactors = FALSE, + KEEP.OUT.ATTRS = FALSE + ) # calculate period end for each period start if (is.null(gen_type)) { @@ -433,22 +422,27 @@ gen_per_gen_unit <- function( # create the corresponding part of the request URL from the par matrix par_part <- par_matrix |> - purrr::pmap(~list(...) |> - purrr::imap(~sprintf(fmt = "&%s=%s", .y, .x)) |> - paste(collapse = "")) |> + purrr::pmap( + ~{ + list(...) |> + purrr::imap(~ sprintf(fmt = "&%s=%s", .y, .x)) |> + paste(collapse = "") + } + ) |> unlist() # compose GET request URL list for a (maximum) 24 hours long period - query_string_list <- paste0("In_Domain=", eic, - "&documentType=A73", - "&processType=A16", - par_part) + query_string_list <- paste0( + "In_Domain=", eic, + "&documentType=A73", + "&processType=A16", + par_part + ) # iterate (maximum) 24 hours long periods thru # and append them into one tibble result_tbl_appended <- query_string_list |> purrr::map(\(query_string) { - # send GET request en_cont_list <- api_req_safe( query_string = query_string, @@ -460,18 +454,15 @@ gen_per_gen_unit <- function( content = en_cont_list, tidy_output = tidy_output ) - }) |> purrr::compact() |> dplyr::bind_rows() # return with all the generation data result_tbl_appended - } - #' @title #' Get Day-Ahead Generation Forecast. (14.1.C) #' @@ -503,23 +494,18 @@ gen_per_gen_unit <- function( gen_day_ahead_forecast <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) { - stop("One control area/bidding zone/country EIC should be provided!") - } - if (length(eic) > 1L) stop("This wrapper only supports one EIC per request!") - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -546,7 +532,6 @@ gen_day_ahead_forecast <- function( } - #' @title #' Get Generation Forecasts for Wind & Solar (14.1.D) #' @@ -588,18 +573,12 @@ gen_wind_solar_forecasts <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) { - stop("One control area/bidding zone/country EIC should be provided!") - } - if (length(eic) > 1L) stop("This wrapper only supports one EIC per request!") - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided!") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -608,27 +587,33 @@ gen_wind_solar_forecasts <- function( # compose GET request urls for a (minimum) 24 hours long period process_type <- c("Day-ahead" = "A01", "Intraday" = "A40", "Current" = "A18") - query_string_list <- purrr::map(process_type, - ~paste0("documentType=A69", - "&processType=", .x, - "&in_Domain=", eic, - "&periodStart=", period_start, - "&periodEnd=", period_end)) + query_string_list <- purrr::map( + process_type, + ~ paste0( + "documentType=A69", + "&processType=", .x, + "&in_Domain=", eic, + "&periodStart=", period_start, + "&periodEnd=", period_end + ) + ) # iterate over request url list # and return with all the data - purrr::map(query_string_list, - \(query_string) { - # send the GET request against the endpoint - en_cont_list <- api_req_safe( - query_string = query_string, - security_token = security_token - ) - - # return with the extracted the response - extract_response( - content = en_cont_list, - tidy_output = tidy_output - ) - }) + purrr::map( + query_string_list, + \(query_string) { + # send the GET request against the endpoint + en_cont_list <- api_req_safe( + query_string = query_string, + security_token = security_token + ) + + # return with the extracted the response + extract_response( + content = en_cont_list, + tidy_output = tidy_output + ) + } + ) } diff --git a/R/en_helpers.R b/R/en_helpers.R index 78ae99cb..d9f65b82 100644 --- a/R/en_helpers.R +++ b/R/en_helpers.R @@ -1,16 +1,16 @@ utils::globalVariables( c( - "get_eiccodes", - "type_def", - "type", + "area_eic", + "doc_status", "eic_code_status", "eic_code_status_value", - "doc_status" + "get_eiccodes", + "type", + "type_def" ) ) - #' @title #' instantiate a memory cache store for maximum 1 hour #' @@ -20,7 +20,6 @@ utils::globalVariables( mh <- cachem::cache_mem(max_age = 3600) - #' @title #' Get Party_X Energy Identification Codes #' @@ -51,27 +50,22 @@ party_eic <- function() { # check if there is any cached value of 'party_eic_name' cache_key <- "party_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Area Y Energy Identification Codes #' @@ -101,27 +95,22 @@ area_eic <- function() { # check if there is any cached value of 'area_eic_name' cache_key <- "area_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Accounting Point Z Energy Identification Codes #' @@ -153,27 +142,22 @@ accounting_point_eic <- function() { # check if there is any cached value of 'accounting_point_eic_name' cache_key <- "accounting_point_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Tie Line T Energy Identification Codes #' @@ -205,27 +189,22 @@ tie_line_eic <- function() { # check if there is any cached value of 'tie_line_eic_name' cache_key <- "tie_line_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Location V Energy Identification Codes #' @@ -256,27 +235,22 @@ location_eic <- function() { # check if there is any cached value of 'location_eic_name' cache_key <- "location_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Resource Object W Energy Identification Codes #' @@ -308,27 +282,22 @@ resource_object_eic <- function() { # check if there is any cached value of 'resource_object_eic_name' cache_key <- "resource_object_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get Substation A Energy Identification Codes #' @@ -365,27 +334,22 @@ substation_eic <- function() { # check if there is any cached value of 'substation_eic_name' cache_key <- "substation_eic_df_key" if (mh$exists(key = cache_key)) { - # recall res_df values res_df <- mh$get(key = cache_key, missing = get_eiccodes(f = f)) - message("\npulling ", f, " file from cache") - + cli::cli_alert_info("pulling {f} file from cache") } else { - # download and import the csv file - message("\ndownloading ", f, " file ...") + cli::cli_alert_info("downloading {f} file ...") res_df <- get_eiccodes(f = f) # cache res_df as cache_key mh$set(key = cache_key, value = res_df) - } res_df } - #' @title #' Get all Approved Energy Identification Codes #' @@ -411,20 +375,21 @@ substation_eic <- function() { #' str(eic_all) #' all_approved_eic <- function() { - list(party_eic(), - area_eic(), - accounting_point_eic(), - tie_line_eic(), - location_eic(), - resource_object_eic(), - substation_eic()) |> + list( + party_eic(), + area_eic(), + accounting_point_eic(), + tie_line_eic(), + location_eic(), + resource_object_eic(), + substation_eic() + ) |> data.table::rbindlist(use.names = TRUE, fill = TRUE) |> unique() |> tibble::as_tibble() } - #' @title #' Get all Allocated Energy Identification Codes #' @@ -457,10 +422,10 @@ all_allocated_eic <- function() { if (mh$exists(key = cache_key)) { # recall res_df values res_df <- mh$get(key = cache_key, missing = get_all_allocated_eic()) - message("\npulling all_allocated_eic table from cache") + cli::cli_alert_info("pulling all_allocated_eic table from cache") } else { # download and import the csv file - message("\ndownloading all_allocated_eic table ...") + cli::cli_alert_info("downloading all_allocated_eic table ...") res_df <- get_all_allocated_eic() # cache res_df as cache_key diff --git a/R/en_load.R b/R/en_load.R index e3940da7..301cb1b0 100644 --- a/R/en_load.R +++ b/R/en_load.R @@ -44,24 +44,20 @@ utils::globalVariables( load_actual_total <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -88,7 +84,6 @@ load_actual_total <- function( } - #' @title #' Get Day-Ahead Total Load Forecast (6.1.B) #' @@ -127,24 +122,20 @@ load_actual_total <- function( load_day_ahead_total_forecast <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -171,7 +162,6 @@ load_day_ahead_total_forecast <- function( } - #' @title #' Get Week-Ahead Total Load Forecast (6.1.C) #' @@ -208,24 +198,20 @@ load_day_ahead_total_forecast <- function( load_week_ahead_total_forecast <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -252,7 +238,6 @@ load_week_ahead_total_forecast <- function( } - #' @title #' Get Month-Ahead Total Load Forecast (6.1.D) #' @@ -286,27 +271,23 @@ load_week_ahead_total_forecast <- function( #' #' str(df) #' -load_month_ahead_total_forecast <- function( +load_month_ahead_total_forecast <- function( # nolint: object_length_linter eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -333,7 +314,6 @@ load_month_ahead_total_forecast <- function( } - #' @title #' Get Year-Ahead Total Load Forecast (6.1.E) #' @@ -370,23 +350,18 @@ load_month_ahead_total_forecast <- function( load_year_ahead_total_forecast <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -413,7 +388,6 @@ load_year_ahead_total_forecast <- function( } - #' @title #' Get Year-Ahead Forecast Margin (8.1) #' @@ -447,26 +421,21 @@ load_year_ahead_total_forecast <- function( #' #' str(df) #' -load_year_ahead_forecast_margin <- function( +load_year_ahead_forecast_margin <- function( # nolint: object_length_linter eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format diff --git a/R/en_market.R b/R/en_market.R index 19b13b3c..beae47a9 100644 --- a/R/en_market.R +++ b/R/en_market.R @@ -44,35 +44,27 @@ utils::globalVariables( #' #' str(df) #' -implicit_offered_transfer_capacity <- function( +implicit_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A07"))) { - stop("The 'contract_type' parameter should be 'A01' or 'A07'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(contract_type, choices = c("A01", "A07")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -101,7 +93,6 @@ implicit_offered_transfer_capacity <- function( } - #' @title #' Get Explicit Offered Transfer Capacity (11.1.A) #' @@ -144,39 +135,30 @@ implicit_offered_transfer_capacity <- function( #' #' str(df) #' -explicit_offered_transfer_capacity <- function( +explicit_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A02", "A03", "A04", "A06", "A07", - "A08"))) { - stop( - "The 'contract_type' parameter should be 'A01', 'A02', 'A03', 'A04', ", - "'A06', 'A07' or 'A08'." - ) - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + contract_type, + choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -205,7 +187,6 @@ explicit_offered_transfer_capacity <- function( } - #' @title #' Get Continuous Offered Transfer Capacity (11.1) #' @@ -237,29 +218,25 @@ explicit_offered_transfer_capacity <- function( #' #' str(df) #' -continuous_offered_transfer_capacity <- function( +continuous_offered_transfer_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -288,7 +265,6 @@ continuous_offered_transfer_capacity <- function( } - #' @title #' Get Flow Based Allocations (11.1.B) #' @@ -340,32 +316,23 @@ continuous_offered_transfer_capacity <- function( flow_based_allocations <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), process_type = "A43", archive = FALSE, tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One 'in' control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if valid process_type provided - if (!process_type %in% c("A32", "A33", "A43", "A44")) { - stop("The 'process_type' parameter should be 'A32', 'A33', 'A43' or 'A44'.") - } - - # check if 'archive' is logical - if (!is.logical(archive)) { - stop("The 'archive' argument should be TRUE or FALSE!") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + process_type, + choices = c("A32", "A33", "A43", "A44") + ) + checkmate::assert_flag(archive) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -393,7 +360,6 @@ flow_based_allocations <- function( } - #' @title #' Get the Auction Revenue (12.1.A) #' @@ -440,35 +406,26 @@ auction_revenue <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A02", "A03", "A04", "A06", "A07", - "A08"))) { - stop( - "The 'contract_type' parameter should be 'A01', 'A02', 'A03', 'A04', ", - "'A06', 'A07' or 'A08'." - ) - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + contract_type, + choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -497,8 +454,6 @@ auction_revenue <- function( } - - #' @title #' Get Total Nominated Capacity (12.1.B) #' @@ -534,25 +489,21 @@ total_nominated_capacity <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -580,7 +531,6 @@ total_nominated_capacity <- function( } - #' @title #' Get Already Allocated Total Capacity (12.1.C) #' @@ -630,46 +580,37 @@ total_nominated_capacity <- function( #' #' str(df) #' -already_allocated_total_capacity <- function( +already_allocated_total_capacity <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), auction_category = "A04", contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") - } - - # check if the auction_category value is valid - if (isFALSE(auction_category %in% c("A01", "A02", "A03", "A04"))) { - stop("The auction_category shoud be 'A01', 'A02', 'A03' or 'A04'") + cli::cli_abort("One year range limit should be applied!") } - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A02", "A03", "A04", "A06", "A07", - "A08"))) { - stop( - "The 'contract_type' parameter should be 'A01', 'A02', 'A03', 'A04', ", - "'A06', 'A07' or 'A08'." - ) - } + checkmate::assert_choice( + auction_category, + choices = c("A01", "A02", "A03", "A04") + ) + checkmate::assert_choice( + contract_type, + choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -698,7 +639,6 @@ already_allocated_total_capacity <- function( } - #' @title #' Get Day-Ahead Prices (12.1.D) #' @@ -737,24 +677,20 @@ already_allocated_total_capacity <- function( day_ahead_prices <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -781,7 +717,6 @@ day_ahead_prices <- function( } - #' @title #' Get Implicit Auction — Net Positions (12.1.E) #' @@ -817,30 +752,22 @@ day_ahead_prices <- function( net_positions <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One bidding zone EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A07"))) { - stop("The 'contract_type' parameter should be 'A01' or 'A07'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(contract_type, choices = c("A01", "A07")) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -869,7 +796,6 @@ net_positions <- function( } - #' @title #' Get Implicit and Flow-based Allocations — Congestion Income (12.1.E) #' @@ -913,34 +839,25 @@ net_positions <- function( congestion_income <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One border or bidding zone EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A02", "A03", "A04", "A06", "A07", - "A08"))) { - stop( - "The 'contract_type' parameter should be 'A01', 'A02', 'A03', 'A04', ", - "'A06', 'A07' or 'A08'." - ) - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + contract_type, + choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -969,7 +886,6 @@ congestion_income <- function( } - #' @title #' Get Transfer Capacities Allocated with Third Countries — Explicit (12.1.H) #' @@ -1020,49 +936,33 @@ congestion_income <- function( #' #' str(df) #' -allocated_transfer_capacities_3rd_countries <- function( +allocated_transfer_capacities_3rd_countries <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), contract_type = "A01", auction_category = "A04", position = 1L, tidy_output = FALSE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if contract_type value is valid - if (isFALSE(contract_type %in% c("A01", "A02", "A03", "A04", "A06", "A07", - "A08"))) { - stop( - "The 'contract_type' parameter should be 'A01', 'A02', 'A03', 'A04', ", - "'A06', 'A07' or 'A08'." - ) - } - - # check if the optional auction_category value is valid - if (isFALSE(auction_category %in% c("A01", "A02", "A03", "A04"))) { - stop("The 'auction_category' should be 'A01', 'A02', 'A03' or 'A04'.") - } - - # check if the optional position value is a positive integer - if ((!is.numeric(position) || - position != as.integer(position) || - position < 1L)) { - stop("The 'position' parameter should be a positive integer.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice( + contract_type, + choices = c("A01", "A02", "A03", "A04", "A06", "A07", "A08") + ) + checkmate::assert_choice( + auction_category, + choices = c("A01", "A02", "A03", "A04") + ) + checkmate::assert_count(position, positive = TRUE) + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -1078,7 +978,7 @@ allocated_transfer_capacities_3rd_countries <- function( if (!is.null(auction_category)) { paste0("&auction.Category=", auction_category) } else { - "" + "" # nocov }, if (!is.null(position)) { paste0( @@ -1086,7 +986,7 @@ allocated_transfer_capacities_3rd_countries <- function( as.integer(position) ) } else { - "" + "" # nocov }, "&periodStart=", period_start, "&periodEnd=", period_end diff --git a/R/en_outages.R b/R/en_outages.R index 36ffa863..38a26945 100644 --- a/R/en_outages.R +++ b/R/en_outages.R @@ -43,13 +43,13 @@ utils::globalVariables( #' df <- entsoeapi::outages_both( #' eic = "10YFR-RTE------C", #' period_start = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 1L), -#' tz = "CET" -#' ), +#' x = Sys.Date() + lubridate::days(x = 1L), +#' tz = "CET" +#' ), #' period_end = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 2L), -#' tz = "CET" -#' ) +#' x = Sys.Date() + lubridate::days(x = 2L), +#' tz = "CET" +#' ) #' ) #' #' str(df) @@ -57,28 +57,34 @@ utils::globalVariables( outages_both <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 2L), - tz = "CET"), + tz = "CET" + ), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - tbl_gu <- try(outages_gen_units(eic = eic, - period_start = period_start, - period_end = period_end, - doc_status = doc_status, - event_nature = event_nature, - tidy_output = tidy_output, - security_token = security_token)) - tbl_pu <- try(outages_prod_units(eic = eic, - period_start = period_start, - period_end = period_end, - doc_status = doc_status, - event_nature = event_nature, - tidy_output = tidy_output, - security_token = security_token)) + tbl_gu <- try(outages_gen_units( + eic = eic, + period_start = period_start, + period_end = period_end, + doc_status = doc_status, + event_nature = event_nature, + tidy_output = tidy_output, + security_token = security_token + )) + tbl_pu <- try(outages_prod_units( + eic = eic, + period_start = period_start, + period_end = period_end, + doc_status = doc_status, + event_nature = event_nature, + tidy_output = tidy_output, + security_token = security_token + )) if (inherits(tbl_gu, "try-error")) { message( @@ -103,7 +109,6 @@ outages_both <- function( } - #' @title #' Get Unavailability of Generation Units. (15.1.A&B) #' @@ -142,13 +147,13 @@ outages_both <- function( #' df <- entsoeapi::outages_gen_units( #' eic = "10YFR-RTE------C", #' period_start = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 1L), -#' tz = "CET" -#' ), +#' x = Sys.Date() + lubridate::days(x = 1L), +#' tz = "CET" +#' ), #' period_end = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 2L), -#' tz = "CET" -#' ) +#' x = Sys.Date() + lubridate::days(x = 2L), +#' tz = "CET" +#' ) #' ) #' #' str(df) @@ -156,36 +161,30 @@ outages_both <- function( outages_gen_units <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 2L), - tz = "CET"), + tz = "CET" + ), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A05", "A09", "A13"))) { - stop("The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL.") - } - - # check if event_nature value is valid - if (isFALSE(event_nature %in% c("A53", "A54"))) { - stop("The 'event_nature' parameter should be 'A53', 'A54' or NULL.") - } + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + doc_status, + choices = c("A05", "A09", "A13"), null.ok = TRUE + ) + checkmate::assert_choice( + event_nature, + choices = c("A53", "A54"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -217,7 +216,6 @@ outages_gen_units <- function( } - #' @title #' Get Unavailability of Production Units. (15.1.C&D) #' @@ -253,13 +251,17 @@ outages_gen_units <- function( #' #' @examples #' df <- entsoeapi::outages_prod_units( -#' eic = "10YFR-RTE------C", -#' period_start = lubridate::ymd(x = Sys.Date() + -#' lubridate::days(x = 1L), -#' tz = "CET"), -#' period_end = lubridate::ymd(x = Sys.Date() + -#' lubridate::days(x = 2L), -#' tz = "CET") +#' eic = "10YFR-RTE------C", +#' period_start = lubridate::ymd( +#' x = Sys.Date() + +#' lubridate::days(x = 1L), +#' tz = "CET" +#' ), +#' period_end = lubridate::ymd( +#' x = Sys.Date() + +#' lubridate::days(x = 2L), +#' tz = "CET" +#' ) #' ) #' #' str(df) @@ -267,36 +269,30 @@ outages_gen_units <- function( outages_prod_units <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 2L), - tz = "CET"), + tz = "CET" + ), doc_status = NULL, event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A05", "A09", "A13"))) { - stop("The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL.") - } - - # check if event_nature value is valid - if (isFALSE(event_nature %in% c("A53", "A54"))) { - stop("The 'event_nature' parameter should be 'A53', 'A54' or NULL.") - } + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + doc_status, + choices = c("A05", "A09", "A13"), null.ok = TRUE + ) + checkmate::assert_choice( + event_nature, + choices = c("A53", "A54"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -328,7 +324,6 @@ outages_prod_units <- function( } - #' @title #' Get Unavailability of Offshore Grid Infrastructure. (10.1.C) #' @@ -362,9 +357,9 @@ outages_prod_units <- function( #' df <- entsoeapi::outages_offshore_grid( #' eic = "10Y1001A1001A82H", #' period_start = lubridate::ymd( -#' x = Sys.Date() -lubridate::days(x = 365L), -#' tz = "CET" -#' ), +#' x = Sys.Date() - lubridate::days(x = 365L), +#' tz = "CET" +#' ), #' period_end = lubridate::ymd(x = Sys.Date(), tz = "CET") #' ) #' @@ -373,30 +368,25 @@ outages_prod_units <- function( outages_offshore_grid <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 2L), - tz = "CET"), + tz = "CET" + ), doc_status = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A05", "A09", "A13"))) { - stop("The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL.") - } + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + doc_status, + choices = c("A05", "A09", "A13"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -425,7 +415,6 @@ outages_offshore_grid <- function( } - #' @title #' Get Unavailability of Consumption Units. (7.1.A&B) #' @@ -476,9 +465,11 @@ outages_offshore_grid <- function( outages_cons_units <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 2L), - tz = "CET"), + tz = "CET" + ), period_start_update = NULL, period_end_update = NULL, doc_status = NULL, @@ -486,28 +477,20 @@ outages_cons_units <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A05", "A09", "A13"))) { - stop("The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL.") - } - - # check if event_nature value is valid - if (isFALSE(event_nature %in% c("A53", "A54"))) { - stop("The 'event_nature' parameter should be 'A53', 'A54' or NULL.") - } + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + doc_status, + choices = c("A05", "A09", "A13"), null.ok = TRUE + ) + checkmate::assert_choice( + event_nature, + choices = c("A53", "A54"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -530,9 +513,11 @@ outages_cons_units <- function( query_string <- paste0(query_string, "&businessType=", event_nature) } if (!is.null(period_start_update) && !is.null(period_end_update)) { - query_string <- paste0(query_string, - "&periodStartUpdate=", period_start_update, - "&periodEndUpdate=", period_end_update) + query_string <- paste0( + query_string, + "&periodStartUpdate=", period_start_update, + "&periodEndUpdate=", period_end_update + ) } # send GET request @@ -546,7 +531,6 @@ outages_cons_units <- function( } - #' @title #' Get Unavailability of Transmission Infrastructure. (10.1.A&B) #' @@ -585,17 +569,17 @@ outages_cons_units <- function( #' eic_in = "10YFR-RTE------C", #' eic_out = "10Y1001A1001A82H", #' period_start = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 1), -#' tz = "CET" -#' ), +#' x = Sys.Date() + lubridate::days(x = 1), +#' tz = "CET" +#' ), #' period_end = lubridate::ymd( -#' x = Sys.Date() + lubridate::days(x = 2), -#' tz = "CET" -#' ), +#' x = Sys.Date() + lubridate::days(x = 2), +#' tz = "CET" +#' ), #' period_start_update = lubridate::ymd( -#' x = Sys.Date() -lubridate::days(x = 7), -#' tz = "CET" -#' ), +#' x = Sys.Date() - lubridate::days(x = 7), +#' tz = "CET" +#' ), #' period_end_update = lubridate::ymd(x = Sys.Date(), tz = "CET") #' ) #' @@ -605,9 +589,11 @@ outages_transmission_grid <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() + lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date() + lubridate::days(x = 3L), - tz = "CET"), + tz = "CET" + ), period_start_update = NULL, period_end_update = NULL, doc_status = NULL, @@ -615,32 +601,21 @@ outages_transmission_grid <- function( tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic per direction provided - if (is.null(eic_in)) stop("One IN control area EIC should be provided.") - if (length(eic_in) > 1L) { - stop("This wrapper only supports one IN control area EIC per request.") - } - if (is.null(eic_out)) stop("One OUT control area EIC should be provided.") - if (length(eic_out) > 1L) { - stop("This wrapper only supports one OUT control area EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A05", "A09", "A13"))) { - stop("The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL.") - } - - # check if event_nature value is valid - if (isFALSE(event_nature %in% c("A53", "A54"))) { - stop("The 'event_nature' parameter should be 'A53', 'A54' or NULL.") - } + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + doc_status, + choices = c("A05", "A09", "A13"), null.ok = TRUE + ) + checkmate::assert_choice( + event_nature, + choices = c("A53", "A54"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -664,9 +639,11 @@ outages_transmission_grid <- function( query_string <- paste0(query_string, "&businessType=", event_nature) } if (!is.null(period_start_update) && !is.null(period_end_update)) { - query_string <- paste0(query_string, - "&periodStartUpdate=", period_start_update, - "&periodEndUpdate=", period_end_update) + query_string <- paste0( + query_string, + "&periodStartUpdate=", period_start_update, + "&periodEndUpdate=", period_end_update + ) } # send GET request @@ -677,11 +654,9 @@ outages_transmission_grid <- function( # return with the extracted the response extract_response(content = en_cont_list, tidy_output = tidy_output) - } - #' @title #' Get Fall-Back Procedures. (IFs IN 7.2, mFRR 3.11, aFRR 3.10) #' @@ -728,37 +703,27 @@ outages_transmission_grid <- function( outages_fallbacks <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 7L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), process_type = "A63", event_nature = "A53", tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one control area EIC per request.") - } - - # check if valid process_type provided - if (!process_type %in% c("A47", "A51", "A63")) { - stop("The 'process_type' parameter should be 'A47', 'A51' or 'A63'.") - } - - # check if valid event_nature provided - if (!event_nature %in% c("C47", "A53", "A54", "A83")) { - stop("The 'event_nature' parameter should be ", - "'C47', 'A53', 'A54' or 'A83'.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_choice(process_type, choices = c("A47", "A51", "A63")) + checkmate::assert_choice( + event_nature, + choices = c("C47", "A53", "A54", "A83") + ) + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format diff --git a/R/en_transmission.R b/R/en_transmission.R index e8cbf65f..421f4d89 100644 --- a/R/en_transmission.R +++ b/R/en_transmission.R @@ -51,42 +51,32 @@ utils::globalVariables( #' #' str(df) #' -expansion_and_dismantling_project <- function( +expansion_and_dismantling_project <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), business_type = NULL, doc_status = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if business_type value is valid - if (isFALSE(business_type %in% c("B01", "B02"))) { - stop( - "The 'business_type' parameter should be 'B01', 'B02'." - ) - } - - # check if doc_status value is valid - if (isFALSE(doc_status %in% c("A01", "A02", "A05", "A09", "A13", "X01"))) { - stop( - "The 'doc_status' parameter should be 'A01', 'A02' ", - "A05', 'A09', 'A13' or 'X01'." - ) - } + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + business_type, + choices = c("B01", "B02"), null.ok = TRUE + ) + checkmate::assert_choice( + doc_status, + choices = c("A01", "A02", "A05", "A09", "A13", "X01"), + null.ok = TRUE + ) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -114,7 +104,6 @@ expansion_and_dismantling_project <- function( } - #' @title #' Get Intraday Cross-Border Transfer Limits (11.3) #' @@ -148,29 +137,25 @@ expansion_and_dismantling_project <- function( #' #' str(df) #' -intraday_cross_border_transfer_limits <- function( +intraday_cross_border_transfer_limits <- function( # nolint: object_length_linter eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -197,7 +182,6 @@ intraday_cross_border_transfer_limits <- function( } - #' @title #' Get Forecasted Transfer Capacities (11.1.A) #' @@ -240,25 +224,21 @@ forecasted_transfer_capacities <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -286,7 +266,6 @@ forecasted_transfer_capacities <- function( } - #' @title #' Get Day-Ahead Commercial Schedules (12.1.F) #' @@ -328,25 +307,21 @@ day_ahead_commercial_sched <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -374,7 +349,6 @@ day_ahead_commercial_sched <- function( } - #' @title #' Get Total Commercial Schedules (12.1.F) #' @@ -417,24 +391,19 @@ total_commercial_sched <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), tz = "CET"), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -462,7 +431,6 @@ total_commercial_sched <- function( } - #' @title #' Get Cross-Border Physical Flows (12.1.G) #' @@ -507,25 +475,21 @@ cross_border_physical_flows <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format @@ -552,7 +516,6 @@ cross_border_physical_flows <- function( } - #' @title title #' Get Redispatching Cross Border (13.1.A) #' @@ -586,21 +549,17 @@ redispatching_cross_border <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -627,7 +586,6 @@ redispatching_cross_border <- function( } - #' @title #' Get Redispatching Internal (13.1.A) #' @@ -658,20 +616,16 @@ redispatching_cross_border <- function( redispatching_internal <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -698,7 +652,6 @@ redispatching_internal <- function( } - #' @title title #' Get Countertrading (13.1.B) #' @@ -734,21 +687,17 @@ countertrading <- function( eic_in = NULL, eic_out = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 1L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic_in)) stop("One 'in' control area EIC should be provided.") - if (is.null(eic_out)) stop("One 'out' control area EIC should be provided.") - if (length(eic_in) > 1L || length(eic_out) > 1L) { - stop("This wrapper only supports one in and one out EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") + checkmate::assert_string(x = eic_in, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(x = eic_out, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) # convert timestamps into accepted format period_start <- url_posixct_format(period_start) @@ -774,7 +723,6 @@ countertrading <- function( } - #' @title #' Get Costs of Congestion Management (13.1.C) #' @@ -811,30 +759,25 @@ countertrading <- function( costs_of_congestion_management <- function( eic = NULL, period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 31L), - tz = "CET"), + tz = "CET" + ), period_end = lubridate::ymd(Sys.Date(), - tz = "CET"), + tz = "CET" + ), event_nature = NULL, tidy_output = TRUE, security_token = Sys.getenv("ENTSOE_PAT") ) { - # check if only one eic provided - if (is.null(eic)) stop("One control area EIC should be provided.") - if (length(eic) > 1L) { - stop("This wrapper only supports one EIC per request.") - } - - # check if valid security token is provided - if (security_token == "") stop("Valid security token should be provided.") - - # check if event_nature value is valid - if (isFALSE(event_nature %in% c("A46", "B03", "B04"))) { - stop("The 'event_nature' parameter should be 'A46', 'B03', 'B04' or NULL.") - } + checkmate::assert_string(x = eic, n.chars = 16L, pattern = "^[A-Z0-9-]*$") + checkmate::assert_string(security_token, min.chars = 1L) + checkmate::assert_choice( + event_nature, + choices = c("A46", "B03", "B04"), null.ok = TRUE + ) # check if the requested period is not longer than one year if (difftime(period_end, period_start, units = "day") > 365L) { - stop("One year range limit should be applied!") + cli::cli_abort("One year range limit should be applied!") } # convert timestamps into accepted format diff --git a/R/entsoeapi-package.R b/R/entsoeapi-package.R new file mode 100644 index 00000000..60c86503 --- /dev/null +++ b/R/entsoeapi-package.R @@ -0,0 +1,12 @@ +#' @title +#' An R Interface to the ENTSO-E Transparency Platform API +#' +#' @description +#' an easy wrapper around the ENTSO-E +#' [API](https://documenter.getpostman.com/view/7009892/2s93JtP3F6)'s data and +#' transform them to tabular format without effort. +#' +#' @name entsoeapi +#' @aliases entsoeapi-package +#' @keywords internal +NULL diff --git a/R/utils.R b/R/utils.R index 6918e936..e0cbbe72 100644 --- a/R/utils.R +++ b/R/utils.R @@ -7,11 +7,12 @@ m <- cachem::cache_mem(max_age = 3600) - utils::globalVariables( c( "allocation_mode_types", "analog_types", + "api_req_safe", + "area_eic", "asset_types", "auction_types", "business_types", @@ -23,11 +24,16 @@ utils::globalVariables( "currency_types", "curve_types", "direction_types", + "doc_status", "eic_types", "energy_product_types", + "extract_response", "fuel_types", + "get_all_allocated_eic", + "get_eiccodes", "hvdc_mode_types", "indicator_types", + "m", "market_product_types", "message_types", "object_aggregation_types", @@ -39,25 +45,24 @@ utils::globalVariables( "role_types", "status_types", "tariff_types", + "there_is_provider", "timeframe_types", + "TimeSeries.mRID", "transmission_pair_eic_dict", + "ts_point_position", + "ts_resolution", + "ts_resolution_ok", + "ts_resolution_real_length", + "ts_resolution_requ_length", + "ts_time_interval_start", "unit_multiplier", "unit_of_measure_types", "unit_symbol_types", - "area_eic", - "m", - "ts_resolution", - "ts_time_interval_start", - "ts_point_position", - "ts_resolution_requ_length", - "ts_resolution_real_length", - "ts_resolution_ok", - "TimeSeries.mRID" + "url_posixct_format" ) ) - #' @title #' Organize list of strings into group #' @@ -70,8 +75,12 @@ utils::globalVariables( grouping_by_common_strings <- function(vector_list) { n <- length(vector_list) - if (n == 0) return(list()) - if (n == 1) return(list(1L)) + if (n == 0L) { + return(list()) + } + if (n == 1L) { + return(list(1L)) + } # Build an inverted index: string -> vector indices containing that string string_to_indices <- new.env(hash = TRUE) @@ -126,7 +135,6 @@ grouping_by_common_strings <- function(vector_list) { } - #' @title #' Calculate the Number of Children for a Given Nodeset #' @@ -139,13 +147,14 @@ grouping_by_common_strings <- function(vector_list) { number_of_children <- function(nodeset) { have_no_child <- purrr::map_lgl( xml2::xml_children(nodeset), - ~xml2::xml_children(.x) |> unlist(recursive = FALSE) |> is.null() + ~ xml2::xml_children(.x) |> + unlist(recursive = FALSE) |> + is.null() ) sum(have_no_child == FALSE) } - #' @title #' Extract the Contents of XML nodesets #' @@ -182,7 +191,7 @@ extract_nodesets <- function(nodesets, prefix = NULL) { # adjust column names accordingly purrr::map( unique_names, - ~named_vect[names(named_vect) == .x] + ~ named_vect[names(named_vect) == .x] ) |> data.table::as.data.table() |> stats::setNames(nm = unique_names) @@ -191,7 +200,6 @@ extract_nodesets <- function(nodesets, prefix = NULL) { } - #' @title #' Extract Data From an XML Document into Tabular Format #' @@ -220,7 +228,7 @@ extract_leaf_twig_branch <- function(nodesets) { xml2::xml_path() child_nodesets <- purrr::map( my_xml_paths, - ~xml2::xml_find_all(x = scnd_ns, xpath = .x) + ~ xml2::xml_find_all(x = scnd_ns, xpath = .x) ) # convert the childless child nodes into a table @@ -247,7 +255,7 @@ extract_leaf_twig_branch <- function(nodesets) { } else { compound_tbls[[2L]] <- seq_along(nodeset_groups) |> purrr::map( - ~nodeset_tbls[nodeset_groups[[.x]]] |> + ~ nodeset_tbls[nodeset_groups[[.x]]] |> data.table::rbindlist(use.names = TRUE, fill = TRUE) ) |> dplyr::bind_cols() @@ -259,7 +267,6 @@ extract_leaf_twig_branch <- function(nodesets) { dplyr::bind_cols() compound_tbl - } ) |> data.table::rbindlist(use.names = TRUE, fill = TRUE) @@ -281,7 +288,6 @@ extract_leaf_twig_branch <- function(nodesets) { #' #' @noRd tidy_or_not <- function(tbl, tidy_output = FALSE) { - # detect if there is any 'bid_ts_' column names bid_ts_cols <- stringr::str_subset( string = names(tbl), @@ -360,7 +366,6 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { # if curve_type not defined or 'A01', then if (is.null(curve_type) || curve_type == "A01") { - # do nothing in this case Sys.sleep(time = 0) @@ -389,7 +394,6 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { # check if there is any need to adjust the timeseries data points if (nrow(tbl_adj) > 0L) { - # remove the to be adjusted rows from the base 'tbl' # or in other words stash the records with 'ok' resolution tbl <- base::subset(x = tbl, subset = ts_resolution_ok) @@ -407,7 +411,7 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { ) |> unique() |> purrr::pmap( - ~tibble::tibble( + ~ tibble::tibble( ts_time_interval_start = ..1, ts_time_interval_end = ..2, ts_point_position = seq.int(from = 1, to = ..3), @@ -450,20 +454,13 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { "ts_point_position" ) ) - } - } else { - # hints: https://eepublicdownloads.entsoe.eu/clean-documents/EDI/ # Library/cim_based/ # Introduction_of_different_Timeseries_possibilities__curvetypes # __with_ENTSO-E_electronic_document_v1.4.pdf - stop( - sprintf("The curve type is not defined, but %s!", curve_type), - call. = FALSE - ) - + cli::cli_abort("The curve type is not defined, but {curve_type}!") } # calculate the 'ts_point_dt_start' values accordingly @@ -477,14 +474,13 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { from = min(ts_time_interval_start), length.out = max(ts_point_position), by = unique(by), - )[ts_point_position] |> # handle the unusual case of any missing period + )[ts_point_position] |> # handle the unusual case of any missing period as.POSIXct(tz = "UTC") ) |> dplyr::ungroup() # if tidy output is needed, then if (tidy_output == TRUE) { - # set the not_needed_cols not_needed_cols <- c( "ts_point_position", "by", "ts_resolution_requ_length", @@ -497,9 +493,7 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { y = names(tbl) ) tbl[not_needed_cols] <- list(NULL) - } else { - # set the not_needed_cols not_needed_cols <- c( "ts_point_dt_start", "by", "ts_resolution_requ_length", @@ -518,7 +512,6 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { tbl, ts_point = tidyselect::all_of(ts_point_cols) ) - } # convert the original 'bid_ts_' column names back @@ -535,7 +528,6 @@ tidy_or_not <- function(tbl, tidy_output = FALSE) { } - #' @title #' calculate offset URLs #' @@ -579,14 +571,13 @@ calc_offset_urls <- function(reason, query_string) { all_offset_seq <- (seq(all_offset_nr) - 1L) * docs_allowed # recompose offset URLs - message("*** The request has been rephrased. ***") + cli::cli_alert_info("*** The request has been rephrased. ***") query_string <- query_string |> gsub(pattern = "\\&offset=[0-9]+", replacement = "") paste0(query_string, "&offset=", all_offset_seq) } - #' @title #' read XML content from a zip compressed file #' @@ -602,19 +593,17 @@ read_zipped_xml <- function(temp_file_path) { # read the xml content from each the decompressed files en_cont_list <- unzipped_files$result |> - purrr::map(~{ + purrr::map(~ { xml_content <- xml2::read_xml(.x) - message(.x, " has been read in") + cli::cli_alert_success("{.x} has been read in") return(xml_content) }) # return with the xml content list en_cont_list - } - #' @title #' call request against the ENTSO-E API and converts the response into xml #' @@ -626,21 +615,13 @@ api_req <- function( query_string = NULL, security_token = NULL ) { - if (is.null(query_string)) { - stop("The argument 'query_string' is missing!", call. = FALSE) - } - if (is.null(security_token)) { - stop( - "The argument 'security_token' is not provided!", - call. = FALSE - ) - } else { - # add the canonical API prefix and suffix to the request url - url <- paste0( - api_scheme, api_domain, api_name, query_string, "&securityToken=" - ) - cat(url, "<...>\n", sep = "") - } + checkmate::assert_string(query_string) + checkmate::assert_string(security_token) + url <- paste0( + api_scheme, api_domain, api_name, query_string, "&securityToken=" + ) + cli::cli_h1("API call") + cli::cli_alert("{url}<...>") # retrieve data from the API req <- httr2::request(base_url = paste0(url, security_token)) |> @@ -657,11 +638,10 @@ api_req <- function( if (is.null(x = resp$error)) { result_obj <- resp$result - message("response has arrived") + cli::cli_alert_success("response has arrived") # if the get request is successful, then ... if (httr2::resp_status(resp = result_obj) == 200) { - # retrieve content-type from response headers rhct <- httr2::resp_content_type(resp = result_obj) expt_zip <- c( @@ -675,7 +655,6 @@ api_req <- function( # if the request is a zip file, then ... if (rhct %in% expt_zip) { - # save raw data to disk from memory temp_file_path <- tempfile(fileext = ".zip") writeBin( @@ -688,29 +667,22 @@ api_req <- function( # return with the xml content list en_cont_list - } else if (rhct %in% expt_xml) { - # read the xml content from the response and return result_obj |> httr2::resp_body_xml(encoding = "UTF-8") - } else { - - stop( - sprintf("Not known response content-type: %s", - result_obj$headers$`content-type`), - call. = FALSE + cli::cli_abort( + "Not known response content-type: {result_obj$headers$`content-type`}" ) - } } - } else { error_obj <- resp$error # retrieve content-type from response headers - if (is.null(error_obj$resp)) stop(error_obj$parent$message, call. = FALSE) + if (isTRUE(error_obj$status == 503)) cli::cli_abort(error_obj$message) + if (is.null(error_obj$resp)) cli::cli_abort(error_obj$parent$message) rhct <- httr2::resp_content_type(resp = error_obj$resp) expt_html <- c("text/html") expt_xml <- c("text/xml", "application/xml") @@ -724,10 +696,8 @@ api_req <- function( xmlconvert::xml_to_list() |> purrr::pluck("body") - stop( - sprintf("%s: %s", response_reason_code, response_reason_text), - call. = FALSE - ) + sprintf("/s: %s", response_reason_code, response_reason_text) |> + cli::cli_abort() } if (rhct %in% expt_xml) { @@ -739,11 +709,11 @@ api_req <- function( if (!is.list(response_reason) || !identical(names(response_reason), c("code", "text"))) { - stop( - sprintf("%s: %s", - httr2::resp_status(error_obj$resp), - httr2::resp_status_desc(error_obj$resp)), - call. = FALSE + cli::cli_abort( + paste( + "{httr2::resp_status(error_obj$resp)}:", + "{httr2::resp_status_desc(error_obj$resp)}" + ) ) } @@ -781,7 +751,7 @@ api_req <- function( # recursively call the api_req() function itself en_cont_list <- offset_query_strings |> purrr::map( - ~api_req( + ~ api_req( query_string = .x, security_token = security_token ) @@ -791,12 +761,9 @@ api_req <- function( } } - stop(paste(response_reason, collapse = "\n"), call. = FALSE) + cli::cli_abort(paste(response_reason, collapse = "\n")) } else { - stop( - sprintf("%s: %s", response_reason$code, response_reason$text), - call. = FALSE - ) + cli::cli_abort("{response_reason$code}: {response_reason$text}") } } @@ -805,14 +772,12 @@ api_req <- function( response_reason <- error_obj$resp |> httr2::resp_body_json(encoding = "utf-8") |> purrr::pluck("uuAppErrorMap", "URI_FORMAT_ERROR") - stop(response_reason$message, call. = FALSE) + cli::cli_abort(response_reason$message) } - } } - #' @title #' safely call api_req() function #' @@ -820,7 +785,6 @@ api_req <- function( api_req_safe <- purrr::safely(api_req) - #' @title #' safely call req_perform() function #' @@ -828,7 +792,6 @@ api_req_safe <- purrr::safely(api_req) req_perform_safe <- purrr::safely(httr2::req_perform) - #' @title #' converts the given POSIXct or character timestamp into the acceptable format #' @@ -839,45 +802,41 @@ url_posixct_format <- function(x) { } else if (inherits(x = x, what = "POSIXct")) { y <- strftime(x = x, format = "%Y%m%d%H%M", tz = "UTC", usetz = FALSE) } else if (inherits(x = x, what = "character")) { - y <- lubridate::parse_date_time(x = x, - orders = c("%Y-%m-%d %H:%M:%S", - "%Y-%m-%d %H:%M", - "%Y-%m-%d", - "%Y.%m.%d %H:%M:%S", - "%Y.%m.%d %H:%M", - "%Y.%m.%d", - "%Y%m%d%H%M%S", - "%Y%m%d%H%M", - "%Y%m%d"), - tz = "UTC", - quiet = TRUE) |> + y <- lubridate::parse_date_time( + x = x, + orders = c( + "%Y-%m-%d %H:%M:%S", + "%Y-%m-%d %H:%M", + "%Y-%m-%d", + "%Y.%m.%d %H:%M:%S", + "%Y.%m.%d %H:%M", + "%Y.%m.%d", + "%Y%m%d%H%M%S", + "%Y%m%d%H%M", + "%Y%m%d" + ), + tz = "UTC", + quiet = TRUE + ) |> strftime(format = "%Y%m%d%H%M", tz = "UTC", usetz = FALSE) if (is.na(y)) { - stop( + cli::cli_abort( paste( "Only the class POSIXct or '%Y-%m-%d %H:%M:%S' formatted text", "are supported by the converter." - ), - call. = FALSE + ) ) } else { - warning( - "The ", x, " value has been interpreted as UTC!", - call. = FALSE - ) + cli::cli_alert_warning("The {x} value has been interpreted as UTC!") } } else { - stop( - "The argument is not in an acceptable timestamp format!", - call. = FALSE - ) + cli::cli_abort("The argument is not in an acceptable timestamp format!") } y } - #' @title #' downloads approved Energy Identification Codes #' @@ -904,12 +863,18 @@ get_eiccodes <- function( ) if (is.null(content$error)) { lns <- content$result |> - stringr::str_replace_all(pattern = "tutkimustehdas;\\sImatra", - replacement = "tutkimustehdas, Imatra") |> - stringr::str_replace_all(pattern = "; S\\.L\\.;", - replacement = ", S.L.;") |> - stringr::str_replace_all(pattern = "\\$amp;", - replacement = "&") + stringr::str_replace_all( + pattern = "tutkimustehdas;\\sImatra", + replacement = "tutkimustehdas, Imatra" + ) |> + stringr::str_replace_all( + pattern = "; S\\.L\\.;", + replacement = ", S.L.;" + ) |> + stringr::str_replace_all( + pattern = "\\$amp;", + replacement = "&" + ) # reading lines as they would be a csv eiccodes <- data.table::fread( @@ -921,7 +886,7 @@ get_eiccodes <- function( # trimming character columns eiccodes <- eiccodes |> - purrr::map(~{ + purrr::map(~ { if (is.character(.x)) { utf8::utf8_encode(x = .x) |> trimws(which = "both") @@ -933,14 +898,12 @@ get_eiccodes <- function( # return eiccodes - } else { - stop(content$error$message, call. = FALSE) + cli::cli_abort(content$error$message) } } - #' @title #' downloads all allocated Energy Identification Codes #' @@ -977,7 +940,7 @@ get_all_allocated_eic <- function() { resp <- req_perform_safe(req = req) if (is.null(resp$error)) { - message("response has arrived") + cli::cli_alert_success("response has arrived") # read the xml content from each the decompressed files en_cont <- httr2::resp_body_raw(resp = resp$result) |> @@ -1009,14 +972,16 @@ get_all_allocated_eic <- function() { # compose a sub table from the second level data second_level_length <- nodesets[children_of_nodes > 0L] |> length() + prb_envir2 <- parent.frame() + cli::cli_progress_bar( + name = "converting", + total = second_level_length, + .envir = prb_envir2 + ) second_level_tbl <- nodesets[children_of_nodes > 0L] |> purrr::imap( \(scnd_ns, idx) { - times <- second_level_length - idx + 1L - if (times %% 1000L == 0L) { - thsnd_idx <- (idx - 1L) %/% 1000L + 1L - message(thsnd_idx, " ", rep(x = "<", times = times %/% 1000L)) - } + cli::cli_progress_update(.envir = prb_envir2) # extract as named list nodeset_list <- xmlconvert::xml_to_list( xml = scnd_ns, @@ -1045,19 +1010,23 @@ get_all_allocated_eic <- function() { ) |> purrr::compact() |> data.table::rbindlist(use.names = TRUE, fill = TRUE) |> - dplyr::rename(dplyr::any_of(c(eic_code = "mRID", - docStatusValue = "docStatus"))) + dplyr::rename(dplyr::any_of(c( + eic_code = "mRID", + docStatusValue = "docStatus" + ))) # combine the first level and the second levels tables together dplyr::bind_cols(first_level_tbl, second_level_tbl) }, error = \(e) { - stop("The XML document has an unexpected tree structure!\n", e) + cli::cli_abort( + "The XML document has an unexpected tree structure! {e}" + ) # nocov } ) if (nrow(result_tbl) == 0L) { - stop("The XML document has an unexpected tree structure!") + cli::cli_abort("The XML document has an unexpected tree structure!") } # rename columns to snakecase @@ -1079,14 +1048,12 @@ get_all_allocated_eic <- function() { # return with the xml content list tibble::as_tibble(result_tbl) - } else { - stop(sprintf("%s\n%s", resp$error$message, req$url)) + cli::cli_abort("{resp$error$message} {req$url}") } } - #' @title #' unpack an xml section into a tabular row #' @@ -1098,9 +1065,10 @@ unpack_xml <- function(section, parent_name = NULL) { tbl <- tibble::tibble() } else { names(result_vector) <- stringr::str_c(parent_name, - xml2::xml_name(section), - names(result_vector), - sep = ".") + xml2::xml_name(section), + names(result_vector), + sep = "." + ) tbl <- tibble::as_tibble_row(result_vector) } # return @@ -1108,7 +1076,6 @@ unpack_xml <- function(section, parent_name = NULL) { } - #' @title #' an own version of snakecase::to_snakecase() function #' @@ -1118,12 +1085,7 @@ unpack_xml <- function(section, parent_name = NULL) { #' #' @noRd my_snakecase <- function(tbl) { - if (isFALSE(is.data.frame(tbl))) { - stop( - "The provided argument is not a valid data frame!", - call. = FALSE - ) - } + checkmate::assert_data_frame(tbl) names(tbl) |> stringr::str_replace_all( c( @@ -1179,7 +1141,6 @@ my_snakecase <- function(tbl) { } - #' @title #' create a specific merge function which adds the needed definitions #' @@ -1201,7 +1162,6 @@ def_merge <- function(x, y, code_name, definition_name) { } - #' @title #' create a specific merge function which adds the EIC names #' @@ -1220,7 +1180,6 @@ eic_name_merge <- function(x, y, eic_code_name, eic_name_name) { } - #' @title #' add type names to codes #' @@ -1349,14 +1308,13 @@ add_type_names <- function(tbl) { ) } if (length(affected_cols) == 0L) { - cat("No additional type names added!", sep = "\n") + cli::cli_alert_info("No additional type names added!") } tbl } - #' @title #' get & adjust area_eic() table #' @@ -1389,13 +1347,11 @@ get_area_eic_name <- function() { # check if there is any cached value of 'area_eic_name' aen_cache_key <- "area_eic_name_key" if (m$exists(key = aen_cache_key)) { - # recall area_eic_name values area_eic_name <- m$get( key = aen_cache_key, missing = get_data() ) - } else { # download area_eic() table & convert to data.table # in order to join faster @@ -1409,7 +1365,6 @@ get_area_eic_name <- function() { } - #' @title #' get & adjust resource_object_eic() table #' @@ -1439,13 +1394,11 @@ get_resource_object_eic <- function( # check if there is any cached value of 'area_eic_name' if (m$exists(key = roe_cache_key)) { - # recall resource_object_eic_name values resource_object_eic <- m$get( key = roe_cache_key, missing = get_data() ) - } else { # download resource_object_eic() table & convert to data.table # in order to join faster @@ -1460,13 +1413,11 @@ get_resource_object_eic <- function( } - #' @title #' add names to EIC codes #' #' @noRd add_eic_names <- function(tbl) { - # convert tbl to data.table in order to join faster tbl <- data.table::data.table(tbl) @@ -1480,7 +1431,6 @@ add_eic_names <- function(tbl) { # add names to eic codes if ("ts_registered_resource_mrid" %in% names(tbl)) { - # download & convert resource_object_eic() table to data.table # in order to join faster resource_object_eic <- get_resource_object_eic() @@ -1488,9 +1438,11 @@ add_eic_names <- function(tbl) { affected_cols <- c(affected_cols, "ts_registered_resource_mrid") tbl <- tbl |> dplyr::select(!tidyselect::any_of("ts_registered_resource_name")) |> - merge(y = resource_object_eic, - by = "ts_registered_resource_mrid", - all.x = TRUE) + merge( + y = resource_object_eic, + by = "ts_registered_resource_mrid", + all.x = TRUE + ) } if ("ts_bidding_zone_domain_mrid" %in% names(tbl)) { affected_cols <- c(affected_cols, "ts_bidding_zone_domain_mrid") @@ -1612,14 +1564,13 @@ add_eic_names <- function(tbl) { ) } if (length(affected_cols) == 0L) { - cat("No additional eic names added!", sep = "\n") + cli::cli_alert_info("No additional eic names added!") } tbl } - #' @title #' add definitions to codes #' @@ -1756,14 +1707,13 @@ add_definitions <- function(tbl) { ) } if (length(affected_cols) == 0L) { - cat("No additional definitions added!", sep = "\n") + cli::cli_alert_info("No additional definitions added!") } tbl } - #' @title #' convert xml content to table new version #' @@ -1771,20 +1721,14 @@ add_definitions <- function(tbl) { xml_to_table <- function(xml_content, tidy_output = FALSE) { is_xml_document <- inherits(x = xml_content, what = "xml_document") if (isFALSE(is_xml_document)) { - stop( - "The 'xml_content' should be an xml document!", - call. = FALSE - ) + cli::cli_abort("The 'xml_content' should be an xml document!") } # extract nodesets from the XML document and process result_tbl <- tryCatch( expr = xml2::xml_contents(xml_content) |> extract_leaf_twig_branch(), error = \(e) { - stop( - sprintf("The XML document has an unexpected tree structure!\n%s", e), - call. = FALSE - ) + cli::cli_abort("The XML document has an unexpected tree structure! {e}") } ) @@ -1816,7 +1760,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { dplyr::mutate( dplyr::across( tidyselect::matches("[t|T]ime$|start$|end$"), - ~as.POSIXct( + ~ as.POSIXct( x = .x, tryFormats = c( "%Y-%m-%dT%H:%MZ", "%Y-%m-%dT%H:%M:%SZ", "%Y-%m-%dT%H:%M:%OSZ" @@ -1831,7 +1775,7 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { match = "number$|position$|quantity$|nominalP$|amount$", ignore.case = TRUE ), - ~as.numeric(x = .x) + ~ as.numeric(x = .x) ) ) @@ -1965,8 +1909,10 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { "constraint_ts_monitored_ptdf_domain_quantity", "constraint_ts_monitored_flow_based_study_domain_margin_quantity" ) - needed_cols <- base::intersect(x = needed_cols, - y = names(result_tbl)) + needed_cols <- base::intersect( + x = needed_cols, + y = names(result_tbl) + ) # check if any columns left to keep if (length(needed_cols)) { @@ -1975,11 +1921,15 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { dplyr::select(tidyselect::all_of(needed_cols)) # reorder the rows - sort_cols <- base::intersect(x = c("created_date_time", "ts_mrid", - "ts_business_type", "ts_mkt_psr_type", - "ts_time_interval_start", - "ts_point_dt_start"), - y = names(result_tbl)) + sort_cols <- base::intersect( + x = c( + "created_date_time", "ts_mrid", + "ts_business_type", "ts_mkt_psr_type", + "ts_time_interval_start", + "ts_point_dt_start" + ), + y = names(result_tbl) + ) result_dtbl <- data.table::as.data.table(result_tbl) data.table::setkeyv(x = result_dtbl, cols = sort_cols) @@ -1988,36 +1938,27 @@ xml_to_table <- function(xml_content, tidy_output = FALSE) { # return result_tbl - } else { - stop( - "There is no interesting column in the result table!", - call. = FALSE - ) + cli::cli_abort("There is no interesting column in the result table!") } - } - #' @title #' extract the response from content list #' #' @noRd extract_response <- function(content, tidy_output = TRUE) { - # check if the content is in the required list format is_in_format <- is.list(content) && length(content) == 2L && all(names(content) == c("result", "error")) if (is_in_format) { - # extract the possible failure reason reason <- content$error # if valid content got if (is.null(reason)) { - # check if the response is list result_is_list <- inherits(x = content$result, what = "list") @@ -2026,43 +1967,47 @@ extract_response <- function(content, tidy_output = TRUE) { if (result_is_list) { # convert XMLs to one table response_length <- length(content$result) + prb_envir <- parent.frame() + cli::cli_progress_bar( + name = "processing xml list", + total = response_length, + .envir = prb_envir + ) result_tbl <- content$result |> purrr::imap( - \(x, idx) { - times <- response_length - idx + 1L - if (times > 1L) { - message( - idx, " ", rep(x = "<", times = times) - ) - } - if (is.null(x)) { - NULL - } else { - if (inherits(x = x, what = "list")) { - all_doc <- purrr::map_lgl( - x, inherits, what = "xml_document" - ) |> - all() - if (all_doc) { - purrr::map( - x, xml_to_table, tidy_output = tidy_output - ) |> - purrr::compact() |> - data.table::rbindlist( - use.names = TRUE, - fill = TRUE - ) - } else { - NULL - } - } else { - xml_to_table( - xml_content = x, - tidy_output = tidy_output - ) - } - } - }) |> + \(x, idx) { + cli::cli_progress_update(.envir = prb_envir) + if (is.null(x)) { + NULL + } else { + if (inherits(x = x, what = "list")) { + all_doc <- purrr::map_lgl( + x, inherits, + what = "xml_document" + ) |> + all() + if (all_doc) { + purrr::map( + x, xml_to_table, + tidy_output = tidy_output + ) |> + purrr::compact() |> + data.table::rbindlist( + use.names = TRUE, + fill = TRUE + ) + } else { + NULL + } + } else { + xml_to_table( + xml_content = x, + tidy_output = tidy_output + ) + } + } + } + ) |> purrr::compact() |> data.table::rbindlist(use.names = TRUE, fill = TRUE) |> tibble::as_tibble() @@ -2076,18 +2021,30 @@ extract_response <- function(content, tidy_output = TRUE) { # return result_tbl - } else { - - stop(reason$message, call. = FALSE) - + cli::cli_abort(reason$message) } } else { + cli::cli_abort("The content is not in the required list format!") + } +} - stop( - "The content is not in the required list format!", - call. = FALSE - ) - } +#' @title +#' check if the Entso-e API provider is up and ready +#' +#' @noRd +there_is_provider <- function( + api_scheme = "https://", + api_domain = "web-api.tp.entsoe.eu/", + api_name = "api?" +) { + req <- paste0( + api_scheme, api_domain, api_name, "foo=bar&securityToken=baz" + ) |> + httr2::request() |> + httr2::req_method(method = "GET") |> + httr2::req_retry(max_tries = 1L) + resp <- req_perform_safe(req) + if (resp$error$message == "HTTP 401 Unauthorized.") TRUE else FALSE } diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 00000000..6259bcc1 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,195 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# entsoeapi ![hexa sticker](man/figures/logo.png){width="120" height="120"} + + + +[![Lifecycle:experimental](https://lifecycle.r-lib.org/articles/figures/lifecycle-experimental.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\ +[![lint-project.yml](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml)\ +[![R-CMD-check](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml)\ +[![test-coverage.yml](https://github.com/krose/entsoeapi/actions/workflows/test-coverage.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/test-coverage.yml) + + + +The goal of `entsoeapi` package is to create an easy wrapper around the ENTSO-E [API](https://documenter.getpostman.com/view/7009892/2s93JtP3F6)'s data and transform them to tabular format without effort. (The downloadable data are available interactively on the ENTSO-E [transparency platform](https://transparency.entsoe.eu/) website as well.) + +The package helps with + +- displaying the queried endpoint URL to easier double check +- upfront checking of function arguments' validity to avoid useless API calls +- query pagination, by allowing the user to not worry about it at all since the package does all necessary requests +- unpacking compressed file responses +- caching data to enhance processing speed +- converting XML structures to tabular ones +- composing consistent and detailed outputs +- providing related, but not API accessible data (for instance: business_types) +- automatic assigning definitions to codes +- calculating and adding timestamps to data points (the response xml does not contain such information explicitly) + +------------------------------------------------------------------------ + +- Already available ENTSO-E API endpoints: + - MARKET + - implicit_offered_transfer_capacities (11.1) (beta test version) + - explicit_offered_transfer_capacities (11.1.A) (beta test version) + - continuous_offered_transfer_capacities (11.1) (beta test version) + - flow_based_allocations (11.1.B) (beta test version) + - auction_revenue (12.1.A) (beta test version) + - total_nominated_capacity (12.1.B) + - already_allocated_total_capacity (12.1.C) + - day_ahead_prices (12.1.D) + - net_positions (12.1.E) (beta test version) + - congestion_income (12.1.E) (beta test version) + - allocated_transfer_capacities_3rd_countries (12.1.H) (beta test version) + - LOAD + - load_actual_total (6.1.A) + - load_day_ahead_total_forecast (6.1.B) + - load_week_ahead_total_forecast (6.1.C) + - load_month_ahead_total_forecast (6.1.D) + - load_year_ahead_total_forecast (6.1.E) + - load_year_ahead_forecast_margin (8.1) + - GENERATION + - gen_installed_capacity_per_pt (14.1.A) + - the gen_installed_capacity_per_pu (14.1.B) + - gen_day_ahead (14.1.C) + - gen_wind_solar_forecasts (14.1.D) + - gen_per_gen_unit (16.1.A) + - gen_per_prod_type (16.1.B&C) + - the gen_storage_mean_filling_rate (16.1.D) + - TRANSMISSION + - expansion_and_dismantling_project (9.1) (beta test version) + - intraday_cross_border_transfer_limits (11.3) (beta test version) + - forecasted_transfer_capacities (11.1.A) + - day_ahead_commercial_sched (12.1.F) + - total_commercial_sched (12.1.F) + - cross_border_physical_flows (12.1.G) + - redispatching_internal (13.1.A) + - redispatching_cross_border (13.1.A) + - countertrading (13.1.B) + - costs_of_congestion_management (13.1.C) + - OUTAGES + - outages_cons_units (7.1.A&B) + - outages_fallbacks (IFs IN 7.2, mFRR 3.11, aFRR 3.10) + - outages_transmission_grid (10.1.A&B) + - outages_offshore_grid (10.1.C) + - outages_gen_units (15.1.A&B) + - outages_prod_units (15.1.C&D) + - outages_both (15.1.A&B + 15.1.C&D) + - BALANCING + - exchanged_volumes (aFRR 3.16, mFRR 3.17) + - netted_volumes (IFs IN 3.10) + - elastic_demands (IF mFRR 3.4) + - balancing_border_cap_limit (IFs 4.3 & 4.4) + - exchanged_volumes_per_border (3.10, 3.16 & 3.17) (beta test version) + - netted_volumes_per_border (3.10, 3.16 & 3.17) (beta test version) + - hvdc_link_constrains (4.5) (beta test version) + - changes_to_bid_availability (mFRR 9.9, aFRR 9.6&9.8) (beta test version) + - current_balancing_state (12.3.A) (beta test version) + - balancing_energy_bids (12.3.B&C) (beta test version) + - aggregated_balancing_energy_bids (12.3.E) (beta test version) + - procured_balancing_capacity (12.3.F) (beta test version) + - allocation_of_cross_zonal_balancing_cap (12.3.H&I) (beta test version) + - contracted_reserves (17.1.B&C) (beta test version) + - activated_balancing_prices (17.1.F) (beta test version) + - imbalance_prices (17.1.G) (beta test version) + - imbalance_volumes (17.1.H) (beta test version) + - financial_expenses_and_income_for_balancing (17.1.I) (beta test version) + - fcr_total_capacity (187.2) (beta test version) + - shares_of_fcr_capacity (187.2) (beta test version) + - rr_and_frr_actual_capacity (188.4 & 189.3) (beta test version) + - rr_actual_capacity (189.3) (beta test version) + - sharing_of_frr_capacity (SO GL 190.1) (beta test version) + +Be aware, that not all API endpoints are implemented in this package, and not every endpoint provides data. + +If you would like to use an unimplemented endpoint, please submit an [issue](https://github.com/krose/entsoeapi/issues/new/choose) and we'll do our best to resolve it. + +If the endpoint is already implemented, but the related function gives back an empty table, then check the response XML in a browser using the request URL displayed in the console just after issuing the function call. Another verification option might be to check the response on the [Entsoe-e Transparency Platform](https://transparency.entsoe.eu/). + +In case of beta test version functions there may be unique quirks which are not handled yet. So please, compare the resulting tables to the data fn the [Entsoe-e Transparency Platform](https://transparency.entsoe.eu/). + +\ +IMPORTANT!\ +Since the underlying engine has fairly been standardized with the introduction of version 0.7.0.0, there are significant (breaking) changes between the 0.7.0.0 and the previous versions. + +## Installation + +You can install the development version of entsoeapi from [GitHub](https://github.com/krose/entsoeapi) with: + +```{r install, eval=FALSE} +if (!require("devtools", quietly = TRUE)) install.packages("devtools", quiet = TRUE) +devtools::install_github(repo = "krose/entsoeapi", ref = "master") +``` + +## Security token + +Read [here](https://transparencyplatform.zendesk.com/hc/en-us/articles/12845911031188-How-to-get-security-token) how to get a security token. You should also create a `.Renviron` file in your working directory with a security token and call it `ENTSOE_PAT`. + +```{r edit renviron, eval=FALSE} +if (!require("usethis", quietly = TRUE)) install.packages("usethis", quiet = TRUE) +usethis::edit_r_environ() +``` + +`ENTSOE_PAT = "your_security_token"` + +## Examples + +You use the eic codes to get the data. Let’s try to find the eic code for Germany. + +```{r example 1} +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr", quiet = TRUE) +entsoeapi::all_approved_eic() |> + dplyr::filter(EicLongName == "Germany") |> + dplyr::glimpse() +``` + +For some of the data you need to translate the generation codes. + +```{r example 2} +if (!require("knitr", quietly = TRUE)) install.packages("knitr", quiet = TRUE) +entsoeapi::asset_types |> + knitr::kable(format = "html") +``` + +Let’s get the demand of 2020-01-01 in Germany. + +```{r example 3} +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr") +entsoeapi::load_actual_total( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd("2020-01-01", tz = "CET"), + period_end = lubridate::ymd("2020-01-02", tz = "CET") +) |> + dplyr::glimpse() +``` + +This is basically how all the functions work, so let’s try to get the production data too. + +```{r example 4} +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr") +entsoeapi::gen_per_prod_type( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd("2020-01-01", tz = "CET"), + period_end = lubridate::ymd("2020-01-02", tz = "CET"), + gen_type = NULL, + tidy_output = TRUE +) |> + dplyr::glimpse() +``` + +## Code of Conduct + +Please note that the entsoeapi project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. diff --git a/README.md b/README.md index 5f106a7c..ff13e14d 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,195 @@ -# README - entsoeapi + + + +# entsoeapi -[![Lifecycle:experimental](https://lifecycle.r-lib.org/articles/figures/lifecycle-experimental.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\ -[![lint-project.yml](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml)\ -[![R-CMD-check](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml)\ +[![Lifecycle:experimental](https://lifecycle.r-lib.org/articles/figures/lifecycle-experimental.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![lint-project.yml](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/lint-project.yml) +[![R-CMD-check](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/R-CMD-check.yml) [![test-coverage.yml](https://github.com/krose/entsoeapi/actions/workflows/test-coverage.yml/badge.svg)](https://github.com/krose/entsoeapi/actions/workflows/test-coverage.yml) -The goal of `entsoeapi` package is to create an easy wrapper for querying the ENTSO-E [API](https://documenter.getpostman.com/view/7009892/2s93JtP3F6)'s Market, Load, Generation, Transmission, Outages & Balancing data which are available on the ENTSO-E [transparency platform](https://transparency.entsoe.eu/) website as well. +The goal of `entsoeapi` package is to create an easy wrapper around the +ENTSO-E +[API](https://documenter.getpostman.com/view/7009892/2s93JtP3F6)’s data +and transform them to tabular format without effort. (The downloadable +data are available interactively on the ENTSO-E [transparency +platform](https://transparency.entsoe.eu/) website as well.) + +The package helps with + +- displaying the queried endpoint URL to easier double check +- upfront checking of function arguments’ validity to avoid useless API + calls +- query pagination, by allowing the user to not worry about it at all + since the package does all necessary requests +- unpacking compressed file responses +- caching data to enhance processing speed +- converting XML structures to tabular ones +- composing consistent and detailed outputs +- providing related, but not API accessible data (for instance: + business_types) +- automatic assigning definitions to codes +- calculating and adding timestamps to data points (the response xml + does not contain such information explicitly) ------------------------------------------------------------------------ -- Already available ENTSO-E API endpoints: - - MARKET - - implicit_offered_transfer_capacities (11.1) (beta test version) - - explicit_offered_transfer_capacities (11.1.A) (beta test version) - - continuous_offered_transfer_capacities (11.1) (beta test version) - - flow_based_allocations (11.1.B) (beta test version) - - auction_revenue (12.1.A) (beta test version) - - total_nominated_capacity (12.1.B) - - already_allocated_total_capacity (12.1.C) - - day_ahead_prices (12.1.D) - - net_positions (12.1.E) (beta test version) - - congestion_income (12.1.E) (beta test version) - - allocated_transfer_capacities_3rd_countries (12.1.H) (beta test version) - - LOAD - - load_actual_total (6.1.A) - - load_day_ahead_total_forecast (6.1.B) - - load_week_ahead_total_forecast (6.1.C) - - load_month_ahead_total_forecast (6.1.D) - - load_year_ahead_total_forecast (6.1.E) - - load_year_ahead_forecast_margin (8.1) - - GENERATION - - gen_installed_capacity_per_pt (14.1.A) - - the gen_installed_capacity_per_pu (14.1.B) - - gen_day_ahead (14.1.C) - - gen_wind_solar_forecasts (14.1.D) - - gen_per_gen_unit (16.1.A) - - gen_per_prod_type (16.1.B&C) - - the gen_storage_mean_filling_rate (16.1.D) - - TRANSMISSION - - expansion_and_dismantling_project (9.1) (beta test version) - - intraday_cross_border_transfer_limits (11.3) (beta test version) - - forecasted_transfer_capacities (11.1.A) - - day_ahead_commercial_sched (12.1.F) - - total_commercial_sched (12.1.F) - - cross_border_physical_flows (12.1.G) - - redispatching_internal (13.1.A) - - redispatching_cross_border (13.1.A) - - countertrading (13.1.B) - - costs_of_congestion_management (13.1.C) - - OUTAGES - - outages_cons_units (7.1.A&B) - - outages_fallbacks (IFs IN 7.2, mFRR 3.11, aFRR 3.10) - - outages_transmission_grid (10.1.A&B) - - outages_offshore_grid (10.1.C) - - outages_gen_units (15.1.A&B) - - outages_prod_units (15.1.C&D) - - outages_both (15.1.A&B + 15.1.C&D) - - BALANCING - - exchanged_volumes (aFRR 3.16, mFRR 3.17) - - netted_volumes (IFs IN 3.10) - - elastic_demands (IF mFRR 3.4) - - balancing_border_cap_limit (IFs 4.3 & 4.4) - - exchanged_volumes_per_border (3.10, 3.16 & 3.17) (beta test version) - - netted_volumes_per_border (3.10, 3.16 & 3.17) (beta test version) - - hvdc_link_constrains (4.5) (beta test version) - - changes_to_bid_availability (mFRR 9.9, aFRR 9.6&9.8) (beta test version) - - current_balancing_state (12.3.A) (beta test version) - - balancing_energy_bids (12.3.B&C) (beta test version) - - aggregated_balancing_energy_bids (12.3.E) (beta test version) - - procured_balancing_capacity (12.3.F) (beta test version) - - allocation_of_cross_zonal_balancing_cap (12.3.H&I) (beta test version) - - contracted_reserves (17.1.B&C) (beta test version) - - activated_balancing_prices (17.1.F) (beta test version) - - imbalance_prices (17.1.G) (beta test version) - - imbalance_volumes (17.1.H) (beta test version) - - financial_expenses_and_income_for_balancing (17.1.I) (beta test version) - - fcr_total_capacity (187.2) (beta test version) - - shares_of_fcr_capacity (187.2) (beta test version) - - rr_and_frr_actual_capacity (188.4 & 189.3) (beta test version) - - rr_actual_capacity (189.3) (beta test version) - -All the function calls convert the xml responses to tabular data. Be aware, that not all endpoints are implemented. If you want to use an unimplemented endpoint, please submit an [issue](https://github.com/krose/entsoeapi/issues/new/choose) and we'll do our best to resolve it.\ -IMPORTANT!\ -Since the underlying engine has fairly been standardized with the introduction of version 0.7.0.0, there are significant (breaking) changes between the 0.7.0.0 and the previous versions. +- Already available ENTSO-E API endpoints: + - MARKET + - implicit_offered_transfer_capacities (11.1) (beta test version) + - explicit_offered_transfer_capacities (11.1.A) (beta test version) + - continuous_offered_transfer_capacities (11.1) (beta test version) + - flow_based_allocations (11.1.B) (beta test version) + - auction_revenue (12.1.A) (beta test version) + - total_nominated_capacity (12.1.B) + - already_allocated_total_capacity (12.1.C) + - day_ahead_prices (12.1.D) + - net_positions (12.1.E) (beta test version) + - congestion_income (12.1.E) (beta test version) + - allocated_transfer_capacities_3rd_countries (12.1.H) (beta test + version) + - LOAD + - load_actual_total (6.1.A) + - load_day_ahead_total_forecast (6.1.B) + - load_week_ahead_total_forecast (6.1.C) + - load_month_ahead_total_forecast (6.1.D) + - load_year_ahead_total_forecast (6.1.E) + - load_year_ahead_forecast_margin (8.1) + - GENERATION + - gen_installed_capacity_per_pt (14.1.A) + - the gen_installed_capacity_per_pu (14.1.B) + - gen_day_ahead (14.1.C) + - gen_wind_solar_forecasts (14.1.D) + - gen_per_gen_unit (16.1.A) + - gen_per_prod_type (16.1.B&C) + - the gen_storage_mean_filling_rate (16.1.D) + - TRANSMISSION + - expansion_and_dismantling_project (9.1) (beta test version) + - intraday_cross_border_transfer_limits (11.3) (beta test version) + - forecasted_transfer_capacities (11.1.A) + - day_ahead_commercial_sched (12.1.F) + - total_commercial_sched (12.1.F) + - cross_border_physical_flows (12.1.G) + - redispatching_internal (13.1.A) + - redispatching_cross_border (13.1.A) + - countertrading (13.1.B) + - costs_of_congestion_management (13.1.C) + - OUTAGES + - outages_cons_units (7.1.A&B) + - outages_fallbacks (IFs IN 7.2, mFRR 3.11, aFRR 3.10) + - outages_transmission_grid (10.1.A&B) + - outages_offshore_grid (10.1.C) + - outages_gen_units (15.1.A&B) + - outages_prod_units (15.1.C&D) + - outages_both (15.1.A&B + 15.1.C&D) + - BALANCING + - exchanged_volumes (aFRR 3.16, mFRR 3.17) + - netted_volumes (IFs IN 3.10) + - elastic_demands (IF mFRR 3.4) + - balancing_border_cap_limit (IFs 4.3 & 4.4) + - exchanged_volumes_per_border (3.10, 3.16 & 3.17) (beta test + version) + - netted_volumes_per_border (3.10, 3.16 & 3.17) (beta test version) + - hvdc_link_constrains (4.5) (beta test version) + - changes_to_bid_availability (mFRR 9.9, aFRR 9.6&9.8) (beta test + version) + - current_balancing_state (12.3.A) (beta test version) + - balancing_energy_bids (12.3.B&C) (beta test version) + - aggregated_balancing_energy_bids (12.3.E) (beta test version) + - procured_balancing_capacity (12.3.F) (beta test version) + - allocation_of_cross_zonal_balancing_cap (12.3.H&I) (beta test + version) + - contracted_reserves (17.1.B&C) (beta test version) + - activated_balancing_prices (17.1.F) (beta test version) + - imbalance_prices (17.1.G) (beta test version) + - imbalance_volumes (17.1.H) (beta test version) + - financial_expenses_and_income_for_balancing (17.1.I) (beta test + version) + - fcr_total_capacity (187.2) (beta test version) + - shares_of_fcr_capacity (187.2) (beta test version) + - rr_and_frr_actual_capacity (188.4 & 189.3) (beta test version) + - rr_actual_capacity (189.3) (beta test version) + - sharing_of_frr_capacity (SO GL 190.1) (beta test version) + +Be aware, that not all API endpoints are implemented in this package, +and not every endpoint provides data. + +If you would like to use an unimplemented endpoint, please submit an +[issue](https://github.com/krose/entsoeapi/issues/new/choose) and we’ll +do our best to resolve it. + +If the endpoint is already implemented, but the related function gives +back an empty table, then check the response XML in a browser using the +request URL displayed in the console just after issuing the function +call. Another verification option might be to check the response on the +[Entsoe-e Transparency Platform](https://transparency.entsoe.eu/). + +In case of beta test version functions there may be unique quirks which +are not handled yet. So please, compare the resulting tables to the data +fn the [Entsoe-e Transparency +Platform](https://transparency.entsoe.eu/). + + +IMPORTANT! +Since the underlying engine has fairly been standardized with the +introduction of version 0.7.0.0, there are significant (breaking) +changes between the 0.7.0.0 and the previous versions. ## Installation -You can install this under development version from [GitHub](https://github.com/krose/entsoeapi) with: +You can install the development version of entsoeapi from +[GitHub](https://github.com/krose/entsoeapi) with: ``` r -install.packages("devtools") +if (!require("devtools", quietly = TRUE)) install.packages("devtools", quiet = TRUE) devtools::install_github(repo = "krose/entsoeapi", ref = "master") ``` ## Security token -Read [here](https://transparencyplatform.zendesk.com/hc/en-us/articles/12845911031188-How-to-get-security-token) how to get a security token. You should also create a `.Renviron` file in your working directory with a security token and call it ENTSOE_PAT. +Read +[here](https://transparencyplatform.zendesk.com/hc/en-us/articles/12845911031188-How-to-get-security-token) +how to get a security token. You should also create a `.Renviron` file +in your working directory with a security token and call it +`ENTSOE_PAT`. -``` shell -ENTSOE_PAT = "your_security_token" +``` r +if (!require("usethis", quietly = TRUE)) install.packages("usethis", quiet = TRUE) +usethis::edit_r_environ() ``` +`ENTSOE_PAT = "your_security_token"` + ## Examples -You use the eic codes to get the data. Let’s try to find the eic code for Germany. +You use the eic codes to get the data. Let’s try to find the eic code +for Germany. ``` r +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr", quiet = TRUE) +#> +#> Attaching package: 'dplyr' +#> The following objects are masked from 'package:stats': +#> +#> filter, lag +#> The following objects are masked from 'package:base': +#> +#> intersect, setdiff, setequal, union entsoeapi::all_approved_eic() |> dplyr::filter(EicLongName == "Germany") |> dplyr::glimpse() +#> ℹ downloading X_eicCodes.csv file ... +#> ℹ downloading Y_eicCodes.csv file ... +#> ℹ downloading Z_eicCodes.csv file ... +#> ℹ downloading T_eicCodes.csv file ... +#> ℹ downloading V_eicCodes.csv file ... +#> ℹ downloading W_eicCodes.csv file ... +#> ℹ downloading A_eicCodes.csv file ... #> Rows: 1 #> Columns: 11 #> $ EicCode "10Y1001A1001A83F" @@ -131,84 +208,1950 @@ entsoeapi::all_approved_eic() |> For some of the data you need to translate the generation codes. ``` r -dplyr::glimpse(entsoeapi::asset_types) -#> Rows: 90 -#> Columns: 3 -#> $ code "A01", "A02", "A03", "A04", "A05", "A06", "A07", "A0… -#> $ title "Tieline", "Line", "Resource Object", "Generation", … -#> $ description "A high voltage line used for cross border energy in… +if (!require("knitr", quietly = TRUE)) install.packages("knitr", quiet = TRUE) +entsoeapi::asset_types |> + knitr::kable(format = "html") ``` -Let’s get the demand in Germany. + -``` r -entsoeapi::load_actual_total( - eic = "10Y1001A1001A83F", - period_start = lubridate::ymd("2020-01-01", tz = "CET"), - period_end = lubridate::ymd("2020-01-02", tz = "CET") -) |> - dplyr::glimpse() -#> Rows: 96 -#> Columns: 21 -#> $ ts_out_bidding_zone_domain_mrid "10Y1001A1001A83F", "10Y1001A1001A83F", "1… -#> $ ts_out_bidding_zone_domain_name "Germany", "Germany", "Germany", "Germany"… -#> $ type "A65", "A65", "A65", "A65", "A65", "A65", … -#> $ type_def "System total load", "System total load", … -#> $ process_type "A16", "A16", "A16", "A16", "A16", "A16", … -#> $ process_type_def "Realised", "Realised", "Realised", "Reali… -#> $ ts_object_aggregation "A01", "A01", "A01", "A01", "A01", "A01", … -#> $ ts_object_aggregation_def "Area", "Area", "Area", "Area", "Area", "A… -#> $ ts_business_type "A04", "A04", "A04", "A04", "A04", "A04", … -#> $ ts_business_type_def "Consumption", "Consumption", "Consumption… -#> $ created_date_time 2024-10-05 19:48:09, 2024-10-05 19:48:09,… -#> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, … -#> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00:00,… -#> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00:00,… -#> $ ts_resolution "PT15M", "PT15M", "PT15M", "PT15M", "PT15M… -#> $ ts_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00:00,… -#> $ ts_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00:00,… -#> $ ts_mrid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, … -#> $ ts_point_dt_start 2019-12-31 23:00:00, 2019-12-31 23:15:00,… -#> $ ts_point_quantity 43881.80, 43639.59, 43330.90, 43149.49, 43… -#> $ ts_quantity_measure_unit_name "MAW", "MAW", "MAW", "MAW", "MAW", "MAW", … -``` + -This is basically how all the functions work, so let’s try to get the production data too. + -``` r -entsoeapi::gen_per_prod_type( - eic = "10Y1001A1001A83F", - period_start = lubridate::ymd("2020-01-01", tz = "CET"), - period_end = lubridate::ymd("2020-01-02", tz = "CET"), - gen_type = NULL, - tidy_output = TRUE -) |> - dplyr::glimpse() -#> Rows: 1,632 -#> Columns: 25 -#> $ ts_in_bidding_zone_domain_mrid "10Y1001A1001A83F", "10Y1001A1001A83F", "10Y1001… -#> $ ts_in_bidding_zone_domain_name "Germany", "Germany", "Germany", "Germany", "Ger… -#> $ ts_out_bidding_zone_domain_mrid NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, … -#> $ ts_out_bidding_zone_domain_name NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, … -#> $ type "A75", "A75", "A75", "A75", "A75", "A75", "A75",… -#> $ type_def "Actual generation per type", "Actual generation… -#> $ process_type "A16", "A16", "A16", "A16", "A16", "A16", "A16",… -#> $ process_type_def "Realised", "Realised", "Realised", "Realised", … -#> $ ts_object_aggregation "A08", "A08", "A08", "A08", "A08", "A08", "A08",… -#> $ ts_object_aggregation_def "Resource type", "Resource type", "Resource type… -#> $ ts_business_type "A01", "A01", "A01", "A01", "A01", "A01", "A01",… -#> $ ts_business_type_def "Production", "Production", "Production", "Produ… -#> $ ts_mkt_psr_type "B01", "B01", "B01", "B01", "B01", "B01", "B01",… -#> $ ts_mkt_psr_type_def "Biomass", "Biomass", "Biomass", "Biomass", "Bio… -#> $ created_date_time 2026-02-24 11:19:58, 2026-02-24 11:19:58, 2026-… -#> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, … -#> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00:00, 2019-… -#> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00:00, 2020-… -#> $ ts_resolution "PT15M", "PT15M", "PT15M", "PT15M", "PT15M", "PT… -#> $ ts_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00:00, 2019-… -#> $ ts_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00:00, 2020-… -#> $ ts_mrid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, … -#> $ ts_point_dt_start 2019-12-31 23:00:00, 2019-12-31 23:15:00, 2019-… -#> $ ts_point_quantity 4809.13, 4803.04, 4787.15, 4787.26, 4784.65, 476… -#> $ ts_quantity_measure_unit_name "MAW", "MAW", "MAW", "MAW", "MAW", "MAW", "MAW",… -``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +code + + +title + + +description +
+ +A01 + + +Tie line + + +A high voltage line used for cross border energy interconnections. +
+ +A02 + + +Line + + +A specific electric line within a country. +
+ +A03 + + +Resource Object + + +A resource that can either produce or consume energy. +
+ +A04 + + +Generation + + +A resource that can produce energy. +
+ +A05 + + +Load + + +A resource that can consume energy. +
+ +A06 + + +Phase Shift Transformer + + +An electrical device for controlling the power flow through specific +lines in a power transmission network. +
+ +A07 + + +Circuit Breaker + + +An electrical switch designed to protect an electrical circuit from +damage caused by overcurrent/overload or short circuit. +
+ +A08 + + +Busbar + + +A specific element within a substation to connect grid elements for +energy distribution purposes. +
+ +A09 + + +Capacitor + + +A transmission element designed to inject reactive power into the +transmission network. +
+ +A10 + + +Inductor + + +A transmission element designed to compensate reactive power in the +transmission network. +
+ +A11 + + +Power plant connection + + +All the network equipment that link the generating unit to the grid. +
+ +A12 + + +FACTS + + +Flexible Alternating Current Transmission System +
+ +A13 + + +Production unit + + +A production unit is a composition of one or several generation units. +
+ +A14 + + +Internal tie line + + +An internal tie line is a line between two scheduling areas within the +same bidding zone. +
+ +B01 + + +Biomass + + +A resource using biomass for energy. +
+ +B02 + + +Fossil Brown coal/Lignite + + +A resource using Fossil Brown coal/Lignite for energy. +
+ +B03 + + +Fossil Coal-derived gas + + +A resource using Fossil Coal-derived gas for energy. +
+ +B04 + + +Fossil Gas + + +A resource using Fossil Gas for energy. +
+ +B05 + + +Fossil Hard coal + + +A resource using Fossil Hard coal for energy. +
+ +B06 + + +Fossil Oil + + +A resource using Fossil Oil for energy. +
+ +B07 + + +Fossil Oil shale + + +A resource using Fossil Oil shale for energy. +
+ +B08 + + +Fossil Peat + + +A resource using Fossil Peat for energy. +
+ +B09 + + +Geothermal + + +A resource using Geothermal for energy. +
+ +B10 + + +Hydro-electric pure pumped storage head installation + + +Unit in which moving water energy is converted to electricity using +flowing water to generate electricity with a large dam and reservoirs. +Pure pumped storage plants store water in an upper reservoir with no +natural inflows. +
+ +B11 + + +Hydro Run-of-river head installation + + +Unit in which moving water energy is converted to electricity using +flowing water to generate electricity in the absence of a large dam and +reservoirs. +
+ +B12 + + +Hydro-electric storage head installation + + +Unit in which moving water energy is converted to electricity using +flowing water to generate electricity with a large dam and reservoirs. +
+ +B13 + + +Marine unspecified + + +Unit in which marine energy is converted to electricity with +equipment/devices not specified. +
+ +B14 + + +Nuclear unspecified + + +A unit in which the heat source is a nuclear reactor of type that is not +specified in other nuclear types. +
+ +B15 + + +Other renewable + + +A resource using Other renewable for energy. +
+ +B16 + + +Solar unspecified + + +Unit in which solar energy is converted to electricity with +equipment/devices not specified. +
+ +B17 + + +Waste + + +A resource using Waste for energy. +
+ +B18 + + +Wind Offshore + + +Unit in which wind energy is converted to electricity using wind farms +constructed in bodies of water, usually in the ocean. +
+ +B19 + + +Wind Onshore + + +Unit in which wind energy is converted to electricity using wind farms +constructed on land. +
+ +B20 + + +Other unspecified + + +Other unspecified technology. +
+ +B21 + + +AC Link + + +Overhead line or cable which is used to transmit electrical power via +Alternative Current. +
+ +B22 + + +DC Link + + +Overhead line or cable which is used to transmit electrical power via +Direct Current. +
+ +B23 + + +Substation + + +An assembly of equipment in an electric power system through which +electric energy is passed for transmission, transformation, distribution +or switching. +
+ +B24 + + +Transformer + + +Electrical device that transfers energy from one voltage level to +another voltage level. +
+ +B25 + + +Energy storage + + +A resource that stores energy. It could be gas, electricity, etc. +
+ +B26 + + +Demand Side Response + + +A resource that change its electricity consumption patterns in response +to a signal or incentive. +
+ +B27 + + +Dispatchable hydro resource + + +A resource referring to dispatchable hydro generation. +
+ +B28 + + +Solar photovoltaic + + +Unit in which solar energy is converted to electricity using a +technology based on the photoelectric effect. +
+ +B29 + + +Solar concentration + + +Unit in which solar energy is converted to electricity using mirrors to +concentrate the sun’s energy to drive traditional steam turbines or +engines. +
+ +B30 + + +Wind unspecified + + +Unit in which wind energy is converted to electricity with +equipment/devices not specified. +
+ +B31 + + +Hydro-electric unspecified + + +Unit in which moving water energy is converted to electricity with +equipment/devices not specified. +
+ +B32 + + +Hydro-electric mixed pumped storage head installation + + +Unit in which moving water energy is converted to electricity using +flowing water to generate electricity with a large dam and reservoirs. +Mixed pumped storage plants use a combination of pumped storage and +conventional hydroelectric plants with an upper reservoir that is +replenished in part by natural inflows from a stream or river. +
+ +B33 + + +Marine tidal + + +Unit in which marine energy from tides is converted to electricity. +
+ +B34 + + +Marine wave + + +Unit in which marine energy from waves is converted to electricity. +
+ +B35 + + +Marine currents + + +Unit in which marine energy from currents is converted to electricity. +
+ +B36 + + +Marine pressure + + +Unit in which marine energy from pressure is converted to electricity. +
+ +B37 + + +Thermal unspecified + + +Unit in which heat energy is converted to electricity with +equipment/devices not specified in other thermal types. +
+ +B38 + + +Thermal combined cycle gas turbine with heat recovery + + +Unit in which heat energy is converted to electricity called Combined +Cycle Gas Turbine. The power is generated by the single or multiple gas +turbine(s) in combination with the steam turbine(s). The unit might be +equipped with waste heat recovery (e.g. to district heating network). +
+ +B39 + + +Thermal steam turbine with back-pressure turbine (open cycle) + + +Unit in which heat energy is converted to electricity. The power is +generated with the steam that is expanded in the back-pressure steam +turbine with or without heat output (e.g. to district heating network). +
+ +B40 + + +Thermal steam turbine with condensation turbine (closed cycle) + + +Unit in which heat energy is converted to electricity. The power is +generated with the steam that is expanded in the condensation steam +turbine with or without heat output (e.g. to district heating network). +
+ +B41 + + +Thermal gas turbine with heat recovery + + +Unit in which heat energy is converted to electricity called Simple +Cycle Gas Turbine. The power is generated by the gas turbine and the +flue gas waste heat is recovered (e.g. to district heating network). +
+ +B42 + + +Thermal internal combustion engine + + +An internal combustion engine is a heat engine in which the combustion +of a fuel occurs with an oxidizer (usually air) in a combustion chamber +that is an integral part of the working fluid flow circuit +(e.g. reciprocating engine). The unit might be equipped with waste heat +recovery (e.g. to district heating network). +
+ +B43 + + +Thermal micro-turbine + + +Unit in which heat energy is converted to electricity called Simple +Cycle Gas Turbine. The power is generated by the gas turbine (capacity +less than 500kWe). The unit might be equipped with waste heat recovery +(e.g. to district heating network). +
+ +B44 + + +Thermal Stirling engine + + +A Stirling engine is a heat engine that is operated by the cyclic +compression and expansion of air or other gas (the working fluid) at +different temperatures, resulting in a net conversion of heat energy to +mechanical work. +
+ +B45 + + +Thermal fuel cell + + +A fuel cell is an electrochemical cell that converts the chemical energy +of a fuel (e.g. hydrogen) and an oxidizing agent (e.g. oxygen) into +electricity through a pair of redox reactions. +
+ +B46 + + +Thermal steam engine + + +A steam engine is a heat engine that performs mechanical work using +steam as its working fluid. The steam engine uses the force produced by +steam pressure to push a piston back and forth inside a cylinder. +
+ +B47 + + +Thermal organic Rankine cycle + + +The Organic Rankine Cycle (ORC) is named for its use of an organic, high +molecular mass fluid with a liquid-vapor phase change, or boiling point, +occurring at a lower temperature than the water-steam phase change. The +fluid allows Rankine cycle heat recovery from lower temperature sources +such as biomass combustion, industrial waste heat, geothermal heat, +solar ponds etc. The low-temperature heat is converted into useful work, +that can itself be converted into electricity. +
+ +B48 + + +Thermal gas turbine without heat recovery + + +Unit in which heat energy is converted to electricity called Simple +Cycle Gas Turbine. The power is generated by the gas turbine and there +is no flue gas waste heat recovery. +
+ +B49 + + +Nuclear heavy water reactor + + +A unit in which the heat source is a pressurized heavy-water reactor +(PHWR) that is a nuclear reactor that uses heavy water (deuterium oxide +D2O) as its coolant and neutron moderator. +
+ +B50 + + +Nuclear light water reactor + + +A unit in which the heat source is a light-water reactor (LWR) that is a +type of thermal-neutron reactor that uses normal water, as both its +coolant and neutron moderator � furthermore a solid form of fissile +elements is used as fuel. +
+ +B51 + + +Nuclear breeder + + +A unit in which the heat source is a nuclear reactor that generates more +fissile material than it consumes. +
+ +B52 + + +Nuclear graphite reactor + + +A unit in which the heat source is a graphite-moderated reactor that is +a nuclear reactor that uses carbon as a neutron moderator, which allows +natural uranium to be used as nuclear fuel. +
+ +B53 + + +Temporary energy storage + + +A resource that is temporarily connected to the grid and that may store +energy when connected, such as an electric vehicle. +
+ +B54 + + +Permanent energy storage + + +A resource that is permanently connected to the grid and that may store +energy when connected, such as a pumped hydro. +
+ +B55 + + +Electric vehicle battery + + +A resource using electric vehicle batteries, commercial and private. The +reason for separating vehicle batteries and non-vehicle batteries is +that the vehicle batteries not necessarily is connected to the charger. +
+ +B56 + + +Heat pump specified + + +A heat pump is a device that uses work to transfer heat from a cool +space to a warm space by transferring thermal energy using a +refrigeration cycle +
+ +B57 + + +Heat pump electrical + + +A heat pump is a device that uses electricity to transfer heat from a +cool space to a warm space by transferring thermal energy using a +refrigeration cycle. +
+ +B58 + + +Heat pump absorption + + +A heat pump is a device that uses absorption technology to transfer heat +from a cool space to a warm space by transferring thermal energy using a +refrigeration cycle. +
+ +B59 + + +Auxiliary power unit + + +A technology that provides energy as a backup. +
+ +B60 + + +Water electrolysis unspecified + + +Unspecified water electrolysis. +
+ +B61 + + +Water electrolysis low temperature unspecified + + +Unspecified water electrolysis at low temperature as in an Alkaline or +Proto-Exchange Membrane (PEM) fuel cell. +
+ +B62 + + +Water electrolysis low temperature main product + + +Main product water electrolysis at low temperature as in an Alkaline or +Proto-Exchange Membrane (PEM) fuel cell. +
+ +B63 + + +Water electrolysis high temperature unspecified + + +Unspecified water electrolysis at high temperature as in a Solid Oxide +Electrolysis Cell (SOEC) fuel cell. +
+ +B64 + + +Steam methane reforming unspecified + + +Unspecified methane reforming. +
+ +B65 + + +Steam methane reforming without CCS/CCU unspecified + + +Main product methane reforming without Carbon Capture and Sequestration +(CCS)/Carbon Capture and Use (CCU). +
+ +B66 + + +Steam methane reforming with CCS/CCU unspecified + + +Unspecified methane reforming with Carbon Capture and Sequestration +(CCS)/Carbon Capture and Use (CCU). +
+ +B67 + + +Steam methane reforming with CCS/CCU main product + + +Main product methane reforming with Carbon Capture and Sequestration +(CCS)/Carbon Capture and Use (CCU). +
+ +B68 + + +Partial oxidation unspecified + + +Unspecified partial oxidation. +
+ +B69 + + +Autothermal reforming unspecified + + +Unspecified autothermal reforming. +
+ +B70 + + +Methanol reforming unspecified + + +Unspecified methanol reforming. +
+ +B71 + + +Ammonia reforming unspecified + + +Unspecified ammonia reforming. +
+ +B72 + + +Ammonia gasification + + +Unspecified gasification. +
+ +B73 + + +Chlor-alkali electrolysis unspecified + + +Unspecified alkali electrolysis. +
+ +B74 + + +Chlor-alkali electrolysis by-product + + +Alkali electrolysis product. +
+ +B75 + + +ACDC converter + + +ACDC converters are electrical circuits that transform alternating +current (AC) into direct current (DC) and vice versa. +
+ +B76 + + +Converter + + +Electrical device that converts current between AC and DC. +
+ +Let’s get the demand of 2020-01-01 in Germany. + +``` r +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr") +entsoeapi::load_actual_total( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd("2020-01-01", tz = "CET"), + period_end = lubridate::ymd("2020-01-02", tz = "CET") +) |> + dplyr::glimpse() +#> +#> ── API call ──────────────────────────────────────────────────────────────────── +#> → https://web-api.tp.entsoe.eu/api?documentType=A65&processType=A16&outBiddingZone_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> +#> <- HTTP/2 200 +#> <- date: Wed, 04 Mar 2026 15:49:50 GMT +#> <- content-type: text/xml +#> <- content-disposition: inline; filename="Actual Total Load_201912312300-202001012300.xml" +#> <- x-content-type-options: nosniff +#> <- x-xss-protection: 0 +#> <- vary: accept-encoding +#> <- content-encoding: gzip +#> <- strict-transport-security: max-age=15724800; includeSubDomains +#> <- +#> ✔ response has arrived +#> ℹ pulling Y_eicCodes.csv file from cache +#> Rows: 96 +#> Columns: 21 +#> $ ts_out_bidding_zone_domain_mrid "10Y1001A1001A83F", "10Y1001A1001A83F"… +#> $ ts_out_bidding_zone_domain_name "Germany", "Germany", "Germany", "Germ… +#> $ type "A65", "A65", "A65", "A65", "A65", "A6… +#> $ type_def "System total load", "System total loa… +#> $ process_type "A16", "A16", "A16", "A16", "A16", "A1… +#> $ process_type_def "Realised", "Realised", "Realised", "R… +#> $ ts_object_aggregation "A01", "A01", "A01", "A01", "A01", "A0… +#> $ ts_object_aggregation_def "Area", "Area", "Area", "Area", "Area"… +#> $ ts_business_type "A04", "A04", "A04", "A04", "A04", "A0… +#> $ ts_business_type_def "Consumption", "Consumption", "Consump… +#> $ created_date_time 2026-03-04 15:49:50, 2026-03-04 15:49… +#> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… +#> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… +#> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… +#> $ ts_resolution "PT15M", "PT15M", "PT15M", "PT15M", "P… +#> $ ts_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… +#> $ ts_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… +#> $ ts_mrid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… +#> $ ts_point_dt_start 2019-12-31 23:00:00, 2019-12-31 23:15… +#> $ ts_point_quantity 43881.80, 43639.59, 43330.90, 43149.49… +#> $ ts_quantity_measure_unit_name "MAW", "MAW", "MAW", "MAW", "MAW", "MA… +``` + +This is basically how all the functions work, so let’s try to get the +production data too. + +``` r +if (!require("dplyr", quietly = TRUE)) install.packages("dplyr") +entsoeapi::gen_per_prod_type( + eic = "10Y1001A1001A83F", + period_start = lubridate::ymd("2020-01-01", tz = "CET"), + period_end = lubridate::ymd("2020-01-02", tz = "CET"), + gen_type = NULL, + tidy_output = TRUE +) |> + dplyr::glimpse() +#> +#> ── API call ──────────────────────────────────────────────────────────────────── +#> → https://web-api.tp.entsoe.eu/api?documentType=A75&processType=A16&in_Domain=10Y1001A1001A83F&periodStart=201912312300&periodEnd=202001012300&securityToken=<...> +#> <- HTTP/2 200 +#> <- date: Wed, 04 Mar 2026 15:49:51 GMT +#> <- content-type: text/xml +#> <- content-disposition: inline; filename="Aggregated Generation per Type_201912312300-202001012300.xml" +#> <- x-content-type-options: nosniff +#> <- x-xss-protection: 0 +#> <- vary: accept-encoding +#> <- content-encoding: gzip +#> <- strict-transport-security: max-age=15724800; includeSubDomains +#> <- +#> ✔ response has arrived +#> Rows: 1,632 +#> Columns: 25 +#> $ ts_in_bidding_zone_domain_mrid "10Y1001A1001A83F", "10Y1001A1001A83F"… +#> $ ts_in_bidding_zone_domain_name "Germany", "Germany", "Germany", "Germ… +#> $ ts_out_bidding_zone_domain_mrid NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… +#> $ ts_out_bidding_zone_domain_name NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… +#> $ type "A75", "A75", "A75", "A75", "A75", "A7… +#> $ type_def "Actual generation per type", "Actual … +#> $ process_type "A16", "A16", "A16", "A16", "A16", "A1… +#> $ process_type_def "Realised", "Realised", "Realised", "R… +#> $ ts_object_aggregation "A08", "A08", "A08", "A08", "A08", "A0… +#> $ ts_object_aggregation_def "Resource type", "Resource type", "Res… +#> $ ts_business_type "A01", "A01", "A01", "A01", "A01", "A0… +#> $ ts_business_type_def "Production", "Production", "Productio… +#> $ ts_mkt_psr_type "B01", "B01", "B01", "B01", "B01", "B0… +#> $ ts_mkt_psr_type_def "Biomass", "Biomass", "Biomass", "Biom… +#> $ created_date_time 2026-03-04 15:49:51, 2026-03-04 15:49… +#> $ revision_number 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… +#> $ time_period_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… +#> $ time_period_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… +#> $ ts_resolution "PT15M", "PT15M", "PT15M", "PT15M", "P… +#> $ ts_time_interval_start 2019-12-31 23:00:00, 2019-12-31 23:00… +#> $ ts_time_interval_end 2020-01-01 23:00:00, 2020-01-01 23:00… +#> $ ts_mrid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… +#> $ ts_point_dt_start 2019-12-31 23:00:00, 2019-12-31 23:15… +#> $ ts_point_quantity 4809.13, 4803.04, 4787.15, 4787.26, 47… +#> $ ts_quantity_measure_unit_name "MAW", "MAW", "MAW", "MAW", "MAW", "MA… +``` + +## Code of Conduct + +Please note that the entsoeapi project is released with a [Contributor +Code of +Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). +By contributing to this project, you agree to abide by its terms. diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 00000000..dd47315b --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,12 @@ +url: https://krose.github.io/entsoeapi/ +navbar: + structure: + left: + - home + - reference + - articles +template: + bootstrap: 5 + bootswatch: cyborg +code: + width: 80 diff --git a/data-raw/code_lists_creator.R b/data-raw/code_lists_creator.R index 1dceab99..1daa42fc 100644 --- a/data-raw/code_lists_creator.R +++ b/data-raw/code_lists_creator.R @@ -15,7 +15,7 @@ out_main_dir <- fs::path_wd("data-raw") # Build and perform the request httr2::request(base_url = url) |> httr2::req_headers(Authorization = Sys.getenv("ENTSOE_PAT")) |> - httr2::req_perform(path = tmp) # streams directly to disk + httr2::req_perform(path = tmp) # streams directly to disk # Extract the archive archive::archive_extract(archive = tmp, dir = out_main_dir) @@ -58,7 +58,9 @@ parse_simple_type <- function(node) { ) # skip non-enum types - if (length(enum_nodes) == 0L) return(NULL) + if (length(enum_nodes) == 0L) { + return(NULL) + } data.table::data.table( list_name = xml2::xml_attr(x = node, attr = "name") |> @@ -111,7 +113,7 @@ parse_simple_type <- function(node) { ) |> purrr::modify(gsub, pattern = "\\n", replacement = " ") |> purrr::modify_if(is.character, trimws, which = "both") |> - purrr::discard(~collapse::allNA(.x)) + purrr::discard(~ collapse::allNA(.x)) ) } diff --git a/data-raw/transmission_pair_eic_dict.R b/data-raw/transmission_pair_eic_dict.R index 41bc2e04..823b06f9 100644 --- a/data-raw/transmission_pair_eic_dict.R +++ b/data-raw/transmission_pair_eic_dict.R @@ -1,10 +1,11 @@ # read raw tsv, trim the character columns and remove empty columns transmission_pair_eic_dict <- fs::path("data-raw", - "transmission_pair_eic_dict", - ext = "tsv") |> + "transmission_pair_eic_dict", + ext = "tsv" +) |> data.table::fread(encoding = "UTF-8", fill = TRUE) |> purrr::modify_if(is.character, trimws, which = "both") |> - purrr::discard(~is.na(.x) |> all()) + purrr::discard(~ is.na(.x) |> all()) # save the package data in the correct format usethis::use_data(transmission_pair_eic_dict, overwrite = TRUE) diff --git a/man/allocation_mode_types.Rd b/man/allocation_mode_types.Rd index bdc79597..9fe0a1f6 100644 --- a/man/allocation_mode_types.Rd +++ b/man/allocation_mode_types.Rd @@ -14,7 +14,6 @@ allocation_mode_types List Allocation Mode Types } \examples{ - str(entsoeapi::allocation_mode_types) } diff --git a/man/analog_types.Rd b/man/analog_types.Rd index 943af15c..de5b84fb 100644 --- a/man/analog_types.Rd +++ b/man/analog_types.Rd @@ -14,7 +14,6 @@ analog_types List Analog Types } \examples{ - str(entsoeapi::analog_types) } diff --git a/man/asset_types.Rd b/man/asset_types.Rd index ca62d1a2..df315673 100644 --- a/man/asset_types.Rd +++ b/man/asset_types.Rd @@ -14,7 +14,6 @@ asset_types List Asset Types } \examples{ - str(entsoeapi::asset_types) } diff --git a/man/auction_types.Rd b/man/auction_types.Rd index c649dffb..3b8a7219 100644 --- a/man/auction_types.Rd +++ b/man/auction_types.Rd @@ -14,7 +14,6 @@ auction_types List Auction Types } \examples{ - str(entsoeapi::auction_types) } diff --git a/man/business_types.Rd b/man/business_types.Rd index 96bb42d5..a4c10c49 100644 --- a/man/business_types.Rd +++ b/man/business_types.Rd @@ -14,7 +14,6 @@ business_types List Business Types } \examples{ - str(entsoeapi::business_types) } diff --git a/man/category_types.Rd b/man/category_types.Rd index ea385d58..ab1153d9 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -14,7 +14,6 @@ category_types List Category Types } \examples{ - str(entsoeapi::category_types) } diff --git a/man/classification_types.Rd b/man/classification_types.Rd index acc447ca..e00ab43f 100644 --- a/man/classification_types.Rd +++ b/man/classification_types.Rd @@ -14,7 +14,6 @@ classification_types List Classification Types } \examples{ - str(entsoeapi::classification_types) } diff --git a/man/coding_scheme_types.Rd b/man/coding_scheme_types.Rd index ce2e1cd2..a4d039ab 100644 --- a/man/coding_scheme_types.Rd +++ b/man/coding_scheme_types.Rd @@ -14,7 +14,6 @@ coding_scheme_types List Coding Scheme Types } \examples{ - str(entsoeapi::coding_scheme_types) } diff --git a/man/contract_types.Rd b/man/contract_types.Rd index 5eb02ab4..4f28d6fc 100644 --- a/man/contract_types.Rd +++ b/man/contract_types.Rd @@ -14,7 +14,6 @@ contract_types List Contract Types } \examples{ - str(entsoeapi::contract_types) } diff --git a/man/coordinate_system_types.Rd b/man/coordinate_system_types.Rd index 47fbe76b..69e1ed15 100644 --- a/man/coordinate_system_types.Rd +++ b/man/coordinate_system_types.Rd @@ -14,7 +14,6 @@ coordinate_system_types List Coordinate System Types } \examples{ - str(entsoeapi::coordinate_system_types) } diff --git a/man/currency_types.Rd b/man/currency_types.Rd index e7b85468..ba1c131c 100644 --- a/man/currency_types.Rd +++ b/man/currency_types.Rd @@ -14,7 +14,6 @@ currency_types List Currency Types } \examples{ - str(entsoeapi::currency_types) } diff --git a/man/curve_types.Rd b/man/curve_types.Rd index 64e45633..1f901548 100644 --- a/man/curve_types.Rd +++ b/man/curve_types.Rd @@ -14,7 +14,6 @@ curve_types List Curve Types } \examples{ - str(entsoeapi::curve_types) } diff --git a/man/direction_types.Rd b/man/direction_types.Rd index 809e05b7..f1f44aca 100644 --- a/man/direction_types.Rd +++ b/man/direction_types.Rd @@ -14,7 +14,6 @@ direction_types List Direction Types } \examples{ - str(entsoeapi::direction_types) } diff --git a/man/document_types.Rd b/man/document_types.Rd index b3217cae..bed25b11 100644 --- a/man/document_types.Rd +++ b/man/document_types.Rd @@ -14,7 +14,6 @@ document_types List Document Types } \examples{ - str(entsoeapi::document_types) } diff --git a/man/eic_types.Rd b/man/eic_types.Rd index 342bb939..0b9313ab 100644 --- a/man/eic_types.Rd +++ b/man/eic_types.Rd @@ -14,7 +14,6 @@ eic_types List EIC Types } \examples{ - str(entsoeapi::eic_types) } diff --git a/man/energy_product_types.Rd b/man/energy_product_types.Rd index 4250b69c..168da7ce 100644 --- a/man/energy_product_types.Rd +++ b/man/energy_product_types.Rd @@ -14,7 +14,6 @@ energy_product_types List Energy Product Types } \examples{ - str(entsoeapi::energy_product_types) } diff --git a/man/entsoeapi.Rd b/man/entsoeapi.Rd new file mode 100644 index 00000000..b8c314ed --- /dev/null +++ b/man/entsoeapi.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/entsoeapi-package.R +\name{entsoeapi} +\alias{entsoeapi} +\alias{entsoeapi-package} +\title{An R Interface to the ENTSO-E Transparency Platform API} +\description{ +an easy wrapper around the ENTSO-E +\href{https://documenter.getpostman.com/view/7009892/2s93JtP3F6}{API}'s data and +transform them to tabular format without effort. +} +\keyword{internal} diff --git a/man/figures/logo.png b/man/figures/logo.png index 80327874..8466e830 100644 Binary files a/man/figures/logo.png and b/man/figures/logo.png differ diff --git a/man/figures/logo.svg b/man/figures/logo.svg new file mode 100644 index 00000000..06413639 --- /dev/null +++ b/man/figures/logo.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + entsoeapi + + + ENTSO-E + diff --git a/man/flow_commodity_option_types.Rd b/man/flow_commodity_option_types.Rd index 1ca85000..91259d04 100644 --- a/man/flow_commodity_option_types.Rd +++ b/man/flow_commodity_option_types.Rd @@ -14,7 +14,6 @@ flow_commodity_option_types List Flow Commodity Types } \examples{ - str(entsoeapi::flow_commodity_option_types) } diff --git a/man/fuel_types.Rd b/man/fuel_types.Rd index 4acdd309..998a2c7d 100644 --- a/man/fuel_types.Rd +++ b/man/fuel_types.Rd @@ -14,7 +14,6 @@ fuel_types List Fuel Types } \examples{ - str(entsoeapi::fuel_types) } diff --git a/man/gen_storage_mean_filling_rate.Rd b/man/gen_storage_mean_filling_rate.Rd index 1ac6c017..10170ed3 100644 --- a/man/gen_storage_mean_filling_rate.Rd +++ b/man/gen_storage_mean_filling_rate.Rd @@ -38,7 +38,8 @@ df <- entsoeapi::gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", period_start = lubridate::ymd(x = "2020-02-01", tz = "CET"), period_end = lubridate::ymd(x = "2021-02-15", tz = "CET"), - tidy_output = TRUE) + tidy_output = TRUE +) str(df) } diff --git a/man/grid_agreement_types.Rd b/man/grid_agreement_types.Rd index ecf50d53..726fc20c 100644 --- a/man/grid_agreement_types.Rd +++ b/man/grid_agreement_types.Rd @@ -14,7 +14,6 @@ grid_agreement_types List Grid Agreement Types } \examples{ - str(entsoeapi::grid_agreement_types) } diff --git a/man/hvdc_mode_types.Rd b/man/hvdc_mode_types.Rd index 31198f0b..14939e5f 100644 --- a/man/hvdc_mode_types.Rd +++ b/man/hvdc_mode_types.Rd @@ -14,7 +14,6 @@ hvdc_mode_types List HVDC Mode Types } \examples{ - str(entsoeapi::hvdc_mode_types) } diff --git a/man/indicator_types.Rd b/man/indicator_types.Rd index 14770533..0ab2ce8c 100644 --- a/man/indicator_types.Rd +++ b/man/indicator_types.Rd @@ -14,7 +14,6 @@ indicator_types List Indicator Types } \examples{ - str(entsoeapi::indicator_types) } diff --git a/man/market_product_types.Rd b/man/market_product_types.Rd index 60bae90d..3abfb0e2 100644 --- a/man/market_product_types.Rd +++ b/man/market_product_types.Rd @@ -14,7 +14,6 @@ market_product_types List Market Product Types } \examples{ - str(entsoeapi::market_product_types) } diff --git a/man/message_types.Rd b/man/message_types.Rd index 10288915..6a64ca13 100644 --- a/man/message_types.Rd +++ b/man/message_types.Rd @@ -14,7 +14,6 @@ message_types List Message Types } \examples{ - str(entsoeapi::message_types) } diff --git a/man/object_aggregation_types.Rd b/man/object_aggregation_types.Rd index f1b6e347..666f8a9b 100644 --- a/man/object_aggregation_types.Rd +++ b/man/object_aggregation_types.Rd @@ -14,7 +14,6 @@ object_aggregation_types List Object Aggregation Types } \examples{ - str(entsoeapi::object_aggregation_types) } diff --git a/man/outages_both.Rd b/man/outages_both.Rd index a4d06e8c..ebfecab2 100644 --- a/man/outages_both.Rd +++ b/man/outages_both.Rd @@ -51,13 +51,13 @@ means the minimum available generation capacity during the period specified. df <- entsoeapi::outages_both( eic = "10YFR-RTE------C", period_start = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 1L), - tz = "CET" - ), + x = Sys.Date() + lubridate::days(x = 1L), + tz = "CET" + ), period_end = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 2L), - tz = "CET" - ) + x = Sys.Date() + lubridate::days(x = 2L), + tz = "CET" + ) ) str(df) diff --git a/man/outages_gen_units.Rd b/man/outages_gen_units.Rd index 456ee32a..43358a29 100644 --- a/man/outages_gen_units.Rd +++ b/man/outages_gen_units.Rd @@ -54,13 +54,13 @@ available generation capacity during the period specified. df <- entsoeapi::outages_gen_units( eic = "10YFR-RTE------C", period_start = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 1L), - tz = "CET" - ), + x = Sys.Date() + lubridate::days(x = 1L), + tz = "CET" + ), period_end = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 2L), - tz = "CET" - ) + x = Sys.Date() + lubridate::days(x = 2L), + tz = "CET" + ) ) str(df) diff --git a/man/outages_offshore_grid.Rd b/man/outages_offshore_grid.Rd index 777286f4..2a5d4cf3 100644 --- a/man/outages_offshore_grid.Rd +++ b/man/outages_offshore_grid.Rd @@ -47,9 +47,9 @@ is provided. df <- entsoeapi::outages_offshore_grid( eic = "10Y1001A1001A82H", period_start = lubridate::ymd( - x = Sys.Date() -lubridate::days(x = 365L), - tz = "CET" - ), + x = Sys.Date() - lubridate::days(x = 365L), + tz = "CET" + ), period_end = lubridate::ymd(x = Sys.Date(), tz = "CET") ) diff --git a/man/outages_prod_units.Rd b/man/outages_prod_units.Rd index 0182b7b5..24c2fb66 100644 --- a/man/outages_prod_units.Rd +++ b/man/outages_prod_units.Rd @@ -51,13 +51,17 @@ available generation capacity during the period specified. } \examples{ df <- entsoeapi::outages_prod_units( - eic = "10YFR-RTE------C", - period_start = lubridate::ymd(x = Sys.Date() + - lubridate::days(x = 1L), - tz = "CET"), - period_end = lubridate::ymd(x = Sys.Date() + - lubridate::days(x = 2L), - tz = "CET") + eic = "10YFR-RTE------C", + period_start = lubridate::ymd( + x = Sys.Date() + + lubridate::days(x = 1L), + tz = "CET" + ), + period_end = lubridate::ymd( + x = Sys.Date() + + lubridate::days(x = 2L), + tz = "CET" + ) ) str(df) diff --git a/man/outages_transmission_grid.Rd b/man/outages_transmission_grid.Rd index 3ec27f8c..9f317225 100644 --- a/man/outages_transmission_grid.Rd +++ b/man/outages_transmission_grid.Rd @@ -60,17 +60,17 @@ df <- entsoeapi::outages_transmission_grid( eic_in = "10YFR-RTE------C", eic_out = "10Y1001A1001A82H", period_start = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 1), - tz = "CET" - ), + x = Sys.Date() + lubridate::days(x = 1), + tz = "CET" + ), period_end = lubridate::ymd( - x = Sys.Date() + lubridate::days(x = 2), - tz = "CET" - ), + x = Sys.Date() + lubridate::days(x = 2), + tz = "CET" + ), period_start_update = lubridate::ymd( - x = Sys.Date() -lubridate::days(x = 7), - tz = "CET" - ), + x = Sys.Date() - lubridate::days(x = 7), + tz = "CET" + ), period_end_update = lubridate::ymd(x = Sys.Date(), tz = "CET") ) diff --git a/man/payment_terms_types.Rd b/man/payment_terms_types.Rd index a3e7409d..8ba44dc8 100644 --- a/man/payment_terms_types.Rd +++ b/man/payment_terms_types.Rd @@ -14,7 +14,6 @@ payment_terms_types List Payment Terms Types } \examples{ - str(entsoeapi::payment_terms_types) } diff --git a/man/price_category_types.Rd b/man/price_category_types.Rd index 0a0c0883..005fd610 100644 --- a/man/price_category_types.Rd +++ b/man/price_category_types.Rd @@ -14,7 +14,6 @@ price_category_types List Price Category Types } \examples{ - str(entsoeapi::price_category_types) } diff --git a/man/price_component_types.Rd b/man/price_component_types.Rd index 258d36af..d7da445f 100644 --- a/man/price_component_types.Rd +++ b/man/price_component_types.Rd @@ -14,7 +14,6 @@ price_component_types List Price Component Types } \examples{ - str(entsoeapi::price_component_types) } diff --git a/man/price_direction_types.Rd b/man/price_direction_types.Rd index 196ceeba..121e8ea0 100644 --- a/man/price_direction_types.Rd +++ b/man/price_direction_types.Rd @@ -14,7 +14,6 @@ price_direction_types List Price Direction Types } \examples{ - str(entsoeapi::price_direction_types) } diff --git a/man/process_types.Rd b/man/process_types.Rd index 653c11fd..78063d1c 100644 --- a/man/process_types.Rd +++ b/man/process_types.Rd @@ -14,7 +14,6 @@ process_types List Process Types } \examples{ - str(entsoeapi::process_types) } diff --git a/man/quality_types.Rd b/man/quality_types.Rd index ab7925aa..7cfb0b35 100644 --- a/man/quality_types.Rd +++ b/man/quality_types.Rd @@ -14,7 +14,6 @@ quality_types List Quality Types } \examples{ - str(entsoeapi::quality_types) } diff --git a/man/reason_code_types.Rd b/man/reason_code_types.Rd index 06bd5d83..8ff94728 100644 --- a/man/reason_code_types.Rd +++ b/man/reason_code_types.Rd @@ -14,7 +14,6 @@ reason_code_types List Reason Code Types } \examples{ - str(entsoeapi::reason_code_types) } diff --git a/man/rights_types.Rd b/man/rights_types.Rd index 6f1e87ce..892b4e69 100644 --- a/man/rights_types.Rd +++ b/man/rights_types.Rd @@ -14,7 +14,6 @@ rights_types List Rights Types } \examples{ - str(entsoeapi::rights_types) } diff --git a/man/role_types.Rd b/man/role_types.Rd index b8c48397..327c7c11 100644 --- a/man/role_types.Rd +++ b/man/role_types.Rd @@ -14,7 +14,6 @@ role_types List Role Types } \examples{ - str(entsoeapi::role_types) } diff --git a/man/settlement_method_types.Rd b/man/settlement_method_types.Rd index 06e24059..6da4122b 100644 --- a/man/settlement_method_types.Rd +++ b/man/settlement_method_types.Rd @@ -14,7 +14,6 @@ settlement_method_types List Settlement Method Types } \examples{ - str(entsoeapi::settlement_method_types) } diff --git a/man/sharing_of_frr_capacity.Rd b/man/sharing_of_frr_capacity.Rd new file mode 100644 index 00000000..db2ee689 --- /dev/null +++ b/man/sharing_of_frr_capacity.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/en_balancing.R +\name{sharing_of_frr_capacity} +\alias{sharing_of_frr_capacity} +\title{Get Sharing of FRR Capacity (SO GL 190.1)} +\usage{ +sharing_of_frr_capacity( + eic_acquiring = NULL, + eic_connecting = NULL, + process_type = NULL, + period_start = lubridate::ymd(Sys.Date() - lubridate::days(x = 7L), tz = "CET"), + period_end = lubridate::ymd(Sys.Date(), tz = "CET"), + tidy_output = TRUE, + security_token = Sys.getenv("ENTSOE_PAT") +) +} +\arguments{ +\item{eic_acquiring}{Energy Identification Code of the acquiring domain} + +\item{eic_connecting}{Energy Identification Code of the connecting domain} + +\item{process_type}{type of reserve +"A56" FRR +"A46" RR} + +\item{period_start}{POSIXct or YYYY-MM-DD HH:MM:SS format +One year range limit applies} + +\item{period_end}{POSIXct or YYYY-MM-DD HH:MM:SS format +One year range limit applies} + +\item{tidy_output}{Defaults to TRUE. flatten nested tables} + +\item{security_token}{Security token for ENTSO-E transparency platform} +} +\description{ +Sharing of Frequency Restoration Reserve capacity between areas. +One year range limit applies. +} +\examples{ +\dontrun{ +df <- entsoeapi::sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE +) + +str(df) +} + +} diff --git a/man/status_types.Rd b/man/status_types.Rd index e0b6c694..1538aa7c 100644 --- a/man/status_types.Rd +++ b/man/status_types.Rd @@ -14,7 +14,6 @@ status_types List Status Types } \examples{ - str(entsoeapi::status_types) } diff --git a/man/tariff_types.Rd b/man/tariff_types.Rd index 779c29b0..aa124f81 100644 --- a/man/tariff_types.Rd +++ b/man/tariff_types.Rd @@ -14,7 +14,6 @@ tariff_types List Tariff Types } \examples{ - str(entsoeapi::tariff_types) } diff --git a/man/timeframe_types.Rd b/man/timeframe_types.Rd index 7968875e..70cd7703 100644 --- a/man/timeframe_types.Rd +++ b/man/timeframe_types.Rd @@ -14,7 +14,6 @@ timeframe_types List Timeframe Types } \examples{ - str(entsoeapi::timeframe_types) } diff --git a/man/transmission_pair_eic_dict.Rd b/man/transmission_pair_eic_dict.Rd index 92847819..747fb0ca 100644 --- a/man/transmission_pair_eic_dict.Rd +++ b/man/transmission_pair_eic_dict.Rd @@ -14,7 +14,6 @@ transmission_pair_eic_dict List Transmission Pair EIC Dictionary } \examples{ - str(entsoeapi::transmission_pair_eic_dict) } diff --git a/man/unit_multiplier.Rd b/man/unit_multiplier.Rd index bb7bfa88..2cbaf390 100644 --- a/man/unit_multiplier.Rd +++ b/man/unit_multiplier.Rd @@ -14,7 +14,6 @@ unit_multiplier List Unit Multiplier } \examples{ - str(entsoeapi::unit_multiplier) } diff --git a/man/unit_of_measure_types.Rd b/man/unit_of_measure_types.Rd index 5b9f2688..dbd02570 100644 --- a/man/unit_of_measure_types.Rd +++ b/man/unit_of_measure_types.Rd @@ -14,7 +14,6 @@ unit_of_measure_types List Unit of Measure Types } \examples{ - str(entsoeapi::unit_of_measure_types) } diff --git a/man/unit_symbol_types.Rd b/man/unit_symbol_types.Rd index 4b56e6af..8dc9f0a9 100644 --- a/man/unit_symbol_types.Rd +++ b/man/unit_symbol_types.Rd @@ -14,7 +14,6 @@ unit_symbol_types List Unit Symbol Types } \examples{ - str(entsoeapi::unit_symbol_types) } diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png new file mode 100644 index 00000000..1387d6a8 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-96x96.png b/pkgdown/favicon/favicon-96x96.png new file mode 100644 index 00000000..45b114c2 Binary files /dev/null and b/pkgdown/favicon/favicon-96x96.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico new file mode 100644 index 00000000..9699ddd0 Binary files /dev/null and b/pkgdown/favicon/favicon.ico differ diff --git a/pkgdown/favicon/favicon.svg b/pkgdown/favicon/favicon.svg new file mode 100644 index 00000000..2503ae05 --- /dev/null +++ b/pkgdown/favicon/favicon.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + entsoeapi + + + ENTSO-E + \ No newline at end of file diff --git a/pkgdown/favicon/site.webmanifest b/pkgdown/favicon/site.webmanifest new file mode 100644 index 00000000..4ebda26b --- /dev/null +++ b/pkgdown/favicon/site.webmanifest @@ -0,0 +1,21 @@ +{ + "name": "", + "short_name": "", + "icons": [ + { + "src": "/web-app-manifest-192x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "/web-app-manifest-512x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} \ No newline at end of file diff --git a/pkgdown/favicon/web-app-manifest-192x192.png b/pkgdown/favicon/web-app-manifest-192x192.png new file mode 100644 index 00000000..5e56a614 Binary files /dev/null and b/pkgdown/favicon/web-app-manifest-192x192.png differ diff --git a/pkgdown/favicon/web-app-manifest-512x512.png b/pkgdown/favicon/web-app-manifest-512x512.png new file mode 100644 index 00000000..1ebb6add Binary files /dev/null and b/pkgdown/favicon/web-app-manifest-512x512.png differ diff --git a/tests/testthat/test-en_balancing.R b/tests/testthat/test-en_balancing.R index c5ad5804..f3e14271 100644 --- a/tests/testthat/test-en_balancing.R +++ b/tests/testthat/test-en_balancing.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "elastic_demands() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = result_full <- elastic_demands( eic = "10YCZ-CEPS-----N", @@ -119,7 +127,10 @@ testthat::test_that( ), tidy_output = TRUE ), - regexp = "The 'process_type' should be 'A47' or 'A51'." + regexp = paste0( + "Assertion on 'process_type' failed: ", + "Must be a subset of \\{'A47','A51'\\}, not 'NULL'" + ) ) testthat::expect_error( object = elastic_demands( @@ -135,16 +146,26 @@ testthat::test_that( ), tidy_output = TRUE ), - regexp = "The 'process_type' should be 'A47' or 'A51'." + regexp = paste0( + "Assertion on 'process_type' failed: ", + "Must be element of set \\{'A47','A51'\\}, but is 'INVALID'" + ) ) } ) - testthat::test_that( desc = "netted_volumes() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = netted_volumes( eic = "10YCZ-CEPS-----N", @@ -244,10 +265,17 @@ testthat::test_that( ) - testthat::test_that( desc = "exchanged_volumes() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_error( object = exchanged_volumes( eic = "10YCZ-CEPS-----N", @@ -397,10 +425,17 @@ testthat::test_that( ) - testthat::test_that( desc = "balancing_border_cap_limit() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) for (pt in c("A47", "A51", "A63")) { testthat::expect_no_error( object = balancing_border_cap_limit( @@ -588,7 +623,10 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One 'in' control area EIC should be provided" + regexp = paste0( + "Assertion on 'eic_in' failed: ", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = balancing_border_cap_limit( @@ -599,16 +637,26 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One 'out' control area EIC should be provided" + regexp = paste0( + "Assertion on 'eic_out' failed: ", + "Must be of type 'string', not 'NULL'" + ) ) } ) - testthat::test_that( desc = "exchanged_volumes_per_border() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = exchanged_volumes_per_border( acquiring_eic = "10YCZ-CEPS-----N", @@ -628,7 +676,10 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One acquiring EIC should be provided" + regexp = paste0( + "Assertion on 'acquiring_eic' failed: ", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -639,7 +690,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one acquiring EIC per request" + regexp = "Assertion on 'acquiring_eic' failed: Must have length 1" ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -684,7 +735,10 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One connecting EIC should be provided" + regexp = paste( + "Assertion on 'connecting_eic' failed:", + "Must be of type 'string', not 'NULL'." + ) ) testthat::expect_error( object = exchanged_volumes_per_border( @@ -695,16 +749,23 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one connecting EIC per request" + regexp = "Assertion on 'connecting_eic' failed: Must have length 1" ) } ) - testthat::test_that( desc = "hvdc_link_constrains() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = hvdc_link_constrains( eic_in = "10YDK-1--------W", @@ -722,7 +783,10 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One 'in' domain EIC should be provided" + regexp = paste0( + "Assertion on 'eic_in' failed: ", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = hvdc_link_constrains( @@ -732,7 +796,10 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One 'out' domain EIC should be provided" + regexp = paste0( + "Assertion on 'eic_out' failed: ", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = hvdc_link_constrains( @@ -742,7 +809,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one in and one out EIC per request" + regexp = "Assertion on 'eic_in' failed: Must have length 1" ) testthat::expect_error( object = hvdc_link_constrains( @@ -763,7 +830,11 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = "Valid security token should be provided" + regexp = paste( + "Assertion on 'security_token' failed:", + "All elements must have at least 1 characters,", + "but element 1 has 0 characters" + ) ) testthat::expect_error( object = hvdc_link_constrains( @@ -774,7 +845,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one interconnector EIC per request" + regexp = "Assertion on 'eic_ic' failed: Must have length 1." ) testthat::expect_error( object = hvdc_link_constrains( @@ -785,16 +856,26 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "The 'process_type' should be 'A47', 'A51' or 'A63'" + regexp = paste( + "Assertion on 'process_type' failed:", + "Must be element of set \\{'A47','A51','A63'\\}, but is 'INVALID'" + ) ) } ) - testthat::test_that( desc = "changes_to_bid_availability() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) for (bt in paste0("C", 40L:46L)) { testthat::expect_no_error( object = changes_to_bid_availability( @@ -822,7 +903,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One control area EIC should be provided" + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = changes_to_bid_availability( @@ -831,7 +912,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one control area EIC per request" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = changes_to_bid_availability( @@ -842,8 +923,8 @@ testthat::test_that( tidy_output = TRUE ), regexp = paste( - "The 'business_type' should be 'C40', 'C41', 'C42',", - "'C43', 'C44', 'C45', 'C46'" + "Assertion on 'business_type' failed: Must be element of set", + "\\{'C40','C41','C42','C43','C44','C45','C46'\\}, but is 'INVALID'" ) ) testthat::expect_error( @@ -854,7 +935,11 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = "Valid security token should be provided" + regexp = paste( + "Assertion on 'security_token' failed:", + "All elements must have at least 1 characters,", + "but element 1 has 0 characters" + ) ) testthat::expect_error( object = changes_to_bid_availability( @@ -869,10 +954,17 @@ testthat::test_that( ) - testthat::test_that( desc = "current_balancing_state() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = current_balancing_state( eic = "10YCZ-CEPS-----N", @@ -922,10 +1014,17 @@ testthat::test_that( ) - testthat::test_that( desc = "balancing_energy_bids() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = balancing_energy_bids( eic = "10YCZ-CEPS-----N", @@ -966,10 +1065,17 @@ testthat::test_that( ) - testthat::test_that( desc = "aggregated_balancing_energy_bids() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = aggregated_balancing_energy_bids( eic = "10YCZ-CEPS-----N", @@ -1034,10 +1140,17 @@ testthat::test_that( ) - testthat::test_that( desc = "procured_balancing_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = procured_balancing_capacity( eic = "10YCZ-CEPS-----N", @@ -1113,10 +1226,17 @@ testthat::test_that( ) - testthat::test_that( desc = "allocation_of_cross_zonal_balancing_cap() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = allocation_of_cross_zonal_balancing_cap( eic_acquiring = "10YAT-APG------L", @@ -1195,10 +1315,17 @@ testthat::test_that( ) - testthat::test_that( desc = "contracted_reserves() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = contracted_reserves( eic = "10YCZ-CEPS-----N", @@ -1283,10 +1410,17 @@ testthat::test_that( ) - testthat::test_that( desc = "activated_balancing_prices() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = activated_balancing_prices( eic = "10YCZ-CEPS-----N", @@ -1336,10 +1470,49 @@ testthat::test_that( ) +testthat::test_that( + desc = "activated_balancing_prices() covers business_type branch with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = activated_balancing_prices( + eic = "10YCZ-CEPS-----N", + business_type = "A63", + period_start = lubridate::ymd(x = "2024-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2024-01-02", tz = "CET"), + tidy_output = TRUE + ), + regexp = "HTTP 503" + ) + } +) + testthat::test_that( desc = "imbalance_prices() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = imbalance_prices( eic = "10YCZ-CEPS-----N", @@ -1389,10 +1562,17 @@ testthat::test_that( ) - testthat::test_that( desc = "imbalance_volumes() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = imbalance_volumes( eic = "10YCZ-CEPS-----N", @@ -1442,10 +1622,17 @@ testthat::test_that( ) - testthat::test_that( desc = "financial_expenses_and_income_for_balancing() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = financial_expenses_and_income_for_balancing( eic = "10YCZ-CEPS-----N", @@ -1495,10 +1682,17 @@ testthat::test_that( ) - testthat::test_that( desc = "fcr_total_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = fcr_total_capacity( eic = "10YEU-CONT-SYNC0", @@ -1514,7 +1708,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "One area EIC should be provided" + regexp = "Assertion on 'eic' failed: Must be of type 'string', not 'NULL'" ) testthat::expect_error( object = fcr_total_capacity( @@ -1523,7 +1717,7 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), tidy_output = TRUE ), - regexp = "This wrapper only supports one area EIC per request" + regexp = "Assertion on 'eic' failed: Must have length 1" ) testthat::expect_error( object = fcr_total_capacity( @@ -1542,16 +1736,27 @@ testthat::test_that( tidy_output = TRUE, security_token = "" ), - regexp = "Valid security token should be provided" + regexp = paste( + "Assertion on 'security_token' failed:", + "All elements must have at least 1 characters,", + "but element 1 has 0 characters." + ) ) } ) - testthat::test_that( desc = "shares_of_fcr_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = shares_of_fcr_capacity( eic = "10YDE-VE-------2", @@ -1616,10 +1821,17 @@ testthat::test_that( ) - testthat::test_that( desc = "rr_and_frr_actual_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = rr_and_frr_actual_capacity( eic = "10YAT-APG------L", @@ -1679,16 +1891,26 @@ testthat::test_that( period_end = lubridate::ymd(x = "2022-04-01", tz = "CET"), tidy_output = TRUE ), - regexp = "The 'business_type' should be 'C77', 'C78' or 'C79'." + regexp = paste0( + "Assertion on 'business_type' failed: ", + "Must be element of set \\{'C77','C78','C79'\\}, but is 'INVALID'." + ) ) } ) - testthat::test_that( desc = "rr_actual_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = rr_actual_capacity( eic = "10YCZ-CEPS-----N", @@ -1729,82 +1951,122 @@ testthat::test_that( ) +testthat::test_that( + desc = "sharing_of_frr_capacity() works", + code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) + # Note: [A26, A56, C22] combination is not available via the public API. + # The happy path for sharing_of_frr_capacity() cannot be exercised + # without a mock. + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = NULL, + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ), + info = "One acquiring domain EIC should be provided." + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = NULL, + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ), + info = "One connecting domain EIC should be provided." + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = c("10YCB-GERMANY--8", "10YDE-VE-------2"), + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ), + info = paste( + "This wrapper only supports one acquiring and", + "one connecting EIC per request." + ) + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + process_type = "INVALID", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ), + info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), + tidy_output = TRUE + ), + info = "One year range limit should be applied!" + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE, + security_token = "" + ), + info = "Valid security token should be provided." + ) + } +) + -# testthat::test_that( -# desc = "sharing_of_frr_capacity() works", -# code = { -# # Note: [A26, A56, C22] combination is not available via the public API. -# # The happy path for sharing_of_frr_capacity() cannot be exercised -# # without a mock. -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = NULL, -# eic_connecting = "10YAT-APG------L", -# process_type = "A56", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -# tidy_output = TRUE -# ), -# info = "One acquiring domain EIC should be provided." -# ) -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = "10YCB-GERMANY--8", -# eic_connecting = NULL, -# process_type = "A56", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -# tidy_output = TRUE -# ), -# info = "One connecting domain EIC should be provided." -# ) -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = c("10YCB-GERMANY--8", "10YDE-VE-------2"), -# eic_connecting = "10YAT-APG------L", -# process_type = "A56", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -# tidy_output = TRUE -# ), -# info = paste( -# "This wrapper only supports one acquiring and", -# "one connecting EIC per request." -# ) -# ) -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = "10YCB-GERMANY--8", -# eic_connecting = "10YAT-APG------L", -# process_type = "INVALID", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -# tidy_output = TRUE -# ), -# info = "The 'process_type' should be 'A56' (FRR) or 'A46' (RR)." -# ) -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = "10YCB-GERMANY--8", -# eic_connecting = "10YAT-APG------L", -# process_type = "A56", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2023-05-01", tz = "CET"), -# tidy_output = TRUE -# ), -# info = "One year range limit should be applied!" -# ) -# testthat::expect_error( -# object = sharing_of_frr_capacity( -# eic_acquiring = "10YCB-GERMANY--8", -# eic_connecting = "10YAT-APG------L", -# process_type = "A56", -# period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), -# period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), -# tidy_output = TRUE, -# security_token = "" -# ), -# info = "Valid security token should be provided." -# ) -# } -# ) +testthat::test_that( + desc = "sharing_of_frr_capacity() covers happy path with mock", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = charToRaw( + paste0( + '', + "Service Unavailable" + ) + ) + ) + } + ) + testthat::expect_error( + object = sharing_of_frr_capacity( + eic_acquiring = "10YCB-GERMANY--8", + eic_connecting = "10YAT-APG------L", + process_type = "A56", + period_start = lubridate::ymd(x = "2022-01-01", tz = "CET"), + period_end = lubridate::ymd(x = "2022-01-02", tz = "CET"), + tidy_output = TRUE + ), + regexp = "HTTP 503" + ) + } +) diff --git a/tests/testthat/test-en_generation.R b/tests/testthat/test-en_generation.R index 506f1307..37c015d1 100644 --- a/tests/testthat/test-en_generation.R +++ b/tests/testthat/test-en_generation.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "gen_installed_capacity_per_pt() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", @@ -20,32 +28,28 @@ testthat::test_that( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) - 3.4, psr_type = NULL - ), - info = "One valid integer year value should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = NULL, year = lubridate::year(x = Sys.Date()), psr_type = NULL - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()), security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pt( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), year = lubridate::year(x = Sys.Date()), psr_type = NULL - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pt( @@ -55,17 +59,23 @@ testthat::test_that( lubridate::year(x = Sys.Date()) - 1L ), psr_type = NULL - ), - info = "One valid integer year value should be provided!" + ) ) } ) - testthat::test_that( desc = "gen_installed_capacity_per_pu() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", @@ -85,8 +95,7 @@ testthat::test_that( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) + 1.4, psr_type = NULL - ), - info = "One valid integer year value should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pu( @@ -96,8 +105,7 @@ testthat::test_that( lubridate::year(x = Sys.Date()) - 1L ), psr_type = NULL - ), - info = "One valid integer year value should be provided!" + ) ) testthat::expect_no_error( object = gen_installed_capacity_per_pu( @@ -111,10 +119,6 @@ testthat::test_that( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()) + 4L, psr_type = NULL - ), - info = paste( - "Cannot be shown more than 3 years ahead", - "as required by the law!" ) ) testthat::expect_no_error( @@ -129,33 +133,37 @@ testthat::test_that( eic = NULL, year = lubridate::year(x = Sys.Date()), psr_type = NULL - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = "10YFR-RTE------C", year = lubridate::year(x = Sys.Date()), security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_installed_capacity_per_pu( eic = c("10YFR-RTE------C", "10YDE-VE-------2"), year = lubridate::year(x = Sys.Date()), psr_type = NULL - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "gen_storage_mean_filling_rate() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_storage_mean_filling_rate( eic = "10YFR-RTE------C", @@ -210,8 +218,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_storage_mean_filling_rate( @@ -225,8 +232,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_storage_mean_filling_rate( @@ -240,8 +246,7 @@ testthat::test_that( tz = "CET" ), security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_storage_mean_filling_rate( @@ -255,17 +260,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "Maximum 380 days range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "gen_per_prod_type() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_per_prod_type( eic = "10YFR-RTE------C", @@ -309,8 +320,7 @@ testthat::test_that( ), gen_type = NULL, tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_per_prod_type( @@ -325,8 +335,7 @@ testthat::test_that( ), gen_type = NULL, tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_per_prod_type( @@ -340,8 +349,7 @@ testthat::test_that( tz = "CET" ), security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_per_prod_type( @@ -356,17 +364,23 @@ testthat::test_that( ), gen_type = NULL, tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "gen_per_gen_unit() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_per_gen_unit( eic = "10YDE-VE-------2", @@ -441,8 +455,7 @@ testthat::test_that( gen_type = NULL, tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_per_gen_unit( @@ -457,8 +470,7 @@ testthat::test_that( ), gen_type = NULL, tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = gen_per_gen_unit( @@ -473,8 +485,7 @@ testthat::test_that( ), gen_type = NULL, tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = gen_per_gen_unit( @@ -490,17 +501,23 @@ testthat::test_that( gen_type = NULL, tidy_output = TRUE, security_token = NULL - ), - info = "alid security token should be provided!" + ) ) } ) - testthat::test_that( desc = "gen_day_ahead_forecast() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_day_ahead_forecast( eic = "10YFR-RTE------C", @@ -528,8 +545,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_day_ahead_forecast( @@ -543,8 +559,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area/bidding zone/country EIC should be provided!" + ) ) testthat::expect_error( object = gen_day_ahead_forecast( @@ -558,8 +573,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = gen_day_ahead_forecast( @@ -573,17 +587,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "gen_wind_solar_forecasts() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = gen_wind_solar_forecasts( eic = "10YFR-RTE------C", @@ -610,8 +630,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = gen_wind_solar_forecasts( @@ -625,8 +644,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area/bidding zone/country EIC should be provided!" + ) ) testthat::expect_error( object = gen_wind_solar_forecasts( @@ -641,8 +659,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = gen_wind_solar_forecasts( @@ -656,8 +673,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) diff --git a/tests/testthat/test-en_helpers.R b/tests/testthat/test-en_helpers.R index f30cbd85..ef568d47 100644 --- a/tests/testthat/test-en_helpers.R +++ b/tests/testthat/test-en_helpers.R @@ -1,6 +1,10 @@ testthat::test_that( desc = "all_approved_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- all_approved_eic() ) @@ -25,10 +29,13 @@ testthat::test_that( ) - testthat::test_that( desc = "party_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- party_eic() ) @@ -56,10 +63,13 @@ testthat::test_that( ) - testthat::test_that( desc = "area_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- area_eic() ) @@ -87,10 +97,13 @@ testthat::test_that( ) - testthat::test_that( desc = "accounting_point_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- accounting_point_eic() ) @@ -118,10 +131,13 @@ testthat::test_that( ) - testthat::test_that( desc = "tie_line_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- tie_line_eic() ) @@ -149,10 +165,13 @@ testthat::test_that( ) - testthat::test_that( desc = "location_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- location_eic() ) @@ -180,10 +199,13 @@ testthat::test_that( ) - testthat::test_that( desc = "resource_object_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- resource_object_eic() ) @@ -211,10 +233,13 @@ testthat::test_that( ) - testthat::test_that( desc = "substation_eic() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = tbl <- substation_eic() ) @@ -242,10 +267,13 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() responses got and appended into a tibble", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) mh$reset() testthat::expect_no_error( object = tbl <- all_allocated_eic() @@ -275,7 +303,6 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() errors with empty response body", code = { @@ -304,7 +331,6 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() errors on HTTP error response", code = { @@ -332,7 +358,6 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() parses XML content-type response", code = { @@ -363,7 +388,7 @@ testthat::test_that( expected = 0L ) testthat::expect_contains( - object = names(tbl), + object = names(tbl), expected = c( "eic_code", "doc_status", @@ -379,7 +404,6 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() parses ZIP/octet-stream content-type response", code = { @@ -413,7 +437,6 @@ testthat::test_that( ) - testthat::test_that( desc = "all_allocated_eic() stops on XML with unexpected structure", code = { @@ -450,3 +473,32 @@ testthat::test_that( ) } ) + + +testthat::test_that( + desc = "all_allocated_eic() uses cache on second call", + code = { + mh$reset() + xml_fixture <- readLines( + con = testthat::test_path("fixtures", "get_allocated_eic_min.xml"), + encoding = "UTF-8" + ) |> + paste(collapse = "\n") |> + charToRaw() + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 200L, + url = req$url, + headers = list("content-type" = "application/xml"), + body = xml_fixture + ) + } + ) + # First call populates the cache + tbl1 <- all_allocated_eic() + # Second call hits the cache (covers lines 424-425) + tbl2 <- all_allocated_eic() + testthat::expect_identical(tbl1, tbl2) + } +) diff --git a/tests/testthat/test-en_load.R b/tests/testthat/test-en_load.R index 5022da83..ef54058d 100644 --- a/tests/testthat/test-en_load.R +++ b/tests/testthat/test-en_load.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "load_actual_total() works and returns valid output structure", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_actual_total( eic = "10Y1001A1001A83F", @@ -30,8 +38,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = load_actual_total( @@ -45,8 +52,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = load_actual_total( @@ -61,8 +67,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_actual_total( @@ -76,17 +81,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "load_day_ahead_total_forecast() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_day_ahead_total_forecast( eic = "10Y1001A1001A83F", @@ -116,8 +127,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = load_day_ahead_total_forecast( @@ -131,8 +141,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request.!" + ) ) testthat::expect_error( object = load_day_ahead_total_forecast( @@ -147,8 +156,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_day_ahead_total_forecast( @@ -162,17 +170,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "load_week_ahead_total_forecast() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_week_ahead_total_forecast( eic = "10Y1001A1001A83F", @@ -202,8 +216,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = load_week_ahead_total_forecast( @@ -217,8 +230,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = load_week_ahead_total_forecast( @@ -233,8 +245,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_week_ahead_total_forecast( @@ -248,17 +259,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "load_month_ahead_total_forecast() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_month_ahead_total_forecast( eic = "10Y1001A1001A82H", @@ -288,8 +305,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = load_month_ahead_total_forecast( @@ -303,8 +319,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "his wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = load_month_ahead_total_forecast( @@ -319,8 +334,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_month_ahead_total_forecast( @@ -334,17 +348,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "load_year_ahead_total_forecast() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_year_ahead_total_forecast( eic = "10Y1001A1001A83F", @@ -374,8 +394,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = load_year_ahead_total_forecast( @@ -389,8 +408,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = load_year_ahead_total_forecast( @@ -405,8 +423,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_year_ahead_total_forecast( @@ -420,17 +437,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "load_year_ahead_forecast_margin() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) result <- testthat::expect_no_error( object = load_year_ahead_forecast_margin( eic = "10Y1001A1001A83F", @@ -460,8 +483,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided.!" + ) ) testthat::expect_error( object = load_year_ahead_forecast_margin( @@ -475,8 +497,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = load_year_ahead_forecast_margin( @@ -491,8 +512,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = load_year_ahead_forecast_margin( @@ -506,8 +526,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!!" + ) ) } ) diff --git a/tests/testthat/test-en_market.R b/tests/testthat/test-en_market.R index 9324852e..ebe2d725 100644 --- a/tests/testthat/test-en_market.R +++ b/tests/testthat/test-en_market.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "day_ahead_prices() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = day_ahead_prices( eic = "10YCZ-CEPS-----N", @@ -27,8 +35,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = day_ahead_prices( @@ -42,8 +49,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request.!" + ) ) testthat::expect_error( object = day_ahead_prices( @@ -58,8 +64,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = day_ahead_prices( @@ -73,17 +78,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "total_nominated_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = total_nominated_capacity( eic_in = "10YDE-VE-------2", @@ -113,8 +124,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = total_nominated_capacity( @@ -129,8 +139,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = total_nominated_capacity( @@ -145,8 +154,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = total_nominated_capacity( @@ -161,8 +169,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "his wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = total_nominated_capacity( @@ -177,17 +184,23 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "already_allocated_total_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = already_allocated_total_capacity( eic_in = "10YDE-VE-------2", @@ -220,8 +233,7 @@ testthat::test_that( auction_category = "A04", contract_type = "A01", tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = already_allocated_total_capacity( @@ -238,8 +250,7 @@ testthat::test_that( auction_category = "A04", contract_type = "A01", tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = already_allocated_total_capacity( @@ -256,8 +267,7 @@ testthat::test_that( auction_category = "A04", contract_type = "A01", tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = already_allocated_total_capacity( @@ -275,8 +285,7 @@ testthat::test_that( contract_type = "A01", tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = already_allocated_total_capacity( @@ -293,17 +302,23 @@ testthat::test_that( auction_category = "A04", contract_type = "A01", tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "implicit_offered_transfer_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = implicit_offered_transfer_capacity( eic_in = "10Y1001A1001A82H", @@ -333,8 +348,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -349,8 +363,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -365,8 +378,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -382,8 +394,7 @@ testthat::test_that( ), contract_type = "A99", tidy_output = FALSE - ), - info = "The 'contract_type' parameter should be 'A01' or 'A07'!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -399,8 +410,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -416,8 +426,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = implicit_offered_transfer_capacity( @@ -432,17 +441,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "explicit_offered_transfer_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = explicit_offered_transfer_capacity( eic_in = "10YBE----------2", @@ -472,8 +487,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = explicit_offered_transfer_capacity( @@ -488,8 +502,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = explicit_offered_transfer_capacity( @@ -504,8 +517,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = explicit_offered_transfer_capacity( @@ -521,10 +533,6 @@ testthat::test_that( ), contract_type = "A99", tidy_output = FALSE - ), - info = paste( - "The 'contract_type' parameter should be ", - "'A01', 'A02', 'A03', 'A04', 'A06', 'A07' or 'A08'!" ) ) testthat::expect_error( @@ -541,8 +549,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = explicit_offered_transfer_capacity( @@ -558,8 +565,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = explicit_offered_transfer_capacity( @@ -574,17 +580,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "continuous_offered_transfer_capacity() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = continuous_offered_transfer_capacity( eic_in = "10YNL----------L", @@ -613,8 +625,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = continuous_offered_transfer_capacity( @@ -629,8 +640,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = continuous_offered_transfer_capacity( @@ -645,8 +655,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = continuous_offered_transfer_capacity( @@ -662,8 +671,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = continuous_offered_transfer_capacity( @@ -679,8 +687,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = continuous_offered_transfer_capacity( @@ -695,17 +702,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "flow_based_allocations() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = flow_based_allocations( eic = "10YDOM-REGION-1V", @@ -735,8 +748,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = flow_based_allocations( @@ -750,8 +762,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = flow_based_allocations( @@ -766,10 +777,6 @@ testthat::test_that( ), process_type = "A99", tidy_output = FALSE - ), - info = paste( - "The 'process_type' parameter should be", - "'A32', 'A33', 'A43' or 'A44'!" ) ) testthat::expect_error( @@ -785,8 +792,7 @@ testthat::test_that( ), archive = "yes", tidy_output = FALSE - ), - info = "The 'archive' argument should be TRUE or FALSE!" + ) ) testthat::expect_error( object = flow_based_allocations( @@ -801,8 +807,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = flow_based_allocations( @@ -817,17 +822,23 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) } ) - testthat::test_that( desc = "auction_revenue() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = auction_revenue( eic_in = "10YBA-JPCC-----D", @@ -857,8 +868,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = auction_revenue( @@ -873,8 +883,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = auction_revenue( @@ -889,8 +898,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = auction_revenue( @@ -906,10 +914,6 @@ testthat::test_that( ), contract_type = "A99", tidy_output = FALSE - ), - info = paste( - "The 'contract_type' parameter should be", - "'A01', 'A02', 'A03', 'A04', 'A06', 'A07' or 'A08'!" ) ) testthat::expect_error( @@ -926,8 +930,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = auction_revenue( @@ -943,8 +946,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = auction_revenue( @@ -959,17 +961,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "net_positions() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = net_positions( eic = "10YCZ-CEPS-----N", @@ -997,8 +1005,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One bidding zone EIC should be provided!" + ) ) testthat::expect_error( object = net_positions( @@ -1012,8 +1019,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = net_positions( @@ -1028,8 +1034,7 @@ testthat::test_that( ), contract_type = "A99", tidy_output = FALSE - ), - info = "The 'contract_type' parameter should be 'A01' or 'A07'!" + ) ) testthat::expect_error( object = net_positions( @@ -1044,8 +1049,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = net_positions( @@ -1060,8 +1064,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = net_positions( @@ -1075,17 +1078,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "congestion_income() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = congestion_income( eic = "10YDOM-1001A083J", @@ -1129,8 +1138,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One border or bidding zone EIC should be provided!" + ) ) testthat::expect_error( object = congestion_income( @@ -1144,8 +1152,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = congestion_income( @@ -1160,10 +1167,6 @@ testthat::test_that( ), contract_type = "A99", tidy_output = FALSE - ), - info = paste( - "The 'contract_type' parameter should be", - "'A01', 'A02', 'A03', 'A04', 'A06', 'A07' or 'A08'!" ) ) testthat::expect_error( @@ -1179,8 +1182,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = congestion_income( @@ -1202,10 +1204,17 @@ testthat::test_that( ) - testthat::test_that( desc = "allocated_transfer_capacities_3rd_countries() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) df <- allocated_transfer_capacities_3rd_countries( eic_in = "10YSK-SEPS-----K", eic_out = "10YUA-WEPS-----0", @@ -1283,7 +1292,10 @@ testthat::test_that( ), tidy_output = FALSE ), - regexp = "One 'in' control area EIC should be provided" + regexp = paste0( + "Assertion on 'eic_in' failed: ", + "Must be of type 'string', not 'NULL'." + ) ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( @@ -1299,7 +1311,10 @@ testthat::test_that( ), tidy_output = FALSE ), - regexp = "One 'out' control area EIC should be provided" + regexp = paste( + "Assertion on 'eic_out' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( @@ -1315,7 +1330,7 @@ testthat::test_that( ), tidy_output = FALSE ), - regexp = "This wrapper only supports one in and one out EIC per request" + regexp = "Assertion on 'eic_in' failed: Must have length 1." ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( @@ -1333,8 +1348,9 @@ testthat::test_that( tidy_output = FALSE ), regexp = paste( - "The 'contract_type' parameter should be", - "'A01', 'A02', 'A03', 'A04', 'A06', 'A07' or 'A08'" + "Assertion on 'contract_type' failed:", + "Must be element of set", + "\\{'A01','A02','A03','A04','A06','A07','A08'\\}, but is 'A99'" ) ) testthat::expect_error( @@ -1352,7 +1368,11 @@ testthat::test_that( auction_category = "A99", tidy_output = FALSE ), - regexp = "The 'auction_category' should be 'A01', 'A02', 'A03' or 'A04'" + regexp = paste( + "Assertion on 'auction_category'", + "failed: Must be element of set \\{'A01','A02','A03','A04'\\},", + "but is 'A99'" + ) ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( @@ -1369,7 +1389,7 @@ testthat::test_that( position = 0L, tidy_output = FALSE ), - regexp = "The 'position' parameter should be a positive integer" + regexp = "Assertion on 'position' failed: Must be >= 1" ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( @@ -1386,7 +1406,11 @@ testthat::test_that( tidy_output = FALSE, security_token = "" ), - regexp = "Valid security token should be provided" + regexp = paste( + "Assertion on 'security_token' failed:", + "All elements must have at least 1 characters,", + "but element 1 has 0 characters." + ) ) testthat::expect_error( object = allocated_transfer_capacities_3rd_countries( diff --git a/tests/testthat/test-en_outages.R b/tests/testthat/test-en_outages.R index 385ce0d6..a456fb15 100644 --- a/tests/testthat/test-en_outages.R +++ b/tests/testthat/test-en_outages.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "outages_both() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_both( eic = "10YFR-RTE------C", @@ -41,18 +49,24 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) |> - testthat::expect_error(info = "One year range limit should be applied!") + testthat::expect_error() } ) - testthat::test_that( desc = "outages_gen_units() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_gen_units( eic = "10YFR-RTE------C", @@ -83,8 +97,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL!" + ) ) testthat::expect_error( object = outages_gen_units( @@ -100,8 +113,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'event_nature' parameter should be 'A53', 'A54' or NULL!" + ) ) testthat::expect_no_error( object = outages_gen_units( @@ -134,8 +146,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_gen_units( @@ -149,8 +160,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_gen_units( @@ -165,8 +175,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_gen_units( @@ -180,8 +189,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = outages_gen_units( @@ -194,17 +202,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "outages_prod_units() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_prod_units( eic = "10YFR-RTE------C", @@ -235,8 +249,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL!" + ) ) testthat::expect_error( object = outages_prod_units( @@ -252,8 +265,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'event_nature' parameter should be 'A53', 'A54' or NULL!" + ) ) testthat::expect_no_error( object = outages_prod_units( @@ -286,8 +298,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_prod_units( @@ -301,8 +312,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_prod_units( @@ -317,8 +327,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_prod_units( @@ -332,8 +341,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = outages_prod_units( @@ -346,17 +354,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "outages_offshore_grid() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_offshore_grid( eic = "10Y1001A1001A82H", @@ -385,8 +399,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL!" + ) ) testthat::expect_no_error( object = outages_offshore_grid( @@ -417,8 +430,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_offshore_grid( @@ -432,8 +444,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_offshore_grid( @@ -448,8 +459,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_offshore_grid( @@ -463,8 +473,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = outages_offshore_grid( @@ -477,17 +486,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "outages_cons_units() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_cons_units( eic = "10YFI-1--------U", @@ -534,8 +549,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL!" + ) ) testthat::expect_error( object = outages_cons_units( @@ -559,8 +573,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The 'event_nature' parameter should be 'A53', 'A54' or NULL!" + ) ) testthat::expect_no_error( object = outages_cons_units( @@ -609,8 +622,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_cons_units( @@ -632,8 +644,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_cons_units( @@ -656,8 +667,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_cons_units( @@ -679,8 +689,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = outages_cons_units( @@ -701,17 +710,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "outages_transmission_grid() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_transmission_grid( eic_in = "10YFR-RTE------C", @@ -760,8 +775,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "The 'doc_status' parameter should be 'A05', 'A09', 'A13' or NULL!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -786,8 +800,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "The 'event_nature' parameter should be 'A53', 'A54' or NULL!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -812,8 +825,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One OUT control area EIC should be provided!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -838,8 +850,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One IN control area EIC should be provided!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -865,8 +876,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -889,8 +899,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -914,8 +923,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -938,8 +946,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in control area EIC per request!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -962,8 +969,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one out control area EIC per request!" + ) ) testthat::expect_error( object = outages_transmission_grid( @@ -984,17 +990,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) - testthat::test_that( desc = "outages_fallbacks() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = outages_fallbacks( eic = "10YBE----------2", @@ -1026,8 +1038,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_fallbacks( @@ -1043,10 +1054,6 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = paste( - "The process_type value should be chosen among", - "'A47', 'A51' or 'A63'!" ) ) testthat::expect_error( @@ -1063,10 +1070,6 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = paste( - "The event_nature value should be chosen among", - "'C47', 'A53', 'A54' or '83'!" ) ) testthat::expect_error( @@ -1081,8 +1084,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) testthat::expect_error( object = outages_fallbacks( @@ -1097,8 +1099,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = outages_fallbacks( @@ -1112,8 +1113,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = outages_fallbacks( @@ -1126,8 +1126,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One control area EIC should be provided!" + ) ) } ) diff --git a/tests/testthat/test-en_transmission.R b/tests/testthat/test-en_transmission.R index c81c7b28..34ab05f5 100644 --- a/tests/testthat/test-en_transmission.R +++ b/tests/testthat/test-en_transmission.R @@ -1,6 +1,14 @@ testthat::test_that( desc = "cross_border_physical_flows() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = cross_border_physical_flows( eic_in = "10Y1001A1001A83F", @@ -29,8 +37,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = cross_border_physical_flows( @@ -44,8 +51,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = cross_border_physical_flows( @@ -59,8 +65,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = cross_border_physical_flows( @@ -76,8 +81,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = cross_border_physical_flows( @@ -93,8 +97,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = cross_border_physical_flows( @@ -109,17 +112,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "day_ahead_commercial_sched() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = day_ahead_commercial_sched( eic_in = "10YCZ-CEPS-----N", @@ -147,8 +156,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = day_ahead_commercial_sched( @@ -162,8 +170,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = day_ahead_commercial_sched( @@ -178,8 +185,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = day_ahead_commercial_sched( @@ -195,8 +201,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = day_ahead_commercial_sched( @@ -212,8 +217,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = day_ahead_commercial_sched( @@ -228,17 +232,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "total_commercial_sched() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = total_commercial_sched( eic_in = "10YCZ-CEPS-----N", @@ -266,8 +276,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = total_commercial_sched( @@ -281,8 +290,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = total_commercial_sched( @@ -297,8 +305,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = total_commercial_sched( @@ -314,8 +321,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = total_commercial_sched( @@ -331,8 +337,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = total_commercial_sched( @@ -347,17 +352,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "forecasted_transfer_capacities works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = forecasted_transfer_capacities( eic_in = "10YCZ-CEPS-----N", @@ -385,8 +396,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = forecasted_transfer_capacities( @@ -400,8 +410,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = forecasted_transfer_capacities( @@ -416,8 +425,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = forecasted_transfer_capacities( @@ -433,8 +441,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = forecasted_transfer_capacities( @@ -450,8 +457,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = forecasted_transfer_capacities( @@ -466,17 +472,23 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "redispatching_cross_border() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = redispatching_cross_border( eic_in = "10YDE-VE-------2", @@ -520,8 +532,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The number of instances (N) exceeds the allowed maximum (100)" + ) ) testthat::expect_error( object = redispatching_cross_border( @@ -536,8 +547,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = redispatching_cross_border( @@ -552,8 +562,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = redispatching_cross_border( @@ -568,8 +577,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = redispatching_cross_border( @@ -584,8 +592,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = redispatching_cross_border( @@ -601,17 +608,23 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) } ) - testthat::test_that( desc = "redispatching_internal() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = redispatching_internal( eic = "10YNO-0--------C", @@ -638,8 +651,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The number of instances (N) exceeds the allowed maximum (100)" + ) ) testthat::expect_error( object = redispatching_internal( @@ -653,8 +665,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = redispatching_internal( @@ -668,8 +679,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one control area EIC per request!" + ) ) testthat::expect_error( object = redispatching_internal( @@ -684,17 +694,23 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) } ) - testthat::test_that( desc = "countertrading() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = countertrading( eic_in = "10YFR-RTE------C", @@ -723,8 +739,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "The number of instances (N) exceeds the allowed maximum (100)" + ) ) testthat::expect_error( object = countertrading( @@ -739,8 +754,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = countertrading( @@ -755,8 +769,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = countertrading( @@ -771,8 +784,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = countertrading( @@ -787,8 +799,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = countertrading( @@ -804,17 +815,23 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) } ) - testthat::test_that( desc = "costs_of_congestion_management() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = costs_of_congestion_management( eic = "10YBE----------2", @@ -839,10 +856,6 @@ testthat::test_that( period_end = lubridate::ymd(x = "2017-01-01", tz = "CET"), event_nature = "B99", tidy_output = TRUE - ), - info = paste( - "The 'event_nature' parameter should be", - "'A46', 'B03', 'B04' or NULL!" ) ) testthat::expect_no_error( @@ -885,8 +898,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "One control area EIC should be provided!" + ) ) testthat::expect_error( object = costs_of_congestion_management( @@ -900,8 +912,7 @@ testthat::test_that( tz = "CET" ), tidy_output = TRUE - ), - info = "This wrapper only supports one EIC per request!" + ) ) testthat::expect_error( object = costs_of_congestion_management( @@ -916,8 +927,7 @@ testthat::test_that( ), tidy_output = TRUE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = costs_of_congestion_management( @@ -925,17 +935,23 @@ testthat::test_that( period_start = lubridate::ymd(x = "2016-01-01", tz = "CET"), period_end = lubridate::ymd(x = "2020-01-01", tz = "CET"), tidy_output = TRUE - ), - info = "One year range limit should be applied!" + ) ) } ) - testthat::test_that( desc = "expansion_and_dismantling_project() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = expansion_and_dismantling_project( eic_in = "10YSK-SEPS-----K", @@ -968,8 +984,7 @@ testthat::test_that( business_type = "B01", doc_status = "A05", tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = expansion_and_dismantling_project( @@ -986,8 +1001,7 @@ testthat::test_that( business_type = "B01", doc_status = "A05", tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = expansion_and_dismantling_project( @@ -1004,8 +1018,7 @@ testthat::test_that( business_type = "B01", doc_status = "A05", tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = expansion_and_dismantling_project( @@ -1023,8 +1036,7 @@ testthat::test_that( doc_status = "A05", tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = expansion_and_dismantling_project( @@ -1041,8 +1053,7 @@ testthat::test_that( business_type = "B99", doc_status = "A05", tidy_output = FALSE - ), - info = "The 'business_type' parameter should be 'B01' or 'B02'!" + ) ) testthat::expect_error( object = expansion_and_dismantling_project( @@ -1059,20 +1070,23 @@ testthat::test_that( business_type = "B01", doc_status = "X99", tidy_output = FALSE - ), - info = paste( - "The 'doc_status' parameter should be", - "'A01', 'A02', 'A05', 'A09', 'A13' or 'X01'!" ) ) } ) - testthat::test_that( desc = "intraday_cross_border_transfer_limits() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_no_error( object = intraday_cross_border_transfer_limits( eic_in = "10YFR-RTE------C", @@ -1101,8 +1115,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'in' control area EIC should be provided!" + ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( @@ -1117,8 +1130,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One 'out' control area EIC should be provided!" + ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( @@ -1133,8 +1145,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "This wrapper only supports one in and one out EIC per request!" + ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( @@ -1150,8 +1161,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "" - ), - info = "Valid security token should be provided!" + ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( @@ -1167,8 +1177,7 @@ testthat::test_that( ), tidy_output = FALSE, security_token = "ABC" - ), - info = "Unauthorized. Missing or invalid security token!" + ) ) testthat::expect_error( object = intraday_cross_border_transfer_limits( @@ -1183,8 +1192,7 @@ testthat::test_that( tz = "CET" ), tidy_output = FALSE - ), - info = "One year range limit should be applied!" + ) ) } ) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 31e3703f..9d5dddff 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -260,10 +260,17 @@ testthat::test_that( ) - testthat::test_that( desc = "extract_leaf_twig_branch() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) url_sample_2 <- paste( "documentType=A73", "processType=A16", @@ -414,7 +421,6 @@ testthat::test_that( ) - testthat::test_that( desc = "read_zipped_xml() works", code = { @@ -427,12 +433,16 @@ testthat::test_that( xml_sample_file <- tempfile(fileext = "xml") zip_xml_sample_file <- tempfile(fileext = ".zip") data.table::fwrite(x = mtcars, file = csv_sample_file, sep = ";") - zip(zipfile = zip_sample_file, - files = c(csv_sample_file)) + zip( + zipfile = zip_sample_file, + files = c(csv_sample_file) + ) cd_cat_xml <- xml2::read_xml(xml2::xml2_example(path = "cd_catalog.xml")) xml2::write_xml(x = cd_cat_xml, file = xml_sample_file) - zip(zipfile = zip_xml_sample_file, - files = c(xml_sample_file)) + zip( + zipfile = zip_xml_sample_file, + files = c(xml_sample_file) + ) testthat::expect_warning( object = read_zipped_xml(temp_file_path = tempfile()), info = "In .f(...) : error 1 in extracting from zip file" @@ -452,7 +462,6 @@ testthat::test_that( ) - testthat::test_that( desc = "calc_offset_urls() works", code = { @@ -488,10 +497,17 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) url_sample_1 <- paste( "documentType=A73", "processType=A16", @@ -555,18 +571,24 @@ testthat::test_that( query_string = NULL, security_token = Sys.getenv("ENTSOE_PAT") ), - regexp = "The argument 'query_string' is missing!" + regexp = paste( + "Assertion on 'query_string' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = api_req(), - regexp = "The argument 'query_string' is missing!" + regexp = paste( + "Assertion on 'query_string' failed:", + "Must be of type 'string', not 'NULL'" + ) ) testthat::expect_error( object = api_req( query_string = NA, security_token = Sys.getenv("ENTSOE_PAT") ), - regexp = "Input parameter does not exist: NA" + regexp = "Assertion on 'query_string' failed: May not be NA." ) testthat::expect_error( object = api_req( @@ -589,7 +611,10 @@ testthat::test_that( object = api_req( query_string = url_sample_1 ), - regexp = "The argument 'security_token' is not provided" + regexp = paste( + "Assertion on 'security_token' failed:", + "Must be of type 'string', not 'NULL'." + ) ) testthat::expect_s3_class( object = api_req( @@ -603,7 +628,7 @@ testthat::test_that( query_string = url_sample_2, security_token = Sys.getenv("ENTSOE_PAT") ) |> - purrr::map(~inherits(x = .x, what = "xml_document")) |> + purrr::map(~ inherits(x = .x, what = "xml_document")) |> unlist() |> all(), info = "The url value should be printed in console!" @@ -612,10 +637,17 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req_safe() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) url_sample_1 <- paste( "documentType=A73", "processType=A16", @@ -658,7 +690,6 @@ testthat::test_that( ) - testthat::test_that( desc = "url_posixct_format() works", code = { @@ -699,18 +730,21 @@ testthat::test_that( stringr::str_like(pattern = "[0-9]{12}"), info = "The result of this functions should be 12 digit length string!" ) - testthat::expect_warning( + testthat::expect_message( object = url_posixct_format(x = "20240722210000"), - info = "The 'x' value has been interpreted as UTC!" + regexp = "The .+ value has been interpreted as UTC!" ) } ) - testthat::test_that( desc = "get_eiccodes() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) testthat::expect_contains( object = get_eiccodes( f = "Y_eicCodes.csv" @@ -777,15 +811,14 @@ testthat::test_that( ) - testthat::test_that( desc = "unpack_xml() works", code = { testthat::expect_equal( object = xml2::xml2_example(path = "order-schema.xml") |> xml2::read_xml() |> - unpack_xml(parent_name = "foo") - |> dim(), + unpack_xml(parent_name = "foo") |> + dim(), expected = c(1L, 4L) ) testthat::expect_contains( @@ -818,7 +851,6 @@ testthat::test_that( ) - testthat::test_that( desc = "tidy_or_not() works", code = { @@ -913,7 +945,6 @@ testthat::test_that( ) - testthat::test_that( desc = "my_snakecase() works", code = { @@ -958,13 +989,15 @@ testthat::test_that( ) testthat::expect_error( object = my_snakecase(tbl = NULL), - info = "The argument 'tbl' is missing!" + regexp = paste( + "Assertion on 'tbl' failed:", + "Must be of type 'data.frame', not 'NULL'." + ) ) } ) - testthat::test_that( desc = "add_type_names() works", code = { @@ -1067,10 +1100,13 @@ testthat::test_that( ) - testthat::test_that( desc = "add_eic_names() works", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) df <- data.frame( ts_in_domain_mrid = c( "16YAOGUADIANA--T", @@ -1141,7 +1177,6 @@ testthat::test_that( ) - testthat::test_that( desc = "add_definitions() works", code = { @@ -1210,10 +1245,17 @@ testthat::test_that( ) - testthat::test_that( desc = "xml_to_table() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) url_sample_1 <- paste( "documentType=A73", "processType=A16", @@ -1346,10 +1388,17 @@ testthat::test_that( ) - testthat::test_that( desc = "extract_response() works", code = { + testthat::skip_if_not( + condition = nchar(Sys.getenv("ENTSOE_PAT")) > 0L, + message = "No ENTSOE_PAT environment variable set" + ) + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) url_sample_2 <- paste( "documentType=A73", "processType=A16", @@ -1436,7 +1485,6 @@ testthat::test_that( ) - testthat::test_that( desc = paste( "get_all_allocated_eic() returns a tibble", @@ -1485,7 +1533,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() joins doc_status from message_types correctly", @@ -1516,7 +1563,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() stops with HTTP error message and request URL", @@ -1547,7 +1593,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() stops on empty response body", code = { @@ -1565,7 +1610,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() stops on XML with unexpected tree structure", code = { @@ -1593,7 +1637,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() returns one row per EICCode_MarketDocument node", @@ -1623,7 +1666,6 @@ testthat::test_that( ) - testthat::test_that( desc = "get_all_allocated_eic() collapses duplicate Function_Names with ' - '", @@ -1656,7 +1698,6 @@ testthat::test_that( ) - testthat::test_that( desc = paste( "get_all_allocated_eic() stops with error message", @@ -1668,8 +1709,7 @@ testthat::test_that( list(message = paste( "Could not resolve host:", "eepublicdownloads.blob.core.windows.net" - ) - ) + )) ) httr2_err <- structure( class = c("httr2_failure", "httr2_error", "error", "condition"), @@ -1694,7 +1734,6 @@ testthat::test_that( ) - testthat::test_that( desc = "tidy_or_not() stops on unknown curve_type", code = { @@ -1713,7 +1752,6 @@ testthat::test_that( ) - testthat::test_that( desc = paste( "get_all_allocated_eic() collapses actual duplicate", @@ -1749,18 +1787,21 @@ testthat::test_that( ) - testthat::test_that( desc = "add_eic_names() adds names for additional domain mrid columns", code = { + testthat::skip_if_not( + condition = there_is_provider(), + message = "The Entso-e API cannot be reached" + ) eic_val <- "16YAOGUADIANA--T" df <- data.frame( - area_domain_mrid = eic_val, - ts_acquiring_domain_mrid = eic_val, - ts_connecting_domain_mrid = eic_val, - bid_ts_acquiring_domain_mrid = eic_val, + area_domain_mrid = eic_val, + ts_acquiring_domain_mrid = eic_val, + ts_connecting_domain_mrid = eic_val, + bid_ts_acquiring_domain_mrid = eic_val, bid_ts_connecting_domain_mrid = eic_val, - domain_mrid = eic_val, + domain_mrid = eic_val, constraint_ts_monitored_ptdf_domain_mrid = eic_val, stringsAsFactors = FALSE ) @@ -1788,7 +1829,6 @@ testthat::test_that( ) - testthat::test_that( desc = "add_definitions() unites multiple ts_reason_code columns", code = { @@ -1809,7 +1849,6 @@ testthat::test_that( ) - testthat::test_that( desc = "xml_to_table() tryCatch handler fires on unequal-group XML", code = { @@ -1833,7 +1872,6 @@ testthat::test_that( ) - testthat::test_that( desc = "extract_response() returns empty tibble for NULL result element", code = { @@ -1845,7 +1883,6 @@ testthat::test_that( ) - testthat::test_that( desc = "extract_response() processes a list-of-xml_documents element", code = { @@ -1861,7 +1898,6 @@ testthat::test_that( ) - testthat::test_that( desc = "extract_response() returns empty tibble for list of non-documents", code = { @@ -1873,7 +1909,6 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() stops on unknown 200 response content-type", code = { @@ -1898,7 +1933,6 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() stops on HTML error response", code = { @@ -1927,7 +1961,6 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() stops on XML error with unexpected Reason structure", code = { @@ -1960,7 +1993,6 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() stops with code:text message on non-999 XML error code", code = { @@ -1996,7 +2028,6 @@ testthat::test_that( ) - testthat::test_that( desc = "api_req() stops with curl error message on no internet connection", code = { @@ -2031,3 +2062,119 @@ testthat::test_that( ) } ) + + +testthat::test_that( + desc = "api_req() stops with HTTP 503 message on service unavailable", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + url = req$url, + headers = list("content-type" = "text/html"), + body = charToRaw("Service Unavailable") + ) + } + ) + testthat::expect_error( + object = api_req( + query_string = "documentType=A73", + security_token = "dummy_token" + ), + regexp = "HTTP 503" + ) + } +) + + +testthat::test_that( + desc = "there_is_provider() returns TRUE on 401 Unauthorized", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 401L, + headers = list("content-type" = "text/html"), + body = charToRaw("Unauthorized") + ) + } + ) + testthat::expect_true( + object = there_is_provider() + ) + } +) + + +testthat::test_that( + desc = "there_is_provider() returns FALSE on 503 Service Unavailable", + code = { + httr2::local_mocked_responses( + mock = function(req) { + httr2::response( + status_code = 503L, + headers = list("content-type" = "text/html"), + body = charToRaw("Service Unavailable") + ) + } + ) + testthat::expect_false( + object = there_is_provider() + ) + } +) + + +testthat::test_that( + desc = "there_is_provider() returns FALSE on network/curl error", + code = { + curl_err <- structure( + class = c("curl_error", "error", "condition"), + list(message = "Could not resolve host: web-api.tp.entsoe.eu") + ) + httr2_err <- structure( + class = c("httr2_failure", "httr2_error", "error", "condition"), + list( + message = "Failed to perform HTTP request.", + resp = NULL, + parent = curl_err + ) + ) + httr2::local_mocked_responses( + mock = function(req) stop(httr2_err) + ) + testthat::expect_false( + object = there_is_provider() + ) + } +) + + +testthat::test_that( + desc = "there_is_provider() uses custom api_scheme, api_domain, and api_name", + code = { + captured_url <- NULL + httr2::local_mocked_responses( + mock = function(req) { + captured_url <<- req$url + httr2::response( + status_code = 401L, + headers = list("content-type" = "text/html"), + body = charToRaw("Unauthorized") + ) + } + ) + testthat::expect_true( + object = there_is_provider( + api_scheme = "http://", + api_domain = "test.example.com/", + api_name = "api?" + ) + ) + testthat::expect_match( + object = captured_url, + regexp = "test\\.example\\.com" + ) + } +) diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 00000000..097b2416 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/da-price-spread-vignette.Rmd b/vignettes/da-price-spread-vignette.Rmd new file mode 100644 index 00000000..679549fe --- /dev/null +++ b/vignettes/da-price-spread-vignette.Rmd @@ -0,0 +1,114 @@ +--- +title: "Day-Ahead Price Spread Vignette" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Day-Ahead Price Spread Vignette} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.width = 10, + fig.height = 6, + out.width = "98%", + out.height = "98%" +) +``` + +```{r setup} +library(entsoeapi) +library(dplyr) |> suppressPackageStartupMessages() +library(lubridate) |> suppressPackageStartupMessages() +library(cli) +library(ggplot2) +``` + +#### Look for the Polish market EIC and set the start and the end of scope dates + +```{r preset constants} +pl_eic <- all_approved_eic() |> + filter(EicLongName == "Poland") |> + select("EicCode") |> + unlist() + +from_ts <- force_tz(time = as.Date("2026-01-01"), tzone = "CET") +till_ts <- from_ts + weeks(x = 1L) + +cli_inform("Polish EIC: '{pl_eic}'") +cli_inform("from: {from_ts}") +cli_inform("till: {till_ts}") +``` + +#### Query the Polish DA prices within the pre-set period + +```{r query da prices} +da_prices <- entsoeapi::day_ahead_prices( + eic = pl_eic, + period_start = from_ts, + period_end = till_ts, + tidy_output = TRUE +) +glimpse(da_prices) +``` + +#### Calculate the daily minimum and maximum prices and the spread + +```{r calculate the daily spreads} +da_spreads <- da_prices |> + select(c(ts_point_dt_start, ts_point_price_amount)) |> + mutate( + ts_point_dt_start = with_tz(time = ts_point_dt_start, tzone = "CET") + ) |> + mutate(ts_point_date = as.Date(x = ts_point_dt_start, tz = "CET")) |> + group_by(ts_point_date) |> + mutate( + max_price = max(ts_point_price_amount, na.rm = TRUE), + min_price = min(ts_point_price_amount, na.rm = TRUE) + ) |> + mutate( + price_spread = max_price - min_price + ) |> + select(c(ts_point_date, min_price, max_price, price_spread)) |> + unique() +``` + +#### Plot the daily minimum and maximum prices and the spread + +```{r plot the daily spreads} +ggplot(data = da_spreads) + + geom_segment( + mapping = aes( + x = ts_point_date, + xend = ts_point_date, + y = min_price, + yend = max_price + ), + linewidth = 10, + color = "tomato" + ) + + geom_text( + mapping = aes( + x = ts_point_date, + y = max_price + 10, + label = price_spread + ), + size = 4 + ) + + scale_x_date( + breaks = da_spreads$ts_point_date, + date_labels = "%Y-%m-%d" + ) + + theme_minimal() + + labs( + title = "Polish Daily Spread of Day-Ahead prices", + subtitle = paste("PT15M,", from_ts, till_ts), + x = "delivery date", + y = "day-ahead price spread" + ) + + theme( + axis.text.x = element_text(angle = 45, hjust = 1) + ) +```