<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/azurer-r-packages-to-control-azure-services/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.revolutionanalytics.com/2018/11/azurer-intro.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p><em>by Hong Ooi, senior data scientist, Microsoft Azure</em></p>
<p>This post is to announce a new family of packages we have developed as part of the <a rel="nofollow" href="https://cloudyr.github.io/packages/index.html" target="_blank">CloudyR</a> project for talking to Azure from R: <a rel="nofollow" href="https://github.com/cloudyr/AzureRMR" target="_blank">AzureR</a>.</p>
<p>As background, some of you may remember the <a rel="nofollow" href="https://blog.revolutionanalytics.com/2016/12/azuresmr.html" target="_blank">AzureSMR</a> package, which was written a few years back as an R interface to Azure. AzureSMR was very successful and gained a significant number of users, but it was never meant to be maintainable in the long term. As more features were added it became more unwieldy until its design limitations became impossible to ignore.</p>
<p>The AzureR family is a refactoring/rewrite of AzureSMR that aims to fix the earlier package's shortcomings.</p>
<p>The core package of the family is <a rel="nofollow" href="https://github.com/cloudyr/AzureRMR" target="_blank"><strong>AzureRMR</strong></a>, which provides a lightweight yet powerful interface to <a rel="nofollow" href="https://docs.microsoft.com/azure/azure-resource-manager/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">Azure Resource Manager</a>. It handles authentication (including automatically renewing when a session token expires), managing resource groups, and working with individual resources and templates. It also calls the Resource Manager <a rel="nofollow" href="https://docs.microsoft.com/en-us/rest/api/resources" target="_blank">REST API</a> directly, so you don't need to have PowerShell or Python installed; it depends only on commonly used R packages like httr, jsonlite and R6.</p>
<p>Here's what some code using AzureRMR looks like. Note that it uses <a rel="nofollow" href="https://blog.revolutionanalytics.com/2017/07/the-r6-class-system.html" target="_blank">R6 classes</a> to represent Azure objects, hence the use of $ to call methods.</p>
<div>
<pre>library(AzureRMR)

az <span>&lt;-</span> az_rm<span>$</span>new(tenant<span>=</span><span>&quot;{tenant_id}&quot;</span>,
    app<span>=</span><span>&quot;{app_id}&quot;</span>,
    password<span>=</span><span>&quot;{password}&quot;</span>)

<span># get a subscription and resource group</span>
sub <span>&lt;-</span> az<span>$</span>get_subscription(<span>&quot;{subscription_id}&quot;</span>)
rg <span>&lt;-</span> sub<span>$</span>get_resource_group(<span>&quot;rgName&quot;</span>)

<span># get a resource (storage account)</span>
stor <span>&lt;-</span> rg<span>$</span>get_resource(type<span>=</span><span>&quot;Microsoft.Storage/storageAccounts&quot;</span>,
    name<span>=</span><span>&quot;myStorage&quot;</span>)

<span># method chaining works too</span>
stor <span>&lt;-</span> az<span>$</span>
    get_subscription(<span>&quot;{subscription_id}&quot;</span>)<span>$</span>
    get_resource_group(<span>&quot;rgName&quot;</span>)<span>$</span>
    get_resource(type<span>=</span><span>&quot;Microsoft.Storage/storageAccounts&quot;</span>,
        name<span>=</span><span>&quot;myStorage&quot;</span>)

<span># create a new resource group and resource</span>
rg2 <span>&lt;-</span> sub<span>$</span>create_resource_group(<span>&quot;newRgName&quot;</span>, location<span>=</span><span>&quot;westus&quot;</span>)

stor2 <span>&lt;-</span> rg2<span>$</span>create_resource(type<span>=</span><span>&quot;Microsoft.Storage/storageAccounts&quot;</span>,
    name<span>=</span><span>&quot;myNewStorage&quot;</span>,
    kind<span>=</span><span>&quot;Storage&quot;</span>, 
    sku<span>=</span>list(name<span>=</span><span>&quot;Standard_LRS&quot;</span>, tier<span>=</span><span>&quot;Standard&quot;</span>))

<span># delete them</span>
stor2<span>$</span>delete(confirm<span>=</span><span>FALSE</span>)
rg2<span>$</span>delete(confirm<span>=</span><span>FALSE</span>)
</pre>
</div>
<p>You can use AzureRMR to work with any Azure service, but a key idea behind it is that it's <em>extensible</em>: you can write new packages that provide extra functionality relevant to specific Azure offerings. This deals with one of the main shortcomings of AzureSMR: as a monolithic package, it became steadily more difficult to add new features as time went on. The packages that extend AzureRMR in this way constitute the AzureR family.</p>
<p>Currently, the AzureR family includes the following packages:</p>
<ul>
<li><a rel="nofollow" href="https://github.com/cloudyr/AzureVM" target="_blank"><strong>AzureVM</strong></a> is a package for working with virtual machines and virtual machine clusters. It allows you to easily deploy, manage and delete a VM from R. A number of templates are provided based on the <a rel="nofollow" href="https://docs.microsoft.com/azure/machine-learning/data-science-virtual-machine/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">Data Science Virtual Machine</a>, or you can also supply your own template.</li>
<li><a rel="nofollow" href="https://github.com/cloudyr/AzureStor" target="_blank"><strong>AzureStor</strong></a> is a package for working with <a rel="nofollow" href="https://docs.microsoft.com/azure/storage/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">storage accounts</a>. In addition to a Resource Manager interface for creating and deleting storage accounts, it also provides a client interface for working with the storage itself. You can upload and download files and blobs, list file shares and containers, list files within a share, and so on. It supports authenticated access to storage via either a key or a shared access signature (SAS).</li>
<li><a rel="nofollow" href="https://github.com/cloudyr/AzureContainers" target="_blank"><strong>AzureContainers</strong></a> is a package for working with containers in Azure: specifically, it provides an interface to <a rel="nofollow" href="https://docs.microsoft.com/azure/container-instances/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">Azure Container Instances</a>, <a rel="nofollow" href="https://docs.microsoft.com/azure/container-registry/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">Azure Container Registry</a> and <a rel="nofollow" href="https://docs.microsoft.com/azure/aks/?WT.mc_id=Revolutions-blog-davidsmi" target="_blank">Azure Kubernetes Service</a>. You can easily create an image, push it to an ACR repo, and then deploy it as a service to AKS. It also provides lightweight shells to docker, kubectl and helm (assuming these are installed).</li>
</ul>
<p>I'll be writing future blog posts to describe each of these in further detail.</p>
<p>All the AzureR packages are part of the <a rel="nofollow" href="https://cloudyr.github.io/" target="_blank">CloudyR Project</a>, which aims to make R work better with cloud services of all kinds. They are not (yet) on CRAN, but you can obtain them with <code>devtools::install_github</code>.</p>
<div>
<pre>library(devtools)
install_github(<span>&quot;cloudyr/AzureRMR&quot;</span>)
install_github(<span>&quot;cloudyr/AzureVM&quot;</span>)
install_github(<span>&quot;cloudyr/AzureStor&quot;</span>)
install_github(<span>&quot;cloudyr/AzureContainers&quot;</span>)
</pre>
</div>
<p>If you use Azure with R, I hope you'll find these packages to be of significant benefit to your workflow. If you have any questions or comments, please contact me at <code>hongooi@microsoft.com</code>.</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.revolutionanalytics.com/2018/11/azurer-intro.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/WzbdVaWEdqQ" height="1"></a></div>