<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/introducing-the-azuresmr-package-manage-azure-services-from-your-r-session/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2016/12/azuresmr.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 Alan Weaver, Advanced Analytics Specialist at Microsoft</em></p>
<p>Very often data scientists and analysts require access to back-end resources on Azure. For example, they may need to start a virtual machine or resize a Hadoop cluster. This typically requires making a request to the IT department and patiently waiting. </p>
<p><a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR">AzureSMR</a> is a simple R package that enables those users to do many of those operations themselves.</p>
<p>It’s very easy to script commonly-used functions which can be run without having to navigate the portal or wizards. AzureSMR uses the <a target="_blank" rel="nofollow" href="https://docs.microsoft.com/en-us/rest/api/">Azure Systems Management API</a> and leverages standard packages such as <a target="_blank" rel="nofollow" href="https://mran.microsoft.com/package/httr/">httr</a>, so it can easily run in any R session (you don't need Microsoft R Server).  You can also manage multiple Azure subscriptions from within the same session.</p>
<p>The AzureSMR functions currently addresses the following Azure Services:</p>
<ul>
<li>Azure Blob: List, Read and Write to Blob Services</li>
<li>Azure Resources: List, Create and Delete Azure Resource. Deploy ARM templates.</li>
<li>Azure VM: List, Start and Stop Azure VMs</li>
<li>Azure HDI: List and Scale Azure HDInsight Clusters</li>
<li>Azure Hive: Run Hive queries against a HDInsight Cluster</li>
<li>Azure Spark: List and create Spark jobs/Sessions against a HDInsight Cluster(Livy)</li>
</ul>
<p>For example, here's how you would use the AzureSMR package to find, start and stop an Azure virtual machine:</p>
<div>
<pre>azureListVM(sc, resourceGroup <span>= </span><span>&quot;Analytics&quot;</span>)   <span># LIST VMS</span>
azureStartVM(sc, vmName <span>= </span><span>&quot;MYVM&quot;</span>)              <span># START A VM</span>
azureStopVM(sc, vmName <span>= </span><span>&quot;MYVM&quot;</span>)               <span># STOP A VM</span>
</pre>
</div>
<p>Or, you could spin up a Spark cluster in <a target="_blank" rel="nofollow" href="https://azure.microsoft.com/en-us/services/hdinsight/">HDInsight</a> (though you should choose better passwords!):</p>
<div>
<pre>azureCreateHDI(sc,
  resourceGroup <span>= </span><span>&quot;myResourceGroup&quot;</span>,
  clusterName   <span>=</span> <span>&quot;myhdicluster&quot;</span>,
  location      <span>= </span><span>&quot;northeurope&quot;</span>, 
  storageAcc    <span>=</span> <span>&quot;azuresmrteststorage&quot;</span>, 
  version       <span>= </span><span>&quot;3.5&quot;</span>, 
  sshUser       <span>=</span> <span>&quot;hdiuser&quot;</span>, <br>  sshPassword   <span>=</span> <span>&quot;Password123!!&quot;</span>,
  adminUser     <span>=</span> <span>&quot;admin&quot;</span>, <br>  adminPassword <span>=</span> <span>&quot;Password123!!&quot;<br></span>)
</pre>
</div>
<p>Or create an <a target="_blank" rel="nofollow" href="https://azure.microsoft.com/en-us/services/storage/">Azure Storage</a> account and list and create files:</p>
<div>
<pre>azureCreateStorageAccount(sc, storageAccount <span>= </span><span>&quot;azuresmrteststorage&quot;</span>, <br>                              resourceGroup <span>=</span> <span>&quot;myResourceGroup&quot;</span>)
azureCreateStorageContainer(sc, <span>&quot;opendata&quot;</span>)
azureListStorageContainers(sc, storageAccount <span>=</span> <span>&quot;azuresmrteststorage&quot;</span>, <br>                               resourceGroup <span>=</span><span>&quot;myResourceGroup&quot;</span>)
azurePutBlob(sc, contents<span>=</span>”XXX”, blob <span>=</span> <span>&quot;testdir/testfile.csv&quot;</span>)
azureBlobCD(sc, <span>&quot;/testdir&quot;</span>)
azureBlobLS(sc)
</pre>
</div>
<p>For a detailed list of the available functions and their syntax please refer to the Help pages. A vignette is available to help set up <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR/blob/master/vignettes/Authentication.Rmd">Authentication</a> and there is also a <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR/blob/master/vignettes/tutorial.Rmd">Getting started tutorial</a>.</p>
<p>To get started with the AzureML package, simply use the devtools package to install it from <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR">Github</a>.</p>
<div>
<pre><span>if</span>(<span>!</span>require(<span>&quot;devtools&quot;</span>)) install.packages(<span>&quot;devtools&quot;</span>)
devtools<span>::</span>install_github(<span>&quot;Microsoft/AzureSMR&quot;</span>)
library(AzureSMR)
</pre>
</div>
<p>We welcome your feedback on this package! Contact us via the Github repo, linked below.</p>
<p>Github (Microsoft): <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR">AzureSMR, an R package for managing a selection of Azure resources</a></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="http://blog.revolutionanalytics.com/2016/12/azuresmr.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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/8Q432Rd0ezc"></a></div>