Giter Site home page Giter Site logo

bnmr's Introduction

Hi there 👋

I'm a data scientist with experience in applied microeconometrics, machine learning and technical writing. I am package maintainer of the R package bnmr and an author of pmdplyr, and I volunteer for PyData Kuala Lumpur.

bnmr's People

Contributors

danielyuo avatar haydenmacdonald avatar j450h1 avatar jcrodriguez1989 avatar philip-khor avatar zatch3301 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bnmr's Issues

vctrs migration?

Not sure if this package should move to using vctrs in the background e.g. vec_c, vec_size

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Fix column names

Is your feature request related to a problem? Please describe.

e.g. names of output of exchange_rate() not syntatically valid:

exchange_rate()
#> # A tibble: 7 x 3
#>   currency_code  unit rate$date  $buying_rate $selling_rate $middle_rate
#>   <chr>         <int> <chr>             <dbl>         <dbl> <lgl>       
#> 1 USD               1 2020-10-12         4.12          4.15 NA          
#> 2 SGD               1 2020-10-12         3.03          3.07 NA          
#> 3 JPY             100 2020-10-12         3.89          3.94 NA          
#> 4 GBP               1 2020-10-12         5.36          5.41 NA          
#> 5 EUR               1 2020-10-12         4.87          4.91 NA          
#> 6 CAD               1 2020-10-12         3.13          3.17 NA          

This makes $ indexing impossible.

This problem arises from the nested JSON format returned by the API. Need to think about how to flatten/tidy the output.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

fix documentation to track the right branch

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Turn function names into verbs

base_rate() -> get_base_rate(), etc.

To deprecate functions,

  1. deprecate the old function names.

bnmr/R/base_rate.R

Lines 39 to 48 in 81ccab1

#' Base rate
#'
#' Deprecated. Use \code{\link{get_base_rate}}
#' @inheritParams get_base_rate
#'
#' @export
base_rate <- function(bank_code = NULL) {
.Deprecated(new = "get_base_rate")
get_base_rate(bank_code = bank_code)
}

  1. Update roxygen2 examples

bnmr/R/base_rate.R

Lines 10 to 12 in 81ccab1

#' @examples
#' get_base_rate()
#' @export

  1. Add the function to bnmr-deprecated.R:

#' Deprecated Functions in Package bnmr
#'
#' These functions are provided for compatibility with older versions of
#' \code{bnmr} only, and may be defunct as soon as the next release.
#'
#' \itemize{
#' \item \code{\link{base_rate}}
#' \item \code{\link{exchange_rate}}
#' }
#'
#' @name bnmr-deprecated
# EXCLUDE COVERAGE START
NULL
# EXCLUDE COVERAGE END

  1. then rebuild documentation using devtools::document() then pkgdown using pkgdown::build_site().

  2. Update the test file in the test/ folder to reflect the new function.

See #14 for an example.

No need to change all in a single pull request: feel free to make separate pull requests for each file.

  • base_rate -> get_base_rate
  • exchange_rate -> get_exchange_rate
  • consumer_alert() #18
  • daily_fx_turnover()
  • interbank_swap() #18
  • interest_rate() #18
  • interest_volume() #18
  • islamic_interbank_rate() #18
  • kijang_emas() #18
  • kl_usd_reference_rate()
  • opr()
  • renminbi()
  • usd_interbank_intraday_rate()

rlang migration

is.null -> is_null, etc.,

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Trim namespace

MSB introduces a lot of endpoints. We need to figure out some way to organize them into fewer functions. For example, the aggregate output endpoints are organized as follows:

bnmr/R/msb.R

Lines 612 to 680 in 547dce1

#' External sector and macroeconomic indicators: aggregate output
#'
#' @param year Scalar integer
#' @param metric One of "gdp", "gni"
#' @param output_by One of "expenditure", "activity"
#' @export
#' @return nested list with "amt" and "change". Different base rates are
#' nested within.
#' @examples
#' # we retrieve GDP by expenditure by default
#' res <- get_aggregate_output()
#'
#' # result is a nested list
#' str(res)
#'
#' # to get change at 2000 prices run the following:
#' res$change$base_2000
#' @name msb3_output
get_aggregate_output <- function(year = NULL, metric = "gdp", output_by = "expenditure", change = TRUE) {
assert_that(metric %in% c("gdp", "gni"))
assert_that(output_by %in% c("expenditure", "activity"))
if (metric == "gdp") {
if (output_by == "expenditure") {
message("GDP by expenditure")
return(
list(
# TODO find a better name than amt
# amt = .get_msb_data("3.2", year = year),
change = list(
base_2000 = .get_msb_data("3.3a", year = year),
base_2010 = .get_msb_data("3.3", year = year)
)
)
)
} else if (output_by == "activity") {
return(
list(
amt = list(
base_2000 = .get_msb_data("3.4.1a", year = year),
base_2010 = .get_msb_data("3.4.1", year = year),
current = .get_msb_data("3.4.2", year = year)
),
change = list(
base_2000 = .get_msb_data("3.4a", year = year),
base_2010 = .get_msb_data("3.4", year = year)
)
)
)
}
} else if (metric == "gni") {
if (output_by == "expenditure") {
return(
list(
# TODO find a better name than amt
# amt = .get_msb_data("3.2", year = year),
amt = list(
base_2000 = .get_msb_data("3.3.1a", year = year),
base_2010 = .get_msb_data("3.3.1", year = year)
),
change = NULL
)
)
} else {
message("No endpoint for retrieving GNI by economic activity")
NULL
}
}
}

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

One test case fails if there is no internet connection.

Describe the bug
If there is no internet connection, the test_api_access.R test cases are failing, these should be skipped.

To Reproduce
Steps to reproduce the behavior:

  1. Disconnect internet.
  2. Run devtools::test().
==> devtools::test()

Loading bnmr
BNM Open API
Please visit https://api.bnm.gov.my/disclaimer to view disclaimers.
Testing bnmr|  OK F W S | Context
x |   0 1     | test_api_access
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
test_api_access.R:2: error: welcome returns correct name
Could not resolve host: api.bnm.gov.my
Backtrace:
 1. testthat::expect_equal(bnm_api("/welcome")$content$name, "BNM.API") tests/testthat/test_api_access.R:2:2
 4. bnmr::bnm_api("/welcome")
 5. httr::GET(...) R/main.R:16:2
 6. httr:::request_perform(req, hu$handle$handle)
 8. httr:::request_fetch.write_memory(req$output, req$url, handle)
 9. curl::curl_fetch_memory(url, handle = handle)
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✓ |   0     1 | test_base_rate
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Expected behavior
Test should be skipped.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.