You are viewing a single comment's thread from:

RE: steemRdata V0.3 - New Features & Bug Fixes

in #utopian-io6 years ago

Good to hear the library has a progress. Finally installed RStudio to my mac to play with it. :)

  if(missing(node)){
    node = "https://api.steemit.com"
  }

I see this code is repeated across all functions. Isn't it possible to set a default NODE as a variable? Or do this check in a encapsulated way to prevent repeats?

Example:

default_node <- "https://api.steemit.com"

send_http_request <- function(query, node) {
  if(missing(node)){
    node = "https://api.steemit.com"
  }

  print(node)
  'make the HTTP request'
  r <- httr::POST(node, body = query)
  data <- httr::content(r, "parsed", "application/json")
  return(data$result)
}


get_dynamic_global_properties <- function(node){
  query <- '{"jsonrpc":"2.0", "method":"database_api.get_dynamic_global_properties", "id":1}'
  data <- send_http_request(query, node)
  return(data)
}

get_account_count <- function(node) {
  query <- '{"jsonrpc":"2.0", "method":"condenser_api.get_account_count", "params":[], "id":1}'
  data <- send_http_request(query, node)
  return(data)
}

Now, If I don't enter the node, default will be https://api.steemit.com.

> get_account_count()
[1] "https://api.steemit.com"
[1] 1102010

If I enter the node,

> get_account_count(node="https://appbase.buildteam.io")
[1] "https://appbase.buildteam.io"
[1] 1102010

Not a R expert, Even though I read it a lot in the past, I don't have much experience so these suggestion may not make any sense at all, but these are my 2 cents. :)


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

Sort:  

Finally installed RStudio to my mac to play with it. :)
Awesome! Just so you know it is quite easy to call python functions from within R, you can get the best of both worlds.

I will have a think about the best way of implementing your suggestion for an R package. R is a little quirky as far as global variables in packages are concerned but your right, there is a lot of repetition in the code and it can certainly be cleaned up.

Thank you for your review, @emrebeyler!

So far this week you've reviewed 5 contributions. Keep up the good work!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63811.50
ETH 2617.28
USDT 1.00
SBD 2.77