<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: A guide for complete R beginners :- Installing R packages]]></title>
	<link>https://bioinformaticsonline.com/pages/view/21444/a-guide-for-complete-r-beginners-installing-r-packages?</link>
	<atom:link href="https://bioinformaticsonline.com/pages/view/21444/a-guide-for-complete-r-beginners-installing-r-packages?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/pages/view/21444/a-guide-for-complete-r-beginners-installing-r-packages</guid>
	<pubDate>Tue, 24 Feb 2015 20:23:34 -0600</pubDate>
	<link>https://bioinformaticsonline.com/pages/view/21444/a-guide-for-complete-r-beginners-installing-r-packages</link>
	<title><![CDATA[A guide for complete R beginners :- Installing R packages]]></title>
	<description><![CDATA[<p>Part of the reason R has become so popular is the vast array of packages available at the <a href="http://cran.r-project.org/" target="_blank">cran</a> and <a href="http://www.bioconductor.org/" target="_blank">bioconductor</a> repositories. In the last few years, the number of packages has grown <a href="http://blog.revolutionanalytics.com/2010/09/what-can-other-languages-learn-from-r.html" target="_blank">exponentially</a>!</p><p>This is a short post giving steps on how to actually install R packages. Let&rsquo;s suppose you want to install the <a href="http://had.co.nz/ggplot2/" target="_blank">ggplot2</a> package. Well nothing could be easier. We just fire up an R shell and type:<br /><code><br />&gt; install.packages("ggplot2")</code></p><p>In theory the package should just install, however:</p><ul>
<li>if you are using Linux and don&rsquo;t have root access, this command won&rsquo;t work.</li>
<li>you will be asked to select your local mirror, i.e. which server should you use to download the package.</li>
</ul><h4>Installing packages without root access</h4><p>First, you need to designate a directory where you will store the downloaded packages. On my machine, I use the directory <code>/data/Rpackages/</code> After creating a package directory, to install a package we use the command:<br /><code><br />&gt; install.packages("ggplot2"</code><code>, lib="/data/Rpackages/")<br />&gt; library(ggplot2, lib.loc="/data/Rpackages/")<br /></code></p><p>It&rsquo;s a bit of a pain having to type <code>/data/Rpackages/</code> all the time. To avoid this burden,&nbsp; we create a file <code>.Renviron</code> in our home area, and add the line <code>R_LIBS=/data/Rpackages/</code> to it. This means that whenever you start R, the directory <code>/data/Rpackages/</code> is added to the list of places to look for R packages and so:</p><p><code>&gt; install.packages("ggplot2"</code><code>)<br />&gt; library(ggplot2)</code></p><p>just works!</p><h4>Setting the repository</h4><p>Every time you install a R package, you are asked which repository R should use. To set the repository and avoid having to specify this at every package install, simply:</p><ul>
<li>create a file <code>.Rprofile</code> in your home area.</li>
<li>Add the following piece of code to it:</li>
</ul><p><code><br />cat(".Rprofile: Setting UK repositoryn")<br />r = getOption("repos") # hard code the UK repo for CRAN<br />r["CRAN"] = "http://cran.uk.r-project.org"<br />options(repos = r)<br />rm(r)<br /></code></p><p>I found this tip in a stackoverflow <a href="http://stackoverflow.com/questions/1189759/expert-r-users-whats-in-your-rprofile/1189826#1189826" target="_blank">answer </a>.</p>]]></description>
	<dc:creator>Archana Malhotra</dc:creator>
</item>

</channel>
</rss>