{"id":75680,"date":"2020-01-22T13:54:20","date_gmt":"2020-01-22T08:24:20","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=75680"},"modified":"2020-01-22T13:54:20","modified_gmt":"2020-01-22T08:24:20","slug":"r-packages","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/r-packages\/","title":{"rendered":"Packages in R &#8211; Learn to install, load and manage packages"},"content":{"rendered":"<p><strong>This TechVidvan article is designed to introduce R package basics that every R programmer needs to be aware of before working on it.<\/strong><\/p>\n<p>While core R is powerful and exciting enough, packages are what makes R truly the must-have tool for data science and machine learning.<\/p>\n<p>In this tutorial, we will explore what packages are in R programming. We will learn how to install them and use them. Finally, we will be showcasing a few useful R packages that make a beginner\u2019s life extremely easy.<\/p>\n<h2>What are R Packages?<\/h2>\n<p>Packages are collections of functions and datasets that can be installed and used in the R environment. They enhance R\u2019s existing abilities and even provide new ones.<\/p>\n<p>R is an open-source programming language and anyone can make and upload a new package. This means that there are a lot of R packages for almost every use imaginable and more packages are uploaded every day.<\/p>\n<p class=\"tvdiduno\"><em>The CRAN repository has more than <strong>15000 R packages<\/strong> ready to use.<\/em><\/p>\n<h3>What is a Repository?<\/h3>\n<p>Repositories are places where packages are stored online so that users can download and use them. While anyone can have their own local repository, there are three most popular repositories available online for R packages.<\/p>\n<p><a href=\"https:\/\/cran.r-project.org\/\">CRAN<\/a>: CRAN or Comprehensive R Archive Network is the largest repository for R packages. It is maintained by the R foundation. Packages uploaded here need to pass several tests to ensure that CRAN policies are being followed.<\/p>\n<p><a href=\"https:\/\/www.bioconductor.org\/\">Bioconductor:<\/a> Bioconductor is an open-source repository for bioinformatics packages. Like CRAN, it also has a submission and review process.<\/p>\n<p><a href=\"https:\/\/github.com\/search?q=r+package\">Github<\/a>: Github does not store packages for R alone. It is the largest open-source repository. It has packages, extensions, and libraries for almost all software and languages. Many popular R packages can be found on the Github repository.<\/p>\n<h3>How to Install an R Package?<\/h3>\n<p>To use a package in R, you must first install it and then load it into your <strong>library<\/strong>. The library is a directory where packages in the current R session are loaded. You need to load the package into the library for every session.<\/p>\n<p>Don&#8217;t have R installed yet? Follow the step by step tutorial to <a href=\"https:\/\/techvidvan.com\/tutorials\/install-r\/\"><strong>install R<\/strong><\/a>.<\/p>\n<p>R already has several packages installed. It loads some of these packages into the library by default while some need to be loaded for <strong>every session<\/strong>.<\/p>\n<p>You can use the following command to install a package in R.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">install.packages(\u201c&lt;package_name&gt;\u201d)<\/pre>\n<p>Here, replace <strong><code>&lt;package_name&gt;<\/code><\/strong> with the name of the package that you need to install. Like everything else in R, package names are also <strong>case sensitive<\/strong>. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">install.packages(\"esquisse\")<\/pre>\n<p>The above command will result in a waterfall of code that details the installation process of the package and all of its dependencies.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-install.packages_esquisse_.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75688\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-install.packages_esquisse_.png\" alt=\"install.packages(_esquisse_) - packages in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h3>How to Load a Package into the Library?<\/h3>\n<p>Once you have installed a package, you need to <strong>load<\/strong> it into the library to be able to use it. You can do that with the following command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">library(&lt;package_name&gt;)<\/pre>\n<p>Here, replace <strong><code>&lt;package_name&gt;<\/code><\/strong> with the name of the package you need to load. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">library(plyr)<\/pre>\n<h3><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-library.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75691\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-library.png\" alt=\"library() - packages in r\" width=\"1299\" height=\"741\" \/><\/a><\/h3>\n<h3>Managing Packages<\/h3>\n<p>There are several commands in R that can help you with managing the packages you use and install. We can view available packages, view installed and loaded packages. We can check for updates and update them to the latest versions.<\/p>\n<p>You can see a list of the R packages loaded into the current session with the following command.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">search()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-search.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75693\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-search.png\" alt=\"search() - packages in r\" width=\"1299\" height=\"742\" \/><\/a><\/p>\n<p>You can use the following command to see all the packages installed on the system.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">installed.packages()<\/pre>\n<p>The <strong><code>installed.packages()<\/code><\/strong> command returns a matrix where every package has a row and the columns show details about the packages like their versions, dependencies, library path, license details, etc.. For example:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-installed.packages.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75694\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-installed.packages.png\" alt=\"installed.packages() - packages in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>To update a package, use the following command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">update.packages(&lt;package_name&gt;)<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-update.packages.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75695\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/packages-in-r-update.packages.png\" alt=\"update.packages() - packages in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>You can also leave the parenthesis empty. In this case, R will check all the packages for the latest versions and ask you which ones to update.<\/p>\n<p><strong>Note<\/strong>: We can also install and manage our packages without using the commands. Both Rstudio and RGUI provide options to install and manage packages through the GUI. For example in Rstudio, you can select the <strong>tools<\/strong> -&gt; <strong>install packages<\/strong> to install new packages and the <strong>tools<\/strong> -&gt; <strong>check for package updates<\/strong> to update installed packages.<\/p>\n<p>You can remove installed packages using the following command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">remove.packages(\u201c&lt;package_name&gt;\u201d)<\/pre>\n<h3>Useful R Packages for Beginners<\/h3>\n<p>There are many packages available for R programming. So many, that it may be very confusing to decide which ones to use. Here are a few reliable and popular packages that you can use:<\/p>\n<ol>\n<li><strong>Tidyverse<\/strong> &#8211; Tidyverse is a collection of packages. It enables the user to clean, process, model and visualize data. The Tidyverse package contains packages like tibble, dplyr, forcats, purrr, readr, ggplot2, stringr, and tidyr.<\/li>\n<li><strong>Rtweet<\/strong> &#8211; Twitter is the best available testing ground for <strong>sentiment analysis<\/strong>. The rtweet package helps users in this by allowing them to <strong>scrape<\/strong> Tweets and organize their content in an easy-to-analyze dataset.<\/li>\n<li><strong>R markdown<\/strong> &#8211; The R markdown package is the ultimate <strong>report generation<\/strong> package for R. It lets you create rich documents in multiple formats like pdf, HTML, etc. It also allows you to embed R code and its results directly into the reports making them thorough and highly informative with the help of R\u2019s rich and powerful visualizations.<\/li>\n<li><strong>MLR<\/strong> (Machine Learning in R) &#8211; MLR is a <strong>complete machine learning package<\/strong> for R. It includes all the famous machine learning algorithms used for machine learning projects.<\/li>\n<li><strong>Reticulate<\/strong> &#8211; Reticulate is a bridging package. It allows you to use <strong><a href=\"https:\/\/techvidvan.com\/tutorials\/category\/python\/\">Python<\/a> alongside with R<\/strong> in the R environment. You can also use various Python libraries within R by using the Reticulate package.<\/li>\n<li><strong>Installr<\/strong> &#8211; Installr is a <strong>package management<\/strong> package. It helps with keeping track of available updates for all your installed packages. It also allows you to update all your packages with a single command.<\/li>\n<li><strong>Shiny<\/strong> &#8211; The Shiny package lets you create <strong>interactive web-apps<\/strong> in the R development environment. You can seamlessly embed R code, results and visualization into Shiny apps for highly engaging data-driven stories.<\/li>\n<li><strong>Tensorflow<\/strong> &#8211; The Tensorflow package is R\u2019s interface to Tensorflow. It lets you work with the Tensorflow API which is an open-source machine learning library.<\/li>\n<\/ol>\n<h2>Summary<\/h2>\n<p>Packages are what make R the flexible, comprehensive and powerful programming language it is. They are the major reason R has stayed relevant to the data science industry for more than two decades.<\/p>\n<p>In this R tutorial, we learned about R packages and the library. We learned how to install packages and how to manage them. We saw how we can update and remove packages as well. Finally, we explored a few useful packages in R that make any R programmer\u2019s life easy.<\/p>\n<p>The R community uploads hundreds of new packages every month. Keep exploring them to find new and exciting features of R and its packages.<\/p>\n<p><strong>Any difficulty while practicing packages in R programming?<\/strong><\/p>\n<p>Ask our\u00a0<strong>TechVidvan<\/strong>\u00a0experts.<\/p>\n<p>Keep Practicing!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This TechVidvan article is designed to introduce R package basics that every R programmer needs to be aware of before working on it. While core R is powerful and exciting enough, packages are what&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":75708,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1020],"tags":[1417,1418,1419,1420,1421,1132,1422,1423,1424],"class_list":["post-75680","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-check-installed-r-packages","tag-check-package-version-r","tag-cran-repository","tag-packages-in-r","tag-r-check-loaded-packages","tag-r-install-package","tag-r-packages","tag-r-uninstall-package","tag-update-r-package"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Packages in R - Learn to install, load and manage packages - TechVidvan<\/title>\n<meta name=\"description\" content=\"R packages are what makes R indeed the must-have tool for data science &amp; machine learning. In this tutorial, you\u2019ll explore how to install &amp; use R packages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/r-packages\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Packages in R - Learn to install, load and manage packages - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"R packages are what makes R indeed the must-have tool for data science &amp; machine learning. In this tutorial, you\u2019ll explore how to install &amp; use R packages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/r-packages\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-22T08:24:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Packages in R - Learn to install, load and manage packages - TechVidvan","description":"R packages are what makes R indeed the must-have tool for data science & machine learning. In this tutorial, you\u2019ll explore how to install & use R packages.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/r-packages\/","og_locale":"en_US","og_type":"article","og_title":"Packages in R - Learn to install, load and manage packages - TechVidvan","og_description":"R packages are what makes R indeed the must-have tool for data science & machine learning. In this tutorial, you\u2019ll explore how to install & use R packages.","og_url":"https:\/\/techvidvan.com\/tutorials\/r-packages\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-01-22T08:24:20+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Packages in R &#8211; Learn to install, load and manage packages","datePublished":"2020-01-22T08:24:20+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/"},"wordCount":1163,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg","keywords":["check installed R packages","check package version R","cran repository","Packages in R","R check loaded packages","r install package","R Packages","R uninstall package","update R package"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/r-packages\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/","url":"https:\/\/techvidvan.com\/tutorials\/r-packages\/","name":"Packages in R - Learn to install, load and manage packages - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg","datePublished":"2020-01-22T08:24:20+00:00","description":"R packages are what makes R indeed the must-have tool for data science & machine learning. In this tutorial, you\u2019ll explore how to install & use R packages.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/r-packages\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/packages-in-R-programming.jpg","width":802,"height":420,"caption":"R packages"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/r-packages\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Packages in R &#8211; Learn to install, load and manage packages"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=75680"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75680\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/75708"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=75680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=75680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=75680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}