{"id":22,"date":"2015-04-28T10:39:36","date_gmt":"2015-04-28T09:39:36","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=22"},"modified":"2025-06-30T07:50:45","modified_gmt":"2025-06-30T06:50:45","slug":"packages","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/packages\/","title":{"rendered":"Packages"},"content":{"rendered":"\n<p>Many packages are available for R<sup class='sup-ref-note' id='note-zotero-ref-p22-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p22-r1'>1<\/a><\/sup> and more than 22,000 have been uploaded to the <a href=\"https:\/\/cran.r-project.org\/\" target=\"_blank\" rel=\"noopener\">CRAN website<\/a>. If you are looking for a specific function, it is very likely that somebody has already developed a package and uploaded it to the <a href=\"https:\/\/cran.r-project.org\/\" target=\"_blank\" rel=\"noopener\">CRAN website<\/a>. It can be difficult to know what package to use and often many packages are available for the same task. Some packages (such as for example the survival package) have become the standard whilst others are relatively unknown. An internet search may help to decide on the most appropriate package to use for your task. Always read and download the accompanying reference manual (PDF) from the <a href=\"https:\/\/cran.r-project.org\/\" target=\"_blank\" rel=\"noopener\">CRAN website<\/a> for a complete reference to the package \/ function.<\/p>\n\n\n\n<p><strong>Installation of packages<\/strong><\/p>\n\n\n\n<p>In <a href=\"https:\/\/posit.co\/download\/rstudio-desktop\/\" target=\"_blank\" rel=\"noopener\">RStudio<\/a><sup class='sup-ref-note' id='note-zotero-ref-p22-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p22-r2'>2<\/a><\/sup>, packages can be installed with the package Installer available in the tools menu. After selecting a suitable repository (CRAN is default), just enter the first letter of the package, go down the list, select the package, select install and installation should commence.<\/p>\n\n\n\n<p>RStudio<sup class='sup-ref-note' id='note-zotero-ref-p22-r3-o1'><a class='sup-ref-note' href='#zotero-ref-p22-r3'>3<\/a><\/sup> also has a package installer in the lower right quadrant window.<\/p>\n\n\n\n<p>Alternatively, it is possible to enter the installation command directly into the console. For example to install the survival package<sup class='sup-ref-note' id='note-zotero-ref-p22-r4-o1'><a class='sup-ref-note' href='#zotero-ref-p22-r4'>4<\/a><\/sup> for the creation of survival curves:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">install.packages(\"survival\")<\/span><\/em><\/code><\/pre>\n\n\n\n<p><strong>Using packages<\/strong><\/p>\n\n\n\n<p>In RStudio<sup class='sup-ref-note' id='note-zotero-ref-p22-r5-o1'><a class='sup-ref-note' href='#zotero-ref-p22-r5'>5<\/a><\/sup>, packages can be made available with package manager available in the lower right quadrant (packages tab) by ticking the box of the required package.<\/p>\n\n\n\n<p>Alternatively, the package can be loaded from the console. For example, to load the survival package, type:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(survival)<\/span><\/em><\/code><\/pre>\n\n\n\n<p>in the console.<\/p>\n\n\n\n<p><strong>Getting help<\/strong><\/p>\n\n\n\n<p>The most comprehensive reference to the package can be downloaded from the CRAN website. For example, the PDF file containing the reference manual for&nbsp; survival package can be downloaded from here:<\/p>\n\n\n\n<p><a href=\"http:\/\/cran.r-project.org\/\" target=\"_blank\" rel=\"noopener\">http:\/\/cran.r-project.org\/<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Select <strong>packages<\/strong> from the menu on the left<\/li>\n\n\n\n<li>Select <strong>Table of available package, sorted by name<\/strong> from the main window<\/li>\n\n\n\n<li>From the top of the screen select <strong>S<\/strong><\/li>\n\n\n\n<li>Scroll down to <strong>survival<\/strong> and select it<\/li>\n\n\n\n<li>Under Reference manual: select <strong>survival.pdf<\/strong><br>The reference manual should now available for download.<\/li>\n<\/ul>\n\n\n\n<p>Further help can also be obtained by typing:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>??survival<\/em><\/span><\/code><\/pre>\n\n\n\n<p>in the console. This should open up a help window with further information and examples on how to use the code.<\/p>\n\n\n\n<p><strong>Updating packages<\/strong><\/p>\n\n\n\n<p>Packages are not updated automatically and this has to be done manually. To update a package in R:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">update.packages(\"survival\")<\/span><\/em><\/code><\/pre>\n\n\n\n<p>Or to update all packages:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">update.packages()<\/span><\/em><\/code><\/pre>\n\n\n\n<p>Enter <em><span style=\"color: #ff0000;\">y<\/span><\/em>  for each package that requires updating.<\/p>\n\n\n\n<p>NB: It is not possible to update a package from within itself. <code><\/code><\/p>\n\n\n\n<p><strong>Bioconductor Packages<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.bioconductor.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Bioconductor<\/a> is a software suite in R for the analysis of biological data. This includes the analysis of genomic data. All packages are open source and over 2000 packages are published on the website.<\/p>\n\n\n\n<p>If you try to install a Bioconductor package using the method described above  it will result in an error:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f60404\" class=\"has-inline-color\">install.packages('pwalign')\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2b05f5\" class=\"has-inline-color\">Warning message:\npackage \u2018pwalign\u2019 is not available for this version of R\n\nA version of this package for your version of R might be available elsewhere,\nsee the ideas at\nhttps:\/\/cran.r-project.org\/doc\/manuals\/r-patched\/R-admin.html#Installing-packages <\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Instead, install the package as described on the <a href=\"https:\/\/www.bioconductor.org\/install\/\" target=\"_blank\" rel=\"noreferrer noopener\">Bioconductor website<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f50101\" class=\"has-inline-color\">if (!require(\"BiocManager\", quietly = TRUE))\n+   install.packages(\"BiocManager\")\nBiocManager::install()\n\nBiocManager::install('pwalign')<\/mark><\/em><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Many packages are available for R and more than 22,000 have been uploaded to the CRAN website. If you are looking for a specific function, it is very likely that somebody has already developed a package and uploaded it to the CRAN website. It can be difficult to know what package to use and often [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-22","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":9,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/22\/revisions"}],"predecessor-version":[{"id":4579,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/22\/revisions\/4579"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}