<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/the-flexibility-of-remote-and-local-r-workspaces/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/01/remote-and-local-r-workspaces.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<div>
<p><em>by Sean Wells, Senior Software Engineer, Microsoft</em></p>
<p>The <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy">mrsdeploy</a> R package facilitates <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy-remoteexec-vignette">Remote Execution</a> and <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy-websrv-vignette">Web Service</a> interactions from your local R IDE command line against a remote <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/microsoft-r/rserver">Microsoft R Server</a> instance. Both core features can be used independently of one another or combined to support different convenient workflows. These different workflows composed together can produce some creative R development and operationalization solutions.</p>
<p><code>mrsdeploy</code> comes bundled with installations of <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/microsoft-r/r-client">Microsoft R Client</a> and <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/microsoft-r/rserver">Microsoft R Server</a>.</p>
<p>Before using any <code>mrsdeploy</code> API you must first <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy-intro-vignette#authenticated-access-to-mrsdeploy-operations">authenticate</a> against the R Server and before we authenticate we should become familiar with the different authentication approaches and their supported arguments. Currently, there are two ways to authenticate:</p>
<ul>
<li><code>remoteLogin()</code> using an on premises Active Directory server on your network:</li>
</ul>
<pre><code>remoteLogin(
   endpoint, 
   session = TRUE, 
   diff = TRUE,
   commandline = TRUE, 
   username = NULL,
   password = NULL
)</code></pre>
<ul>
<li><code>remoteLoginAAD()</code> using Azure Active Directory in the cloud:</li>
</ul>
<pre><code>remoteLoginAAD(
   endpoint,
   authuri = NULL,
   tenantid = NULL,
   clientid = NULL,
   resource = NULL,
   session = TRUE,
   diff = TRUE,
   commandline = TRUE
)</code></pre>
<p>Both APIs are equivalent in that they provide the means to authenticate against a Microsoft R Server instance. Take special note of the arguments <code>session</code> and <code>commandline</code>:</p>
<table>
<colgroup>
<col width="19%">
<col width="80%">
</colgroup>
<thead>
<tr>
<th align="left">Argument</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>session</code></td>
<td align="left">If <code>TRUE</code>, create a remote session.</td>
</tr>
<tr>
<td align="left"><code>commandline</code></td>
<td align="left">If <code>TRUE</code>, creates a <em>REMOTE</em> command line in the R console. <em>REMOTE</em> command line is used to interact with the remote R session. Parameter is only valid if session parameter is <em>TRUE</em>.</td>
</tr>
</tbody>
</table>
<p>These two parameters are subtle yet can produce bold context switches from your local R workspace. Depending on their values, you can end up in <strong>one</strong> of <strong>three</strong> post authentication command line states in the R console:</p>
<div>
<h4>State 1 – Remote Command Line</h4>
<p>Authenticate, create a remote R session, and transition to the <em>remote</em> REPL command line. The default prompt <code>REMOTE></code> indicates you are now interacting with your <em>remote</em> R session and are no longer in your local R environment:</p>
<pre><code># Taking the default arguments (session = TRUE, commandline = TRUE)
> remoteLogin(&quot;http://localhost:12800&quot;)
REMOTE></code></pre>
<div>
<img alt src="https://i1.wp.com/cloud.githubusercontent.com/assets/9246638/21606150/77cf4dc2-d162-11e6-83b6-33c64b2befe5.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<p></p>
</div>
<div>
<h4>State 2 – Local Command Line</h4>
<p>Authenticate, create a remote R session, and remain in your local R environment:</p>
<pre><code>> remoteLogin(&quot;http://localhost:12800&quot;, session = TRUE, commandline = FALSE)
></code></pre>
<div>
<img alt src="https://i1.wp.com/cloud.githubusercontent.com/assets/9246638/21606153/7da8e91a-d162-11e6-8f96-dc4a18dfbfb7.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<p></p>
</div>
<div>
<h4>State 3 – Local Command Line <small>No remote session</small></h4>
<p>Authenticate, do <strong>not</strong> create a remote R session, and remain in your local R environment:</p>
<pre><code>> remoteLogin(&quot;http://localhost:12800&quot;, session = FALSE)
></code></pre>
<div>
<img alt src="https://i1.wp.com/cloud.githubusercontent.com/assets/9246638/21606158/81527d7e-d162-11e6-986b-7c85bc8b21ca.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<p></p>
<p>Now that we understand the different authentication scenarios and their arguments we can begin to compose them together with other <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy#remote-execution-functions">supported functions</a>. The <code>mrsdeploy</code> package provides many convenience functions to aid workflow from the R IDE command line. Listed below are a few that deal with context switching between your local and remote sessions post authentication:</p>
<table>
<colgroup>
<col width="19%">
<col width="80%">
</colgroup>
<thead>
<tr>
<th align="left">Argument</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>pause</code></td>
<td align="left">When executed from the remote R session, returns the user to the local <code>></code> command prompt.</td>
</tr>
<tr>
<td align="left"><code>resume</code></td>
<td align="left">When executed from the local R session, returns the user to the <code>REMOTE></code> command prompt, and sets a remote execution context.</td>
</tr>
<tr>
<td align="left"><code>putLocalObject</code></td>
<td align="left">Puts an object from the workspace of the local R session and loads it into the workspace of the remote R session.</td>
</tr>
</tbody>
</table>
<p>See the documentation for a full list of <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy#remote-execution-functions">supported functions</a>.</p>
<p>Expanding on <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2017/01/remote-and-local-r-workspaces.html#state-1---local-command-line">State 1</a> as shown above, here we define an interactive authentication workflow that spans both our local and remote environments.</p>
<p></p>
<p>The same outcome can be achieved with <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2017/01/remote-and-local-r-workspaces.html#state-2---local-command-line">State 2’s</a> authentication workflow as it differs only in the R environment order. Here we start out in the local R session then move to the remote R session.</p>
<p></p>
<p>Finally, <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2017/01/remote-and-local-r-workspaces.html#state-3---local-command-line-no-remote-session">State 3’s</a> workflow demonstrates authentication without a remote R session being created <code>session = FALSE</code>. This is useful if the intention is to only work with the <a target="_blank" rel="nofollow" href="https://msdn.microsoft.com/en-us/microsoft-r/mrsdeploy/mrsdeploy-websrv-vignette">Web Service</a> functionality of the <code>mrsdeploy</code> package. Here we authenticate and remain confined within our local R session in order to publish and consume a service.</p>
<p></p>
<p><strong>Note</strong> Web Service management can only occur locally. Attempting to use the service APIs during remote interaction <code>REMOTE></code> will result in a error.</p>
</div>
<div>
<h3>Feedback</h3>
<p>I am interested in seeing what people build. If you have any feedback on the above approach or the <code>mrsdeploy</code> package in general, please leave a comment below.</p>
<p>Happy New Year!</p>
</div>
</div>
</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/01/remote-and-local-r-workspaces.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/p3PWCidUvbU"></a></div>