<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/"></div></div><div><a data-url="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/" data-counturl="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/" data-count="horizontal" data-text="How to install R packages on an off-line SQL Server 2016 instance" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2016/05/minicran-sql-server.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>by Andrie de Vries</p>
<p>One of the most exciting features of the forthcoming release of SQL Server 2016 (<a target="_blank" href="https://blogs.technet.microsoft.com/dataplatforminsider/2016/05/02/get-ready-sql-server-2016-coming-on-june-1st/">generally available on June 1</a>, and in <a target="_blank" href="https://www.microsoft.com/en-us/evalcenter/evaluate-sql-server-2016">preview now</a>) is the ability to run R scripts directly in database using <a target="_blank" href="https://msdn.microsoft.com/en-us/library/mt604845.aspx">SQL Server R Services</a>. This means your R code will run directly on the server, as opposed to first extracting the data to your local R session. This has several advantages, for example the data never moves from the server — this offers improved data security and also prevents the latency of downloading data.</p>
<p>This is great news for R users, of course. However, it means the data base administrator (DBA) has to learn a new set of tools to manage an R environment on the SQL Server instance.</p>
<p>One administration task is to ensure that SQL Server instance has all the correct versions of R packages installed.</p>
<h2>Installing packages on a SQL Server machine</h2>
<p>If the SQL Server machine has a connection to the Internet, then this is a trivial task: run <span>install.packages()</span> from an R session. However, many production instances will be on a machine behind a fire wall, with no Internet connectivity at all. In this case, <span>install.packages()</span> will not find the packages on your favourite CRAN mirror.</p>
<p>As an experienced R user, you will know that you can install R packages from a local package zip file. This is correct, and also easy to do. The problem is how to ensure that you have resolved all of the dependencies of the package you need, and to install from local zip files in the correct sequence.</p>
<p>Fortunately there is an easy way to install many packages in a simple operation. The solution is to use the <span>miniCRAN</span> package to create a local repository of the packages you need, then to install from this repository.</p>
<p>You can find an introduction to <span>miniCRAN</span> in the blog posts I wrote in the past, for example:</p>
<ul>
<li><a target="_blank" href="http://blog.revolutionanalytics.com/2014/10/introducing-minicran.html">Introducing miniCRAN: an R package to create a private CRAN repository</a></li>
<li><a target="_blank" href="http://blog.revolutionanalytics.com/2014/07/dependencies-of-popular-r-packages.html">Dependencies of popular R packages</a></li>
<li><a target="_blank" href="http://blog.revolutionanalytics.com/2015/10/using-minicran-in-azure-ml.html">Using miniCRAN in Azure ML</a></li>
</ul>
<p>In summary, <span>miniCRAN</span> enables organisations to maintain a private mirror of CRAN with only a subset of packages that are relevant to them. <span>miniCRAN</span> makes this possible by determining the dependency tree for a given set of packages, then downloading all of the package dependencies.</p>
<h2>Recipe for installing packages</h2>
<p>To be clear, installing your package on a SQL Server instance is a three step process:</p>
<ol>
<li>On a machine with Internet access, create a <span>miniCRAN</span> repository. A <span>miniCRAN</span> repository is a folder structure that contains all the required packages, as well as their dependencies.</li>
<li>Copy the <span>miniCRAN</span> respository to the SQL Server instance. To do this, you will have to use standard system administration tools, for example use FTP or SSH to copy the files to the target machine. The result is that the <span>miniCRAN</span> repository resides on the SQL Server instance.</li>
<li>On the target SQL Server machine, use <span>install.packages()</span>, making sure you point to the local <span>miniCRAN</span> repository.</li>
</ol>
<p>This is all comparatively simple, and the trickiest bit is to ensure you specify all the correct R version settings to a script.</p>
<h2>The code</h2>
<p>The code below contains the complete sequence for managing this process for SQL Server 2016 as the target machine.</p>
<p></div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/"></div></div><div><a data-url="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/" data-counturl="http://www.r-bloggers.com/how-to-install-r-packages-on-an-off-line-sql-server-2016-instance/" data-count="vertical" data-text="How to install R packages on an off-line SQL Server 2016 instance" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<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/05/minicran-sql-server.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://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="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/T1iHwIdjvbY"></a></div>