{"id":698,"date":"2015-01-27T18:02:36","date_gmt":"2015-01-28T01:02:36","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=698"},"modified":"2015-01-27T18:02:36","modified_gmt":"2015-01-28T01:02:36","slug":"using-r-installing-packages","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/01\/27\/using-r-installing-packages\/","title":{"rendered":"Using R \u2014 Installing Packages"},"content":{"rendered":"<div class=\"seriesmeta\">This entry is part 2 of 14 in the series <a class=\"series-54\" title=\"Using R\" href=\"http:\/\/mazamascience.com\/WorkingWithData\/?series=using-r\">Using R<\/a><\/div>\n<p>One of the reasons to use R for analysis and visualization is the rich ecosystem of \u2018packages\u2019 contributed by others. In most cases, just as with smartphones, \u201cThere\u2019s a package for that.\u201d If you want to be efficient you need to embrace other people\u2019s work and in the case of R that means installing packages.\u00a0 This post walks you through the basics of package installation and use and gives some tips on workarounds when a package won\u2019t install.<span id=\"more-728\"><\/span><\/p>\n<h2>Simple example<\/h2>\n<p>For the impatient lets start off with a simple example. In this example (on Ubuntu Linux) we\u2019ll run R as the superuser so that packages will be installed in the default location. We will install the \u201c<a href=\"http:\/\/cran.r-project.org\/web\/packages\/geonames\/index.html\" target=\"_blank\" rel=\"noopener\">geonames\u201d<\/a> package and then show off the new functionality we just added.<\/p>\n<div id=\"crayon-54c8259920f3c238525431\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f3c238525431-11\">11<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f3c238525431-12\">12<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f3c238525431-1\" class=\"crayon-line\">$ sudo R &#8211;vanilla<\/div>\n<div id=\"crayon-54c8259920f3c238525431-2\" class=\"crayon-line crayon-striped-line\">&#8230;<\/div>\n<div id=\"crayon-54c8259920f3c238525431-3\" class=\"crayon-line\">&gt; install.packages(c(&#8220;geonames&#8221;))<\/div>\n<div id=\"crayon-54c8259920f3c238525431-4\" class=\"crayon-line crayon-striped-line\">Warning in install.packages(c(&#8220;geonames&#8221;)) :<\/div>\n<div id=\"crayon-54c8259920f3c238525431-5\" class=\"crayon-line\">\u00a0\u00a0argument &#8216;lib&#8217; is missing: using &#8216;\/usr\/local\/lib\/R\/site-library&#8217;<\/div>\n<div id=\"crayon-54c8259920f3c238525431-6\" class=\"crayon-line crayon-striped-line\">&#8212; Please select a CRAN mirror for use in this session &#8212;<\/div>\n<div id=\"crayon-54c8259920f3c238525431-7\" class=\"crayon-line\">Loading Tcl\/Tk interface &#8230;<\/div>\n<div id=\"crayon-54c8259920f3c238525431-8\" class=\"crayon-line crayon-striped-line\">&#8230;<\/div>\n<div id=\"crayon-54c8259920f3c238525431-9\" class=\"crayon-line\">* DONE (geonames)<\/div>\n<div id=\"crayon-54c8259920f3c238525431-10\" class=\"crayon-line crayon-striped-line\"><\/div>\n<div id=\"crayon-54c8259920f3c238525431-11\" class=\"crayon-line\">The downloaded packages are in<\/div>\n<div id=\"crayon-54c8259920f3c238525431-12\" class=\"crayon-line crayon-striped-line\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/tmp\/Rtmp3FziH3\/downloaded_packages<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If you don\u2019t run R as superuser you won\u2019t have permission to write packages into the site-library and you will be prompted to create a personal library. You can specify the library, repository and a few other options by passing parameters to the <code>install.packages()<\/code>method. Use <code>?install.packages<\/code> to learn more.<\/p>\n<p>So what extra functionality does this new \u201c<a href=\"http:\/\/cran.r-project.org\/web\/packages\/geonames\/index.html\" target=\"_blank\" rel=\"noopener\">geonames<\/a>\u201d package bring?\u00a0 You\u2019ll have to do a little reading to figure out the details but for now just paste these lines into your R session:<\/p>\n<div id=\"crayon-54c8259920f52314810045\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-11\">11<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-12\">12<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-13\">13<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-14\">14<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-15\">15<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-16\">16<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-17\">17<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f52314810045-18\">18<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f52314810045-19\">19<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f52314810045-1\" class=\"crayon-line\"><span class=\"crayon-p\"># first load the new package<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">library<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">geonames<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-3\" class=\"crayon-line\"><\/div>\n<div id=\"crayon-54c8259920f52314810045-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-p\"># now define a function to convert zip codes into weather reports<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-5\" class=\"crayon-line\"><span class=\"crayon-i\">zip_weather<\/span> <span class=\"crayon-o\">&lt;<\/span><span class=\"crayon-o\">&#8211;<\/span> <span class=\"crayon-t\">function<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">postalcode<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-sy\">{<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">options<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-v\">warn<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-o\">&#8211;<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-p\"># Ignore warnings about &#8216;incomplete final line&#8217;.<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-7\" class=\"crayon-line\"><span class=\"crayon-v\">zip<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-e\">GNfindNearbyPostalCodes<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-v\">postalcode<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-i\">postalcode<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">country<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-s\">&#8216;US&#8217;<\/span><span class=\"crayon-sy\">,<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">maxRows<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-9\" class=\"crayon-line\"><span class=\"crayon-v\">weather<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-e\">GNfindNearByWeather<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">zip<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">lat<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-i\">zip<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">lng<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-10\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">tempF<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-st\">as<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">numeric<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">weather<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">temperature<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-o\">*<\/span> <span class=\"crayon-cn\">9<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-cn\">5<\/span> <span class=\"crayon-o\">+<\/span> <span class=\"crayon-cn\">32<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-11\" class=\"crayon-line\"><span class=\"crayon-v\">line1<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-e\">paste<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">weather<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">datetime<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216; GMT&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">sep<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-s\">&#8221;<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-12\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">line2<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-e\">paste<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8216;Weather for &#8216;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-i\">weather<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">stationName<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">sep<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-s\">&#8221;<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-13\" class=\"crayon-line\"><span class=\"crayon-v\">line3<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-e\">paste<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8216;temp = &#8216;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-i\">tempF<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216; deg. F with &#8216;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-i\">weather<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">clouds<\/span><span class=\"crayon-sy\">,<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-14\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-s\">&#8216;, wind at &#8216;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-i\">weather<\/span><span class=\"crayon-sy\">$<\/span><span class=\"crayon-i\">windSpeed<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8216; knots&#8217;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">sep<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-s\">&#8221;<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-15\" class=\"crayon-line\"><span class=\"crayon-e\">print<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">line1<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-16\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">print<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">line2<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-17\" class=\"crayon-line\"><span class=\"crayon-e\">print<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">line3<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-18\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-e\">options<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-v\">warn<\/span><span class=\"crayon-o\">=<\/span><span class=\"crayon-cn\">0<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-p\"># Restore default warnings.<\/span><\/div>\n<div id=\"crayon-54c8259920f52314810045-19\" class=\"crayon-line\"><span class=\"crayon-sy\">}<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Here is the result:<\/p>\n<div id=\"crayon-54c8259920f5b013527031\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f5b013527031-11\">11<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f5b013527031-12\">12<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f5b013527031-1\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">zip_weather<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">20066<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;2011-05-12 17:52:00 GMT&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-3\" class=\"crayon-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;Weather for Washington DC, Reagan National Airport&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;temp = 71.06 deg. F with few clouds, wind at 11 knots&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-5\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">zip_weather<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">63146<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;2011-05-12 16:51:00 GMT&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-7\" class=\"crayon-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;Weather for St. Louis, Lambert-St. Louis International Airport&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;temp = 80.96 deg. F with few clouds, wind at 12 knots&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-9\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">zip_weather<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-cn\">98107<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-10\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;2011-05-12 17:53:00 GMT&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-11\" class=\"crayon-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;Weather for Seattle, Seattle Boeing Field&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920f5b013527031-12\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;temp = 53.06 deg. F with few clouds, wind at 06 knots&#8221;<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Who\u2019d-a-thunk that R could so easily be turned into a real time weather system?<\/p>\n<h2>CRAN<\/h2>\n<p>In order to install and make use of packages you first have to find them.\u00a0 Luckily, most (but not all) R packages are organized and available from <a href=\"http:\/\/cran.r-project.org\/index.html\" target=\"_blank\" rel=\"noopener\">CRAN<\/a> \u2014 the Comprehensive R Archive Network. Just click on the <a href=\"http:\/\/cran.r-project.org\/web\/packages\/\" target=\"_blank\" rel=\"noopener\">Packages<\/a> link to see the full list of contributed packages. Packages are listed alphabetically with a short description. Unfortunately, there is no rating system but you can get a quick sense of quality by clicking on a package link and looking at the \u201cPublished\u201d date and especially any \u201cReverse dependencies\u201d listed at the the bottom of a package. Reading the documentation and looking at the number of releases in the \u201cOld sources\u201d is also very helpful.<\/p>\n<p>CRAN also maintains a set of <a href=\"http:\/\/cran.r-project.org\/web\/views\/\" target=\"_blank\" rel=\"noopener\">Task Views<\/a> that identify all the packages associated with a particular task. The maintainers of these views do a generally excellent job of staying on top of their area of interest and giving a detailed summary of which packages do what. If one of the task views is a perfect match you can have R install every package from that view using the \u201c<a href=\"http:\/\/cran.r-project.org\/web\/packages\/ctv\/\" target=\"_blank\" rel=\"noopener\">ctv<\/a>\u201d package. Yes, \u201cctv\u201d is a package to automate package installation. See the section below on \u201cInstalling older versions\u201d if you have trouble installing \u201cctv\u201d.<\/p>\n<h2>Installing packages<\/h2>\n<p>The basics of package installation are given in <a href=\"http:\/\/cran.r-project.org\/doc\/manuals\/R-admin.html#Add_002don-packages\" target=\"_blank\" rel=\"noopener\">chapter 6<\/a> of <a href=\"http:\/\/cran.r-project.org\/doc\/manuals\/R-admin.html\">R Installation and Administration<\/a>. There are two ways to do a command line installation of packages: from the R command line and from the shell command line.<\/p>\n<div id=\"crayon-54c8259920f67486991885\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f67486991885-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f67486991885-1\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-v\">install<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">packages<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-p\"># at the R prompt<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Within R you can use <code>install.packages()<\/code> as demonstrated in the example above. This will always attempt to install the latest version of packages it knows about.<\/p>\n<div id=\"crayon-54c8259920f6f310080109\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f6f310080109-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f6f310080109-1\" class=\"crayon-line\"><span class=\"crayon-sy\">$<\/span> <span class=\"crayon-i\">R<\/span> <span class=\"crayon-e\">CMD <\/span><span class=\"crayon-i\">INSTALL<\/span> <span class=\"crayon-p\"># at the shell prompt<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You can also invoke R from the command line. This is useful for some packages when<code>install.packages()<\/code> doesn\u2019t work or for packages that are not part of CRAN. More information is available with <code>R CMD INSTALL --help<\/code>. To install packages this way you must first download the package source to your local machine. Here is a quick demonstration:<\/p>\n<div id=\"crayon-54c8259920f89807666618\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f89807666618-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f89807666618-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f89807666618-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f89807666618-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f89807666618-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f89807666618-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f89807666618-7\">7<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f89807666618-1\" class=\"crayon-line\">$ # download the &#8220;fortunes&#8221; package using &#8216;wget&#8217;<\/div>\n<div id=\"crayon-54c8259920f89807666618-2\" class=\"crayon-line crayon-striped-line\">$ wget http:\/\/cran.r-project.org\/src\/contrib\/fortunes_1.4-1.tar.gz<\/div>\n<div id=\"crayon-54c8259920f89807666618-3\" class=\"crayon-line\">$ # install the package as superuser<\/div>\n<div id=\"crayon-54c8259920f89807666618-4\" class=\"crayon-line crayon-striped-line\">$ sudo R CMD INSTALL fortunes_1.4-1.tar.gz<\/div>\n<div id=\"crayon-54c8259920f89807666618-5\" class=\"crayon-line\">&#8230;<\/div>\n<div id=\"crayon-54c8259920f89807666618-6\" class=\"crayon-line crayon-striped-line\">* DONE (fortunes)<\/div>\n<div id=\"crayon-54c8259920f89807666618-7\" class=\"crayon-line\">$<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>Installing older versions<\/h2>\n<p>If you have total control over your system and always keep it at the bleeding edge then you will have no problem installing the latest and greatest versions of R packages. However, if your version of R is older (Perhaps you are running R on a webserver with CentOS?) then some of the more recent releases of packages will not work and <code>install.packages()<\/code> will generate messages like:<\/p>\n<div id=\"crayon-54c8259920f92820340481\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f92820340481-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f92820340481-2\">2<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f92820340481-1\" class=\"crayon-line\">Warning message:<\/div>\n<div id=\"crayon-54c8259920f92820340481-2\" class=\"crayon-line crayon-striped-line\">In install.packages(c(&#8220;sp&#8221;)) : package \u2018sp\u2019 is not available<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This is when you have to poke around in the \u201cOld sources\u201d link on the CRAN page for that package and use trial-and-error to find an older version of the package that will work with your version of R.\u00a0 You should start by determining what version of R you have:<\/p>\n<div id=\"crayon-54c8259920f99681676464\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920f99681676464-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920f99681676464-2\">2<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920f99681676464-1\" class=\"crayon-line\">$ R &#8211;version<\/div>\n<div id=\"crayon-54c8259920f99681676464-2\" class=\"crayon-line crayon-striped-line\">R version 2.8.1 (2008-12-22)<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Given that our version of R was released at the end of 2008, any version of the \u201csp\u201d package released in 2008 should definitely work. At least some of the 2009 releases should also work. Perusing the <a href=\"http:\/\/cran.r-project.org\/src\/contrib\/Archive\/sp\/\" target=\"_blank\" rel=\"noopener\">sp archive<\/a>, we might try installing version 0.9-37, the last of the 0.9-3x series which was released in May of 2009:<\/p>\n<div id=\"crayon-54c8259920fa1673598704\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa1673598704-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa1673598704-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa1673598704-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa1673598704-4\">4<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fa1673598704-1\" class=\"crayon-line\">$ wget http:\/\/cran.r-project.org\/src\/contrib\/Archive\/sp\/sp_0.9-37.tar.gz<\/div>\n<div id=\"crayon-54c8259920fa1673598704-2\" class=\"crayon-line crayon-striped-line\">$ sudo CMD INSTALL sp_0.9-37.tar.gz<\/div>\n<div id=\"crayon-54c8259920fa1673598704-3\" class=\"crayon-line\">&#8230;<\/div>\n<div id=\"crayon-54c8259920fa1673598704-4\" class=\"crayon-line crayon-striped-line\">$ # Success!<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>Using packages<\/h2>\n<p>To use a package you start up R and load packages one at a time with the library() command.<\/p>\n<div id=\"crayon-54c8259920fa8822298162\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa8822298162-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa8822298162-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa8822298162-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa8822298162-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa8822298162-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa8822298162-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fa8822298162-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fa8822298162-8\">8<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fa8822298162-1\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-p\"># load a specific package<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">library<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-o\">&lt;<\/span><span class=\"crayon-i\">em<\/span><span class=\"crayon-o\">&gt;<\/span><span class=\"crayon-i\">package_name<\/span><span class=\"crayon-o\">&lt;<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-i\">em<\/span><span class=\"crayon-o\">&gt;<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-3\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-p\"># learn about a package<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-sy\">?<\/span><span class=\"crayon-o\">&lt;<\/span><span class=\"crayon-i\">em<\/span><span class=\"crayon-o\">&gt;<\/span><span class=\"crayon-i\">package_name<\/span><span class=\"crayon-o\">&lt;<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-i\">em<\/span><span class=\"crayon-o\">&gt;<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-5\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-p\"># find out what packages are installed<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">library<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-7\" class=\"crayon-line\"><span class=\"crayon-e\">Packages <\/span><span class=\"crayon-st\">in<\/span> <span class=\"crayon-i\">library<\/span> <span class=\"crayon-s\">&#8216;\/usr\/local\/lib\/R\/site-library&#8217;<\/span><span class=\"crayon-o\">:<\/span><\/div>\n<div id=\"crayon-54c8259920fa8822298162-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">.<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Over time, your package library will contain more and more packages. Or\u00a0 perhaps system administrators or other users have also installed packages. It\u2019s good to know what\u2019s installed and at what version. This is where the location of the package library comes in handy. If you poke around you will find out that most packages come with a DESCRIPTION file that contains that information. To see all the package versions on our Ubuntu system we could just type:<\/p>\n<div id=\"crayon-54c8259920faf347061386\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920faf347061386-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920faf347061386-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920faf347061386-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920faf347061386-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920faf347061386-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920faf347061386-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920faf347061386-7\">7<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920faf347061386-1\" class=\"crayon-line\">$ head -4 \/usr\/local\/lib\/R\/site-library\/*\/DESCRIPTION<\/div>\n<div id=\"crayon-54c8259920faf347061386-2\" class=\"crayon-line crayon-striped-line\">==&gt; \/usr\/local\/lib\/R\/site-library\/abind\/DESCRIPTION &lt;==<\/div>\n<div id=\"crayon-54c8259920faf347061386-3\" class=\"crayon-line\">Package: abind<\/div>\n<div id=\"crayon-54c8259920faf347061386-4\" class=\"crayon-line crayon-striped-line\">Version: 1.1-0<\/div>\n<div id=\"crayon-54c8259920faf347061386-5\" class=\"crayon-line\">Date: 2004-03-12<\/div>\n<div id=\"crayon-54c8259920faf347061386-6\" class=\"crayon-line crayon-striped-line\">Title: Combine multi-dimensional arrays<\/div>\n<div id=\"crayon-54c8259920faf347061386-7\" class=\"crayon-line\">&#8230;<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Of course there is also an \u2018R\u2019 way of getting this information. All of the fields in DESCRIPTION files are accessible through the install<strong>ed<\/strong>.packages() command (note the spelling) which returns a matrix of information with packages as row names and fields as column names. The following example shows how to access this information programmatically from within R:<\/p>\n<div id=\"crayon-54c8259920fb7407481922\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fb7407481922-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fb7407481922-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-5\">5<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fb7407481922-6\">6<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-7\">7<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fb7407481922-8\">8<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-9\">9<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fb7407481922-10\">10<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fb7407481922-11\">11<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fb7407481922-1\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-v\">packages<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">installed<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">packages<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">)<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">rownames<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">packages<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-p\"># to see all installed packages<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-3\" class=\"crayon-line\">\u00a0 <span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;abind&#8221;<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span class=\"crayon-s\">&#8220;ade4&#8221;<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"crayon-s\">&#8220;adegenet&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-h\">\u00a0\u00a0<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">.<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-5\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-e\">colnames<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-i\">packages<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-p\"># to see all fields<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-6\" class=\"crayon-line crayon-striped-line\">\u00a0<span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">1<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;Package&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;LibPath&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;Version&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;Priority&#8221;<\/span> \u00a0<span class=\"crayon-s\">&#8220;Depends&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;Imports&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-7\" class=\"crayon-line\">\u00a0\u00a0<span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">7<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;LinkingTo&#8221;<\/span> <span class=\"crayon-s\">&#8220;Suggests&#8221;<\/span> \u00a0<span class=\"crayon-s\">&#8220;Enhances&#8221;<\/span> \u00a0<span class=\"crayon-s\">&#8220;OS_type&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;License&#8221;<\/span> \u00a0 <span class=\"crayon-s\">&#8220;Archs&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-8\" class=\"crayon-line crayon-striped-line\">\u00a0<span class=\"crayon-sy\">[<\/span><span class=\"crayon-cn\">13<\/span><span class=\"crayon-sy\">]<\/span> <span class=\"crayon-s\">&#8220;Built&#8221;<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-9\" class=\"crayon-line\"><span class=\"crayon-o\">&gt;<\/span> <span class=\"crayon-v\">packages<\/span><span class=\"crayon-sy\">[<\/span><span class=\"crayon-s\">&#8220;sp&#8221;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-e\">c<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-s\">&#8220;Package&#8221;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8220;Version&#8221;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-s\">&#8220;License&#8221;<\/span><span class=\"crayon-sy\">)<\/span><span class=\"crayon-sy\">]<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-10\" class=\"crayon-line crayon-striped-line\">\u00a0\u00a0<span class=\"crayon-t\">Package<\/span> \u00a0 \u00a0 \u00a0<span class=\"crayon-i\">Version<\/span> \u00a0 \u00a0 \u00a0<span class=\"crayon-i\">License<\/span><\/div>\n<div id=\"crayon-54c8259920fb7407481922-11\" class=\"crayon-line\"><span class=\"crayon-h\">\u00a0\u00a0 <\/span>\u00a0 \u00a0 <span class=\"crayon-s\">&#8220;sp&#8221;<\/span> \u00a0 \u00a0 <span class=\"crayon-s\">&#8220;0.9-72&#8221;<\/span> <span class=\"crayon-s\">&#8220;GPL (&gt;= 2)&#8221;<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>Special Cases<\/h2>\n<h3>ncdf<\/h3>\n<p>The <a href=\"http:\/\/cran.r-project.org\/web\/packages\/ncdf\/index.html\">ncdf<\/a> package requires that NetCDF \u2014 including the development libraries \u2014 first be installed on your system. Unfortunately, the NetCDF libraries and include files are not installed in a uniform location across Unix systems. This is a case where we need to pass configuration arguments to R CMD INSTALL. Here is what ended up working on Ubuntu 10.04 LTS:<\/p>\n<div id=\"crayon-54c8259920fc0021902436\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fc0021902436-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fc0021902436-1\" class=\"crayon-line\">sudo R CMD INSTALL &#8211;configure-args=&#8221;&#8211;with-netcdf-include=\/usr\/include &#8211;with-netcdf-lib=\/usr\/lib&#8221; ncdf_1.6.5.tar.gz<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>And for anyone stuck on CentOS 5.x:<\/p>\n<div id=\"crayon-54c8259920fc7585213787\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fc7585213787-1\">1<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fc7585213787-1\" class=\"crayon-line\">R CMD INSTALL &#8211;configure-args=&#8221;&#8211;with-netcdf-include=\/usr\/include\/netcdf-3 &#8211;with-netcdf-lib=\/usr\/lib&#8221; ncdf_1.6.5.tar.gz<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Here\u2019s an August, 2013 update for CentOS 6.x:<\/p>\n<div id=\"crayon-54c8259920fce947964884\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-54c8259920fce947964884-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-54c8259920fce947964884-2\">2<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-54c8259920fce947964884-1\" class=\"crayon-line\">sudo wget http:\/\/cran.r-project.org\/src\/contrib\/ncdf_1.6.6.tar.gz<\/div>\n<div id=\"crayon-54c8259920fce947964884-2\" class=\"crayon-line crayon-striped-line\">sudo R CMD INSTALL &#8211;configure-args=&#8221;&#8211;with-netcdf-include=\/usr\/include &#8211;with-netcdf-lib=\/usr\/lib&#8221; ncdf_1.6.6.tar.gz<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This entry is part 2 of 14 in the series Using R One of the reasons to use R for analysis and visualization is the&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-698","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}