R Tutorial – Connecting to STEEMSQL


R-studio R Tutorial - Connecting to STEEMSQL database mssql R programming SteemIt

R-studio

R is suitable for data analysis and we can use R to do machine learning after mining the data from STEEMSQL. The first step is to connect to STEEMSQL, and let’s do it.

Step 1 – Install the MS SQL package

@arcange ‘s STEEMSQL is a Microsoft SQL Server, thus we need R to be able to handle the MSSQL connection via the RODBC library. To install the connector in R, run the following command

install.packages("RODBC")

Step 2 – Reference the RODBC library

After RODBC is installed, you first need to reference it e.g. in R script.

library(RODBC)

Step 3 – Connect via odbcDriverConnect method

Like other programming language, RODBC has a DB-connect method, i.e. odbcDriverConnect which needs to be customised to the following according to STEEMSQL:

conn <- odbcDriverConnect("Driver=SQL Server Native Client 11.0;Server=sql.steemsql.com;Database=DBSteem;Uid=steemit;Pwd=steemit")

Upon success, the connection is stored in conn.

Step 4 – Run the SQL query

This is easy to understand, first parameter is the db connection and the second parameter is the actual SQL statement!

sqlQuery(conn, str_c("select voting_power from Accounts where name='justyy'"))

Demo R Function – Get Current Voting Power

Let’s wrap this up!

library(RODBC)
library(stringr)

getvp = function(id) {
  conn <- odbcDriverConnect("Driver=SQL Server Native Client 11.0;Server=sql.steemsql.com;Database=DBSteem;Uid=steemit;Pwd=steemit")
  x <- sqlQuery(conn, str_c("select voting_power from Accounts where name='", id, "'"))
  close(conn)
  return(x)
}
R-demo-steemsql-get-voting-power R Tutorial - Connecting to STEEMSQL database mssql R programming SteemIt

R-demo-steemsql-get-voting-power

You may also like: R 教程之 怎么样连接到 STEEMSQL 数据库

R Tutorial

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
595 words
Last Post: SteemIt: Javascript Function to Get Original Post from Comment's PermLink
Next Post: R Tutorial - How rich is SteemIt Wechat Group?

The Permanent URL is: R Tutorial – Connecting to STEEMSQL

2 Comments

  1. ben

Leave a Reply