In the last post, I have explained, how to use AzureML package with the aim of exploration of Azure ML studio experiments and datasets inside R studio environment. moreover how we can use this package to upload a dataset from R studio into Azure ML has been shown.
In this post, I am going to show you how we can create a function inside R and then publish an API from it.
imagine we have a function for the adding two number in R studio as below there
add <- function(x, y) { x + y }
is a function of the AzureML package “publishWebService” that able to publish function in R studio into Azure Ml as API.
api <- publishWebService( ws, fun = add, name = "AzureML_Add_Function", inputSchema = list( x = "numeric", y = "numeric" ), outputSchema = list( ans = "numeric" ))
this function gets :
1- ws, information about the web service that has been explained in the last post,
2-fnn, the name of the function
3- name, the name that we want to display it in the Azure environment
4- input dataset, as a list
5-output dataset as a list
NOTE: when you run the code, it may ask you to install zip, you able to handle the error by downloading one version of Rtools into your machine from https://cran.r-project.org/bin/windows/Rtools/
Just go and check the web service in Azure ML, you will see the function in top of the list (see below)
you able to test it
Moreover, you able to share the API key and URL with any other application, language to have smarter application.