Skip to content

Commit

Permalink
Merge pull request #50 from next-game-solutions/49-refactor-tidyselec…
Browse files Browse the repository at this point in the history
…t-expressions

49 refactor tidyselect expressions
  • Loading branch information
next-game-solutions authored Apr 15, 2023
2 parents 6b421df + 230658b commit 40955da
Show file tree
Hide file tree
Showing 30 changed files with 89 additions and 156 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
^\.github/workflows/R-CMD-check\.yaml$
^\.github/workflows/test-coverage\.yaml$
^CRAN-RELEASE$
^CRAN-SUBMISSION$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: geckor
Title: R Client for the 'CoinGecko' API
Version: 0.3.0.9000
Version: 0.3.0
Authors@R: c(
person("Sergey", "Mastitsky",
role = c("aut", "cre"),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export(trending_coins)
importFrom(knitr,clean_cache)
importFrom(lifecycle,badge)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# geckor 0.3.0

As v0.3.0, `geckor` is no longer published on CRAN.

## Major changes

CoinGecko significantly reduced the rate limit of the free version of its API - from 50 to ca. 10-30 calls/minute. This had a dramatic effect on how `geckor` functions and how much data can be retrieved using its functions. In particular, the following changes had to be introduced in v0.3.0:
CoinGecko significantly reduced the rate limit of the free version of its API - from 50 to ca. 10-30 calls/minute. This had a dramatic effect on how `geckor` functions and how much data can be retrieved using its functions. In particular, the following changes had to be introduced in v0.3.0:

* All of the `coin_history_*` functions now accept a much smaller number of coin IDs to process simultaneously (5 vs 30 in v0.2.0).
* The `coin_tickers()` function retrieves up to 5 pages of data.
* Tests are now skipped not only on CRAN but also when `ping()` returns `FALSE` before running the test.
* Examples in the package documentation now won't execute when running `R CMD check`.
* Examples in vignettes are not evaluated any more.

Expand Down
5 changes: 2 additions & 3 deletions R/coin_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#' returns nothing (`NULL`).
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @export
#'
Expand Down Expand Up @@ -70,7 +69,7 @@ coin_history <- function(coin_id,
)

if (is.na(days) ||
is.na(suppressWarnings(as.numeric(days))) && days != "max") {
is.na(suppressWarnings(as.numeric(days))) && days != "max") {
rlang::abort("`days` only accepts coercible-to-numeric values or a character value \"max\"")
}

Expand Down Expand Up @@ -145,7 +144,7 @@ coin_history <- function(coin_id,
) %>%
dplyr::mutate(
timestamp = as.POSIXct(
.data$timestamp / 1000,
timestamp / 1000,
origin = as.Date("1970-01-01"),
tz = "UTC", format = "%Y-%m-%d %H:%M:%S"
)
Expand Down
3 changes: 1 addition & 2 deletions R/coin_history_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#' returns nothing (`NULL`).
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @export
#'
Expand Down Expand Up @@ -136,7 +135,7 @@ coin_history_range <- function(coin_id,
) %>%
dplyr::mutate(
timestamp = as.POSIXct(
.data$timestamp / 1000,
timestamp / 1000,
origin = as.Date("1970-01-01"),
tz = "UTC", format = "%Y-%m-%d %H:%M:%S"
)
Expand Down
9 changes: 4 additions & 5 deletions R/coin_history_snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#' @export
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @examplesIf FALSE
#' r <- coin_history_snapshot(
Expand Down Expand Up @@ -85,7 +84,7 @@ coin_history_snapshot <- function(coin_id,
names_to = "vs_currency",
values_to = "price"
) %>%
dplyr::filter(.data$vs_currency %in% vs_currencies)
dplyr::filter(vs_currency %in% vs_currencies)

market_cap <- r$market_data$market_cap %>%
tibble::as_tibble() %>%
Expand All @@ -94,7 +93,7 @@ coin_history_snapshot <- function(coin_id,
names_to = "vs_currency",
values_to = "market_cap"
) %>%
dplyr::filter(.data$vs_currency %in% vs_currencies)
dplyr::filter(vs_currency %in% vs_currencies)

total_volume <- r$market_data$total_volume %>%
tibble::as_tibble() %>%
Expand All @@ -103,7 +102,7 @@ coin_history_snapshot <- function(coin_id,
names_to = "vs_currency",
values_to = "total_volume"
) %>%
dplyr::filter(.data$vs_currency %in% vs_currencies)
dplyr::filter(vs_currency %in% vs_currencies)

result <- dplyr::inner_join(price, market_cap, by = "vs_currency") %>%
dplyr::inner_join(total_volume, by = "vs_currency")
Expand All @@ -114,7 +113,7 @@ coin_history_snapshot <- function(coin_id,
name = r$name,
date = date
), result) %>%
dplyr::arrange(.data$vs_currency)
dplyr::arrange(vs_currency)

is_na <- apply(result, 2, anyNA)

Expand Down
39 changes: 19 additions & 20 deletions R/current_market.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#' @export
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @examplesIf ping()
#' r <- current_market(
Expand Down Expand Up @@ -123,36 +122,36 @@ current_market <- function(coin_ids,
x %>%
tibble::as_tibble() %>%
dplyr::rename(
coin_id = .data$id,
last_updated_at = .data$last_updated
coin_id = id,
last_updated_at = last_updated
) %>%
dplyr::mutate(vs_currency = vs_currency) %>%
dplyr::relocate(.data$vs_currency, .after = .data$name) %>%
dplyr::relocate(.data$last_updated_at, .after = vs_currency) %>%
dplyr::relocate(.data$price_change_percentage_1h_in_currency,
.after = .data$atl_date
dplyr::relocate(vs_currency, .after = name) %>%
dplyr::relocate(last_updated_at, .after = vs_currency) %>%
dplyr::relocate(price_change_percentage_1h_in_currency,
.after = atl_date
) %>%
dplyr::relocate(.data$price_change_percentage_24h_in_currency,
.after = .data$price_change_percentage_1h_in_currency
dplyr::relocate(price_change_percentage_24h_in_currency,
.after = price_change_percentage_1h_in_currency
) %>%
dplyr::relocate(.data$price_change_percentage_7d_in_currency,
.after = .data$price_change_percentage_24h_in_currency
dplyr::relocate(price_change_percentage_7d_in_currency,
.after = price_change_percentage_24h_in_currency
) %>%
dplyr::relocate(.data$price_change_percentage_14d_in_currency,
.after = .data$price_change_percentage_7d_in_currency
dplyr::relocate(price_change_percentage_14d_in_currency,
.after = price_change_percentage_7d_in_currency
) %>%
dplyr::relocate(.data$price_change_percentage_30d_in_currency,
.after = .data$price_change_percentage_14d_in_currency
dplyr::relocate(price_change_percentage_30d_in_currency,
.after = price_change_percentage_14d_in_currency
) %>%
dplyr::relocate(.data$price_change_percentage_200d_in_currency,
.after = .data$price_change_percentage_30d_in_currency
dplyr::relocate(price_change_percentage_200d_in_currency,
.after = price_change_percentage_30d_in_currency
) %>%
dplyr::mutate_at(
.vars = dplyr::vars(tidyselect::contains("date")),
.funs = ~ as.POSIXct(gsub("T", " ", .x),
origin = as.Date("1970-01-01"),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
origin = as.Date("1970-01-01"),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
)
)
}
Expand Down
9 changes: 4 additions & 5 deletions R/current_price.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#' @export
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @examplesIf FALSE
#' r <- current_price(
Expand Down Expand Up @@ -111,14 +110,14 @@ current_price <- function(coin_ids,
vol_24h = vol_24h,
price_percent_change_24h = change_24h,
last_updated_at = as.POSIXct(x$last_updated_at,
origin = as.Date("1970-01-01"),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
origin = as.Date("1970-01-01"),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
)
)
}) %>%
dplyr::bind_rows(.id = "coin_id") %>%
dplyr::arrange(.data$coin_id)
dplyr::arrange(coin_id)

return(result)
}
5 changes: 2 additions & 3 deletions R/exchange_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#' returns nothing (`NULL`).
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @export
#'
Expand Down Expand Up @@ -65,8 +64,8 @@ exchange_rate <- function(currency = NULL,
result <- r %>%
lapply(tibble::as_tibble) %>%
dplyr::bind_rows() %>%
dplyr::select(-.data$unit) %>%
dplyr::rename(price_in_btc = .data$value)
dplyr::select(-unit) %>%
dplyr::rename(price_in_btc = value)

return(
dplyr::bind_cols(
Expand Down
5 changes: 2 additions & 3 deletions R/supported_exchanges.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#' @export
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @examplesIf FALSE
#' r <- supported_exchanges()
Expand Down Expand Up @@ -68,8 +67,8 @@ supported_exchanges <- function(max_attempts = 3) {

result <- tibble::as_tibble(x) %>%
dplyr::rename(
exchange_id = .data$id,
trading_volume_24h_btc = .data$trade_volume_24h_btc
exchange_id = id,
trading_volume_24h_btc = trade_volume_24h_btc
)

return(result)
Expand Down
8 changes: 2 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ knitr::opts_chunk$set(
[![CRAN status](https://www.r-pkg.org/badges/version/geckor)](https://cran.r-project.org/package=geckor)
[![Codecov test coverage](https://codecov.io/gh/next-game-solutions/geckor/branch/main/graph/badge.svg)](https://codecov.io/gh/next-game-solutions/geckor?branch=main)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/geckor)](https://cran.r-project.org/package=geckor)

<!-- badges: end -->

`geckor` is an R client for the _free_ version of the [CoinGecko API](https://www.coingecko.com/en/api#explore-api). This package implements several endpoints offered by that API, allowing users to collect the current and historical market data on thousands of cryptocurrencies from hundreds of exchanges. Results are returned in a tabular form (as [tibbles](https://tibble.tidyverse.org/)), ready for any downstream analyses.

## Installation

A stable version of the package can be installed from [CRAN](https://CRAN.R-project.org/package=geckor) the usual way:
As of v0.3.0, `geckor` is no longer published on CRAN.

``` r
install.packages("geckor")
```

To install the development version from GitHub, use the following command(s):
To install the package from GitHub, use the following command(s):

``` r
# install.packages("devtools")
Expand Down
76 changes: 34 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ status](https://www.r-pkg.org/badges/version/geckor)](https://cran.r-project.org
coverage](https://codecov.io/gh/next-game-solutions/geckor/branch/main/graph/badge.svg)](https://codecov.io/gh/next-game-solutions/geckor?branch=main)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN
downloads](https://cranlogs.r-pkg.org/badges/grand-total/geckor)](https://cran.r-project.org/package=geckor)

<!-- badges: end -->

Expand All @@ -27,15 +25,9 @@ any downstream analyses.

## Installation

A stable version of the package can be installed from
[CRAN](https://CRAN.R-project.org/package=geckor) the usual way:

``` r
install.packages("geckor")
```
As of v0.3.0, `geckor` is no longer published on CRAN.

To install the development version from GitHub, use the following
command(s):
To install the package from GitHub, use the following command(s):

``` r
# install.packages("devtools")
Expand Down Expand Up @@ -72,15 +64,15 @@ current_price(
#> # A tibble: 9 × 7
#> coin_id price vs_currency market_cap vol_24h price…¹ last_updated_at
#> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dttm>
#> 1 cardano 0.361 usd 12689075561. 3.15e8 5.17 2023-03-28 19:23:43
#> 2 cardano 0.333 eur 11699962121. 2.90e8 4.72 2023-03-28 19:23:43
#> 3 cardano 0.293 gbp 10284203893. 2.55e8 4.72 2023-03-28 19:23:43
#> 4 polkadot 6.06 usd 7371780769. 1.51e8 3.10 2023-03-28 19:23:40
#> 5 polkadot 5.59 eur 6797150458. 1.40e8 2.64 2023-03-28 19:23:40
#> 6 polkadot 4.91 gbp 5974658763. 1.23e8 2.66 2023-03-28 19:23:40
#> 7 tron 0.0641 usd 5851571758. 3.52e8 0.874 2023-03-28 19:23:36
#> 8 tron 0.0591 eur 5396319475. 3.24e8 0.425 2023-03-28 19:23:36
#> 9 tron 0.0520 gbp 4741938206. 2.85e8 0.448 2023-03-28 19:23:36
#> 1 cardano 0.451 usd 15837697908. 5.56e8 3.39 2023-04-15 21:07:54
#> 2 cardano 0.407 eur 14264982830. 5.01e8 2.56 2023-04-15 21:07:54
#> 3 cardano 0.363 gbp 12748697470. 4.48e8 3.40 2023-04-15 21:07:54
#> 4 polkadot 6.77 usd 8267452378. 1.96e8 0.466 2023-04-15 21:07:59
#> 5 polkadot 6.09 eur 7446477822. 1.76e8 -0.341 2023-04-15 21:07:59
#> 6 polkadot 5.45 gbp 6654960199. 1.58e8 0.475 2023-04-15 21:07:59
#> 7 tron 0.0661 usd 6004155496. 2.71e8 -0.473 2023-04-15 21:07:55
#> 8 tron 0.0595 eur 5407930847. 2.44e8 -1.36 2023-04-15 21:07:55
#> 9 tron 0.0532 gbp 4833099004. 2.18e8 -0.473 2023-04-15 21:07:55
#> # … with abbreviated variable name ¹​price_percent_change_24h

# Get a more comprehensive view of the current Cardano, Tron, and
Expand All @@ -96,34 +88,34 @@ current_market(
#> $ symbol <chr> "ada", "dot", "trx"
#> $ name <chr> "Cardano", "Polkadot", "TRON"
#> $ vs_currency <chr> "usd", "usd", "usd"
#> $ last_updated_at <dttm> 2023-03-28 19:23:43, 2023-03-…
#> $ current_price <dbl> 0.361329, 6.060000, 0.064135
#> $ market_cap <dbl> 12689075561, 7371780769, 5851
#> $ market_cap_rank <int> 7, 13, 16
#> $ fully_diluted_valuation <dbl> 16293567152, 7862074556, 5851
#> $ total_volume <int> 314844487, 151291225, 3516209
#> $ high_24h <dbl> 0.362596, 6.060000, 0.064538
#> $ low_24h <dbl> 0.340777, 5.810000, 0.063214
#> $ price_change_24h <dbl> 0.01777009, 0.18186900, 0.00
#> $ price_change_percentage_24h <dbl> 5.17235, 3.09588, 0.87356
#> $ market_cap_change_24h <int> 649457410, 226364606, 58443269
#> $ market_cap_change_percentage_24h <dbl> 5.39434, 3.16797, 1.00884
#> $ circulating_supply <dbl> 35045020830, 1216721335, 9106
#> $ total_supply <dbl> 45000000000, 1297644918, 9106
#> $ last_updated_at <dttm> 2023-04-15 21:07:54, 2023-04-…
#> $ current_price <dbl> 0.451337, 6.770000, 0.066087
#> $ market_cap <dbl> 15837697908, 8267452378, 6004
#> $ market_cap_rank <int> 7, 12, 17
#> $ fully_diluted_valuation <dbl> 20336595299, 8815092886, 6004
#> $ total_volume <int> 555995806, 195933965, 2711042
#> $ high_24h <dbl> 0.461386, 6.860000, 0.066406
#> $ low_24h <dbl> 0.433541, 6.650000, 0.065706
#> $ price_change_24h <dbl> 0.0148089400, 0.0314165600,
#> $ price_change_percentage_24h <dbl> 3.39244, 0.46648, -0.47265
#> $ market_cap_change_24h <dbl> 538138558, 42175955, -26009412
#> $ market_cap_change_percentage_24h <dbl> 3.51735, 0.51276, -0.43132
#> $ circulating_supply <dbl> 35045020830, 1222024275, 9081
#> $ total_supply <dbl> 45000000000, 1302971823, 9081
#> $ max_supply <dbl> 4.5e+10, NA, NA
#> $ ath <dbl> 3.090000, 54.980000, 0.231673
#> $ ath_change_percentage <dbl> -88.27058, -88.97655, -72.260
#> $ ath_change_percentage <dbl> -85.35035, -87.69465, -71.429
#> $ ath_date <dttm> 2021-09-02 06:00:10, 2021-11-…
#> $ atl <dbl> 0.01925275, 2.70000000, 0.001…
#> $ atl_change_percentage <dbl> 1780.6496, 124.6856, 3461.6535
#> $ atl_change_percentage <dbl> 2248.8684, 150.8139, 3568.3223
#> $ atl_date <dttm> 2020-03-13 02:22:55, 2020-08-…
#> $ price_change_percentage_1h_in_currency <dbl> 0.9341879, 1.8463548, 0.14733
#> $ price_change_percentage_24h_in_currency <dbl> 5.1723483, 3.0958767, 0.87355
#> $ price_change_percentage_7d_in_currency <dbl> 7.964421, -1.040912, -2.327616
#> $ price_change_percentage_14d_in_currency <dbl> 5.0559277, -0.7807645, -4.477
#> $ price_change_percentage_30d_in_currency <dbl> -0.3644916, -7.3714292, -5.62
#> $ price_change_percentage_200d_in_currency <dbl> -24.728783, -18.104854, 4.645…
#> $ price_change_percentage_1y_in_currency <dbl> -69.35711, -72.94615, -6.99422
#> $ price_change_percentage_1h_in_currency <dbl> 0.1800281, -0.3640175, -0.185
#> $ price_change_percentage_24h_in_currency <dbl> 3.3924391, 0.4664765, -0.4726
#> $ price_change_percentage_7d_in_currency <dbl> 17.4481845, 9.3653120, -0.163…
#> $ price_change_percentage_14d_in_currency <dbl> 12.9854039, 6.6405967, 0.6041
#> $ price_change_percentage_30d_in_currency <dbl> 38.6393053, 14.8147770, 0.665
#> $ price_change_percentage_200d_in_currency <dbl> 1.022590, 3.502597, 11.015018
#> $ price_change_percentage_1y_in_currency <dbl> -51.643189, -62.314239, 9.762…

# Collect all historical data on the price of Cardano (expressed in EUR),
# and plot the result:
Expand Down
Loading

0 comments on commit 40955da

Please sign in to comment.