Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow EUR as unit sign as well as € #35

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2097375'
ValidationKey: '2198460'
AutocreateReadme: no
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'GDPuc: Easily Convert GDP Data'
version: 1.0.5
date-released: '2024-09-09'
version: 1.1.0
date-released: '2024-09-20'
abstract: Convert GDP time series data from one unit to another. All common GDP units
are included, i.e. current and constant local currency units, US$ via market exchange
rates and international dollars via purchasing power parities.
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: GDPuc
Title: Easily Convert GDP Data
Version: 1.0.5
Date: 2024-09-09
Version: 1.1.0
Date: 2024-09-20
Authors@R:
person("Johannes", "Koch", , "jokoch@pik-potsdam.de", role = c("aut", "cre"))
Description: Convert GDP time series data from one unit to
Expand Down
15 changes: 8 additions & 7 deletions R/check_user_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ check_gdp <- function(gdp) {
# Check input parameters 'unit_in' and 'unit_out'
check_unit_in_out <- function(unit_in, unit_out) {
valid_units <- c(
"current LCU",
"current US\\$MER",
"current Int\\$PPP",
"constant .... LCU",
"constant .... US\\$MER",
"constant .... \u20ac",
"constant .... Int\\$PPP"
"^current LCU$",
"^current US\\$MER$",
"^current Int\\$PPP$",
"^constant .... LCU$",
"^constant .... US\\$MER$",
"^constant .... \u20ac$",
"^constant .... EUR$",
"^constant .... Int\\$PPP$"
)
if (!is.character(unit_in) || !any(sapply(valid_units, grepl, unit_in))) {
abort("Invalid 'unit_in' argument.")
Expand Down
2 changes: 1 addition & 1 deletion R/convertGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ convertGDP <- function(gdp,
gsub("_YYYY", "", .) %>%
gsub("\\$", "", .) %>%
# \u20ac is the ascii code for the € sign
gsub("\u20ac", "EURO", .)
gsub("\u20ac|EUR", "EURO", .)

# Get list of function arguments
a <- list("gdp" = internal$gdp, "source" = internal$source) %>%
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-05_convertGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,24 @@ test_that("convertSingle", {
expect_equal(gdp1_conv$value, gdp2_conv)
expect_equal(gdp1_conv, gdp3_conv$result)
})

test_that("convert euros", {
gdp1_conv <- convertSingle(100, "USA",
unit_in = "constant 2015 LCU",
unit_out = "constant 2017 €")

gdp2_conv <- convertSingle(100, "USA",
unit_in = "constant 2015 LCU",
unit_out = "constant 2017 EUR")

gdp3_conv <- convertSingle(100, "DEU",
unit_in = "constant 2010 LCU",
unit_out = "constant 2017 €")

gdp4_conv <- convertSingle(100, "DEU",
unit_in = "constant 2010 €",
unit_out = "constant 2017 LCU")

expect_equal(gdp1_conv, gdp2_conv)
expect_equal(gdp3_conv, gdp4_conv)
})
Loading