0

I am trying to connect to a socket.io data source using R. Specifically I am trying to connect to CoinCap https://github.com/CoinCapDev/CoinCap.io.

I started by trying the websockets package from here but I could not get a connection. Maybe it is not socket.io compliant.

The best example appears to be in this post which asks the same question.

It seems the answer was to create a socket.io server as a middleman and then connect to R.

The problem is that I am not nearly as advanced as jeromefroe and have no experience with sockets or javascript and I have do not understand how the server that he created works or how to build or start it. jeromefroe provides his javascript server code in the post, and I don't know what to do with it.

I am trying to collect data in R and use for analysis. Can somebody help me get the connection running and/or help me set up the sever like jeromefroe did for the connection?

MichaelE
  • 763
  • 8
  • 22
  • isnt it just a REST (http acutally) query? you can just use `httr::GET`. for e.g. `resp <- GET("http://coincap.io/coins"); jsonlite::fromJSON(rawToChar(resp$content))` – chinsoon12 Jan 23 '18 at 07:22
  • Thank you, but I don't understand what that means and how to use it. Installed Node.js as shown here: [link](https://www.youtube.com/watch?v=vnPemSnnJYY) I copied jeromefroe's code to index.html and socket.io.js to a socket.io sub-folder. It appears the site loads but I cannot get further and cannot tell if the script is running. – MichaelE Jan 25 '18 at 21:21

1 Answers1

1

If I understand your question correctly, you are trying to "collect data in R and use for analysis". The website provides the REST URLs and so it is a matter of doing a http GET to retrieve data. An example usage of the httr package as follows. The result retrieved is in json format. Hence, you need jsonlite package to convert into a R data structure.

library(httr)
library(jsonlite)
resp <- httr::GET("http://coincap.io/coins")
jsonlite::fromJSON(rawToChar(resp$content))
chinsoon12
  • 25,005
  • 4
  • 25
  • 35