Reading Package

library(RCurl)
## Loading required package: bitops
#data(iris)
#View(iris)
#names(iris)
iris<-read.csv("C:/Program Files/RStudio/iris2class.csv")
head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
#for input variables
irisInput<-iris[,-5]

MOdel building

library(randomForest)
## randomForest 4.6-12
## Type rfNews() to see new features/changes/bug fixes.
model<-randomForest(Species~.,data=iris,method="class")

Predict function

mypredict<-function(newdata){
  require(randomForest) # we need to load the required packages that are used in traning
  predict(model,newdata,type = "response")
}

Publishing the model into azure

library(AzureML)
## Warning: package 'AzureML' was built under R version 3.3.3
library(devtools)

#NOte : need to install Rtools,set tick at path
#go to azure studio -> settings -> take WORKSPACE ID
#go to azure studio -> settings -> AUTHORIZATION TOKENS -> PRIMARY AUTHORIZATION TOKEN

wsID="9f119c34247a49c393214a9f304c5b89"
wsAuth="d6819252940d4bdca80654cfe6ccb313"

wsobj=workspace(wsID,wsAuth)

iriswebservice<-publishWebService(
                                   wsobj,
                                   fun=mypredict,
                                   name = "iriswebservice",
                                   inputSchema = irisInput
)
## converting `inputSchema` to data frame

It will automatically update in webservice in Azure.

iriswebservice <- updateWebService(
  wsobj,
  fun=mypredict,
  name = "iriswebservice1",
  inputSchema = irisInput,
  serviceId = iriswebservice$WebServiceId   # <<-- Required to update!
)
## converting `inputSchema` to data frame