How to connect to a socket.io from R? - r

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?

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))

Related

How to Access SAS Server with IOM Protocol in R

I'm trying to read in SAS data into R similarly to this quick tutorial here: https://josezea.wordpress.com/2019/05/02/connect-sas-server-from-r/
The issue is that the server I'm trying to connect to uses an IOM protocol, which doesn't seem to be supported in the RCurl package. Does anyone have any suggestions to reading data from a SAS Server with these protocols in R? It can be reading from a file pathway or a library, either works for my scenario. Thanks!
Below is the code I attempted to run in R:
library(RCurl)
library(haven)
protocol <- "IOM"
server <- "server.com:5555"
userpwd <- "username:password"
sasfileRoute <- "/path_to_data/bonus_schedule.sas7bdat"
## Read Data as data frame
url <- paste0(protocol, "://", server, sasfileRoute)
binary_sasdata <- getBinaryURL(url = url, userpwd=userpwd)
df_data = read_sas(binary_sasdata)
I think you're misunderstanding what the linked page does. It shows how to use R to read in a SAS dataset - but not to connect to SAS.
SAS datasets are usually stored as .sas7bdat files. You should connect via SFTP or network share or similar to access datasets; this won't work if the datasets are stored in a LASR server or other in-memory location of course.
If you need to connect to SAS itself (to execute code or to access in-memory data), you can do so if the SAS server is a SAS Viya server. See R SWAT for more information on that; it uses SAS's APIs to do what you need.
Otherwise, you will have to run the SAS executable from inside R (if you have access to that version of SAS), or have a SAS user export your data for you from inside SAS. I am not familiar with a way to connect to SAS 9 via R directly, and the link in comments seems out of date (CRAN at least doesn't seem to have that package any more).
SASPy does allow Python to do something similar with SAS 9.4, so perhaps that's a better route if you have SAS 9.4.
IOM is a SAS protocol used by its Integration Technologies product. Instead of IOM, find the network path to the file and use it. See resources using IOM (C#, Java, PowerShell, etc.) on the SAS website. Usually, IOM is used for code submission and SAS object management.

I need to get connected with MS-SQL by using dplyr R package

I am running MS-SQL Server2008 R2 under the MS SQL Server Management Studio. I need to use "dplyr" R-project package and MS-SQL. I got some information about how to do it using "RSQLServer" package at https://github.com/imanuelcostigan/RSQLServer but I have not been able to get it done so far.
I am trying to get the solution for both cases as most Google stuff recommend about it:
Case 1: playing around with the sql.yaml file.
I tried but it did not work in my case. Anyway, I am still trying this solution but I am surrounded and my guess is I will lose very soon.
Case 2: writing the "AW" inside the connection script. [This is the solution that I would like to get done first]
I mean, doing this:
library(dplyr)
conDplyr <- RSQLServer::src_sqlserver(server="local", type="sqlserver", user="HA", port: "1433", database = "MydataOne")
I do not include "password" because I do not use password in my MS SQL configuration. I consider port "1433" here but my MS-SQL configuration does not have any specific assigned port. It gets one by the time it gets connected). I think this could be some of the problems. I do not know!

Execute R Script on AWS via API

I have an R package that I would like to host through Amazon Web Services that will be accessible via an API. The script should take a couple of input values and return the R output in json format. Also, the API should be able to handle multiple requests simultaneously.
So for example, call http://sampleapi.com/?location=USA?state=Florida. That would then run the R package and return the output data to the calling application.
Has anyone done this before or know of resources you can point me to that would explain how to do so? Thanks!
Thanks for all the suggestions. I decided to use Ruby for the API with the rinruby and rails-api gems and will host that through AWS Elastic Beanstalk. See this question for how I am setting it up - Ruby API - Accept parameters and execute script

download data from Graphite using Python

I am a beginner so please be kind. I want to download CPU utilization rate from from some VMs installed on a server. The server has Graphite installed. I installed the Python graphite-api and I have the server connection details. How do I make the REST api call to start pulling the data ?
Use the requests package:
>>> r = requests.get('https://your_graphite_host.com/render?target=app.numUsers&format=json', auth=('user', 'pass'))
>>> r.json() # this will give your the JSON file with the data
Keep in mind that you will have to replace app.numUsers with the appropriate metric name. You can also request other formats and time ranges, see the graphite-api docs.

oauth flickr api using httr to retrieve token

I would like to use httr to link up/upload my R image outputs to flickr, but am having difficulty with the initial stages where i need to authenticate myself using OAuth 1.0.
I previously created an app by going to the following link http://www.flickr.com/services/apps/create/apply/
and then got a secret and key string for that app...
I then used it in the httr package function to get a token but to no avail. I have been trying to use the provided documentation on this link http://www.flickr.com/services/api/auth.oauth.html to help out but, I am struggling...
The following is the code I used.
flickr.app <- oauth_app("flickr",key="xxxxxx", secret="xxxxxxxx")
flickr.urls <- oauth_endpoint(request="http://www.flickr.com/services/oauth/request_token",
authorize="http://www.flickr.com/services/oauth/authorize",
access="http://www.flickr.com/services/oauth/access_token")
flickr.token <- oauth1.0_token(flickr.urls,flickr.app)
from which i get the error message
Error: http client error (400)
Not too sure where to go from here...any help would be much appreciated.
N.B. Also I recognise that due to the nature of setting up api links, that there are secrets , api-keys, logins and passwords that need to be kept secret etc, but it does not take long to set up a dummy flickr account from www.flickr.com , to be able to reproduce the problem...in my opinion...perhaps others could try setting one up and letting me know if they got similar issues, and potential methods to work around the situation?
I have never used the httr library, but I recently (as of yesterday) just finished writing from scratch Objective-C code to access Flickr. The biggest pain point for me was figuring out how to correctly encode the signature. I don't know the httr library well enough, but if I had to guess my guess would be that it is not encoding the signature properly.
If you read through this: http://www.flickr.com/services/api/auth.oauth.html
You will find very detailed instructions on how to authorize with Flickr - it was useful to me because I wrote the code in Objective C from scratch. Might be less useful to you unless you are able to debug through the httr source and figure out if it is doing things exactly as Flickr expects.

Resources