<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/azuredsvm-a-new-r-package-for-elastic-use-of-the-azure-data-science-virtual-machine/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/05/azuredsvm-a-new-r-package-for-elastic-use-of-the-azure-data-science-virtual-machine.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 Le Zhang (Data Scientist, Microsoft) and Graham Williams (Director of Data Science, Microsoft)</em></p>
<p>The Azure <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2017/05/aka.ms/dsvm">Data Science Virtual Machine</a> (DSVM) is a curated VM which provides commonly-used tools and software for data science and machine learning, pre-installed. <a target="_blank" rel="nofollow" href="https://github.com/Azure/AzureDSVM">AzureDSVM</a> is a new R package that enables seamless interaction with the DSVM from a local R session, by providing functions for the following tasks:</p>
<ol>
<li>Deployment, deallocation, deletion of one or multiple DSVMs;</li>
<li>Remote execution of local R scripts: <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/scaler/scaler#compute-context-functions">compute contexts</a> available in Microsoft R Server can be enabled for enhanced computation efficiency for either a single DSVM or a cluster of DSVMs;</li>
<li>Retrieval of cost consumption and total expense spent on using DSVM(s).</li>
</ol>
<p>AzureDSVM is built upon the <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR">AzureSMR</a> package and depends on the same set of R packages such as httr, jsonlite, etc. It requires the same <a target="_blank" rel="nofollow" href="https://github.com/Microsoft/AzureSMR/blob/master/vignettes/Authentication.Rmd">initial set up</a> on Azure Active Directory (for authentication).</p>
<p>To install AzureDSVM with devtools package:</p>
<pre>library(devtools)
devtools::install_github(&quot;Azure/AzureDSVM&quot;)
library(&quot;AzureDSVM&quot;)
</pre>
<p>When deploying a Data Science Virtual Machine, the machine name, size, OS type, etc. must be specified. AzureDSVM supports DSVMs on Ubuntu, CentOS, Windows, and Windows with the <a target="_blank" rel="nofollow" href="https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft-ads.dsvm-deep-learning">Deep Learning Toolkit</a> (on GPU-class instances). For example, the following code fires up a D4 v2 Ubuntu DSVM located in South East Asia:</p>
<pre>deployDSVM(context, 
           resource.group=&quot;example&quot;,
           location=&quot;southeastasia&quot;,
           size=&quot;Standard_D4_v2&quot;,
           os=&quot;Ubuntu&quot;,
           hostname=&quot;mydsvm&quot;,
           username=&quot;myname&quot;,
           pubkey=&quot;pubkey&quot;)
</pre>
<p>where <code>context</code> is an <code>azureActiveContext</code> object created by <code>AzureSMR::createAzureContext()</code> function that encapsulates credentials (Tenant ID, Client ID, etc.) for Azure authentication.</p>
<p>In addition to launching a single DSVM, the AzureDSVM package makes it easy to launch a cluster with multiple virtual machines. Multi-deployment supports:</p>
<ol>
<li>creating a collection of independent DSVMs which can be distributed to a group of data scientists for collaborative projects, as well as</li>
<li>clustering a set of connected DSVMs for high-performance computation.</li>
</ol>
<p>To create a cluster of 5 Ubuntu DSVMs with default VM size, use:</p>
<pre>cluster&lt;-deployDSVMCluster(context, 
                           resource.group=RG, 
                           location=&quot;southeastasia&quot;, 
                           hostnames=&quot;mydsvm&quot;,
                           usernames=&quot;myname&quot;, 
                           pubkeys=&quot;pubkey&quot;,
                           count=5)
</pre>
<p>To execute a local script on remote cluster of DSVMs with a specified Microsoft R Server compute context, use the <code>executeScript</code> function. (NOTE: only Linux-based DSVM instances are supported at the moment as underneath the remote execution is achieved via SSH. Microsoft R Server 9.x allows remote interaction for both Linux and Windows, and more details can be found <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/operationalize/remote-execution">here</a>.) Here, we use the <code><a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/scaler/packagehelp/rxforeachdopar">RxForeachDoPar</a></code> context (as indicated by the <code>compute.context</code> option):</p>
<pre>executeScript(context,
              resource.group=&quot;southeastasia&quot;,
              machines=&quot;dsvm_names_in_the_cluster&quot;,
              remote=&quot;fqdn_of_dsvm_used_as_master&quot;,
              user=&quot;myname&quot;,
              script=&quot;path_to_the_script_for_remote_execution&quot;,
              master=&quot;fqdn_of_dsvm_used_as_master&quot;,
              slaves=&quot;fqdns_of_dsvms_used_as_slaves&quot;,
              compute.context=&quot;clusterParallel&quot;)
</pre>
<p>Information of cost consumption and expense spent on DSVMs can be retrieved with:</p>
<pre>consum&lt;-expenseCalculator(context,
                            instance=&quot;mydsvm&quot;,
                            time.start=&quot;time_stamp_of_starting_point&quot;,
                            time.end=&quot;time_stamp_of_ending_point&quot;,
                            granularity=&quot;Daily&quot;,
                            currency=&quot;USD&quot;,
                            locale=&quot;en-US&quot;,
                            offerId=&quot;offer_id_of_azure_subscription&quot;,
                            region=&quot;southeastasia&quot;)

print(consum)
</pre>
<p>Detailed introductions and tutorials can be found in the AzureDSVM Github <a target="_blank" rel="nofollow" href="https://github.com/Azure/AzureDSVM">repository</a>, linked below.</p>
<p>Github (Azure): <a target="_blank" rel="nofollow" href="https://github.com/Azure/AzureDSVM">AzureDSVM</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/2017/05/azuredsvm-a-new-r-package-for-elastic-use-of-the-azure-data-science-virtual-machine.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/SCfKdrTwoNg"></a></div>