{"id":1741,"date":"2020-12-04T20:48:09","date_gmt":"2020-12-04T20:48:09","guid":{"rendered":"https:\/\/ded9.com\/?p=1741"},"modified":"2025-10-25T07:42:56","modified_gmt":"2025-10-25T07:42:56","slug":"packages-in-the-programming-language-r","status":"publish","type":"post","link":"https:\/\/ded9.com\/de\/packages-in-the-programming-language-r\/","title":{"rendered":"Packages in the R Programming Language: A Comprehensive Guide"},"content":{"rendered":"<p><span style=\"font-size: 12pt;\">R packets are a set of R functions that match the sample data and code. They are stored in the R directory under a &#8221; library &#8221; directory. <\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-258625 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/top_25_r_packages.jpg\" alt=\"Packages in the R Programming Language: A Comprehensive Guide\" width=\"1018\" height=\"703\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/top_25_r_packages.jpg 1018w, https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/top_25_r_packages-300x207.jpg 300w, https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/top_25_r_packages-768x530.jpg 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/span><\/p>\n<p>R packages are a set of R Functions; R installs a set of packages. More packages can be added later; That is, when they are needed for a specific purpose.<\/p>\n<p>When we launch the R console, only the default packages are available. Other packages are already installed; the R program must explicitly download them, and when using them, they must be usable.<\/p>\n<p style=\"text-align: left;\">All packages available in the R programming language<span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">\u00a0are listed in\u00a0<a href=\"https:\/\/www.geeksforgeeks.org\/packages-in-r-programming\/\" target=\"_blank\" rel=\"noopener\">R packages<\/a><\/span>.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"aligncenter wp-image-258628 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/list-of-r-packages.png\" alt=\"All packages available in the R programming language\u00a0are listed in\u00a0R packages.\" width=\"600\" height=\"500\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/list-of-r-packages.png 600w, https:\/\/ded9.com\/wp-content\/uploads\/2020\/12\/list-of-r-packages-300x250.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The following is a List of commands used to check, verify, and use R packets:<\/p>\n<h2>Check The Packages Available In R<\/h2>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">.libPaths ()<\/pre>\n<\/div>\n<p>When we run the above code, the following result is obtained. Of course, your computer&#8217;s local configuration package may change slightly.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">[2] \u201cC: \/ Program Files \/ R \/ R-3.2.2 \/ library\u201d<\/pre>\n<\/div>\n<h1><span style=\"font-size: 18pt;\">Get a List of all installed packages.<\/span><\/h1>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">library ()\r\n\r\nPackages in library 'C: \/ Program Files \/ R \/ R-3.2.2 \/ library':\r\n\r\nbase The R Base Package\r\n\r\nboot Bootstrap Functions (Originally by Angelo Canty\r\n\r\nfor S)\r\n\r\nclass Functions for Classification\r\n\r\ncluster \u201cFinding Groups in Data\u201d: Cluster Analysis\r\n\r\nExtended Rousseeuw et al.\r\n\r\ncodetools Code Analysis Tools for R\r\n\r\ncompiler The R Compiler Package\r\n\r\ndatasets The R Datasets Package\r\n\r\nforeign Read Data Stored by 'Minitab', 'S', 'SAS',\r\n\r\n'SPSS', 'Stata', 'Systat', 'Weka', 'dBase',\u2026\r\n\r\ngraphics The R Graphics Package\r\n\r\ngrDevices The R Graphics Devices and Support for Colors\r\n\r\nand Fonts\r\n\r\ngrid The Grid Graphics Package\r\n\r\nKernSmooth Functions for Kernel Smoothing Supporting Wand\r\n\r\n&amp; Jones (1995)\r\n\r\nlattice Trellis Graphics for R\r\n\r\nMASS Support Functions and Datasets for Venables and\r\n\r\nRipley's MASS\r\n\r\nMatrix Sparse and Dense Matrix Classes and Methods\r\n\r\nmethods Formal Methods and Classes\r\n\r\nmgcv Mixed GAM Computation Vehicle with GCV \/ AIC \/ REML\r\n\r\nSmoothness Estimation\r\n\r\nnlme Linear and Nonlinear Mixed Effects Models\r\n\r\nnnet Feed-Forward Neural Networks and Multinomial\r\n\r\nLog-Linear Models\r\n\r\nparallel Support for Parallel computation in R\r\n\r\nrpart Recursive Partitioning and Regression Trees\r\n\r\nspatial Functions for Kriging and Point Pattern\r\n\r\nAnalysis\r\n\r\nsplines Regression Spline Functions and Classes\r\n\r\nstats The R Stats Package\r\n\r\nstats4 Statistical Functions using S4 Classes\r\n\r\nsurvival Survival Analysis\r\n\r\ntcltk Tcl \/ Tk Interface\r\n\r\ntools Tools for Package Development\r\n\r\nutils The R Utils Package<\/pre>\n<\/div>\n<p>Thus, all packets currently loaded in the R environment will be received.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">search ()<\/pre>\n<\/div>\n<p>When we execute the above code, the following result is obtained, which, of course, may depend on your computer&#8217;s local settings, slightly different:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">[1] \u201c.GlobalEnv\u201d \u201cpackage: stats\u201d \u201cpackage: graphics\u201d\r\n\r\n[4] \u201cpackage: grDevices\u201d \u201cpackage: utils\u201d \u201cpackage: datasets\u201d\r\n\r\n[7] \u201cpackage: methods\u201d \u201cAutoloads\u201d \u201cpackage: base\u201d<\/pre>\n<\/div>\n<h2>Install a new package.<\/h2>\n<p>There are two ways we can add new packages to R. One is to install directly from the CRAN directory, and the other is to download a package for your local System and install it manually.<\/p>\n<h4>Direct installation from CRAN<\/h4>\n<p>The following Command receives the packages directly from the CRAN website page and installs the package in the R environment. You may be asked to select the nearest mirror. Choose one that fits your location.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">install.packages (\u201cPackage Name\u201d)\r\n\r\n# Install the package named \u201cXML\u201d.\r\n\r\ninstall.packages (\u201cXML\u201d)<\/pre>\n<\/div>\n<h4>Install the package manually.<\/h4>\n<p>See the\u00a0R packages link. Download the required package. Save the package as a zip File to a convenient location on your local System.<\/p>\n<p>You can now run the following Command to install this package in the R environment:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">install.packages (file_name_with_path, repos = NULL, type = \u201csource\u201d)\r\n\r\n# Install the package named \u201cXML\u201d\r\n\r\ninstall.packages (\u201cE: \/XML_3.98-1.3.zip\u201d, repos = NULL, type = \u201csource\u201d)<\/pre>\n<\/div>\n<div>\n<h1 class=\"break-words\" dir=\"auto\"><span style=\"font-size: 18pt;\"><strong>R Packages and Repositories Explained<\/strong><\/span><\/h1>\n<p class=\"break-words\" dir=\"auto\"><strong>Understanding R Packages<\/strong><\/p>\n<p class=\"break-words\" dir=\"auto\">An R package is a powerful tool for organizing and sharing work, bundling together code (not limited to R), documentation for both the package and its functions, tests to ensure proper functionality, and data sets. In R, packages are collections of functions, compiled code, and sample data stored in a &#8220;library&#8221; directory within the R environment.<\/p>\n<p class=\"break-words\" dir=\"auto\">During R installation, a set of default packages is included, which are automatically available when you start the R console. However, other pre-installed packages must be explicitly loaded to be used in your R program.<\/p>\n<p class=\"break-words\" dir=\"auto\"><strong>What Are Repositories?<\/strong><br \/>\nRepositories are centralized locations where R packages are stored and can be accessed for installation. They can be local or online, often publicly available, and are maintained by organizations or developers. Here are some of the most widely used repositories for R packages:<\/p>\n<ul class=\"marker:text-secondary\" dir=\"auto\">\n<li class=\"break-words\"><strong>CRAN (Comprehensive R Archive Network):<\/strong> The official repository for R, CRAN is a global Network of <a href=\"https:\/\/ded9.com\/understanding-ftp-and-its-common-errors\/\">FTP<\/a> and web servers managed by the R community. To be published on CRAN, a package must pass rigorous tests to ensure compliance with CRAN&#8217;s policies, thereby guaranteeing quality and reliability.<\/li>\n<li class=\"break-words\"><strong>Bioconductor:<\/strong> A specialized repository focused on open-source bioinformatics software, Bioconductor has its own submission and review processes. Its active community regularly hosts conferences and meetings to maintain high standards.<\/li>\n<li class=\"break-words\"><strong>GitHub:<\/strong> The leading platform for open-source projects, GitHub is favored for its unlimited space for open-source work, seamless integration with Git for version control, and its collaborative features that make sharing and teamwork easy.<\/li>\n<li>\n<p class=\"break-words\" dir=\"auto\"><strong>Loading Packages in the R Programming Language<\/strong><\/p>\n<p class=\"break-words\" dir=\"auto\"><strong>How to Load an R Package<\/strong><br \/>\nOnce an R package is installed, you can access its functionalities using either the <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">library()<\/span> or <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">require()<\/span> function. These functions load the specified package into your R session for use. Here&#8217;s how:<\/p>\n<div class=\"not-prose\" dir=\"auto\">\n<div class=\"relative [&amp;_div+div]:!mt-0 mt-3 mb-3 -mx-4 -mr-2 @md:-mr-4\">\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"># Load a package using the library function library(dplyr) # Load a package using the require function require(dplyr)<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"break-words\" dir=\"auto\"><strong>Key Difference Between <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">library()<\/span> and <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">require()<\/span><\/strong><br \/>\nWhile both functions load a package, they behave differently when a package fails to load. The <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">library<\/span>\u00a0function will throw an error if the package is unavailable or cannot be loaded, causing the script to halt. In contrast, <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">require()<\/span> issues a warning and returns <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">FALSE<\/span>, allowing the script to continue running.<\/p>\n<p class=\"break-words\" dir=\"auto\"><strong>Package vs. Library: Clearing the Confusion<\/strong><br \/>\nThe terms &#8220;package&#8221; and &#8220;library&#8221; are often used interchangeably, but they have distinct meanings:<\/p>\n<ul class=\"marker:text-secondary\" dir=\"auto\">\n<li class=\"break-words\"><strong>Library<\/strong>: Refers to the Library Command\u00a0used to load a package, as well as the directory on your computer where installed packages are stored.<\/li>\n<li class=\"break-words\"><strong>Package<\/strong>: A collection of functions, data, and documentation bundled together, designed to organize and share code efficiently.<\/li>\n<\/ul>\n<p class=\"break-words\" dir=\"auto\"><strong>Loading Multiple Packages at Once<\/strong><br \/>\nUnlike <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">install.packages()<\/span>, which accepts a vector of package names for installation, the <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">library()<\/span> function does not natively support loading multiple packages in a single call. However, you can load multiple packages using a workaround, such as listing them sequentially or using community-developed methods. Here&#8217;s an example of loading various packages:<\/p>\n<div class=\"not-prose\" dir=\"auto\">\n<div class=\"relative [&amp;_div+div]:!mt-0 mt-3 mb-3 -mx-4 -mr-2 @md:-mr-4\">\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"># Load multiple packages using library library(caret) library(dplyr) library(ggplot2)<\/pre>\n<\/div>\n<p>Alternatively, you can use the <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">require()<\/span> function similarly:<\/p>\n<\/div>\n<\/div>\n<div class=\"not-prose\" dir=\"auto\">\n<div class=\"relative [&amp;_div+div]:!mt-0 mt-3 mb-3 -mx-4 -mr-2 @md:-mr-4\">\n<div>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"># Load multiple packages using require require(caret) require(dplyr) require(ggplot2)<\/pre>\n<\/div>\n<p>Both approaches work effectively, but Library <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">()<\/span> is often preferred for its clarity, while <span class=\"text-sm px-1 rounded-sm !font-mono bg-orange-400\/10 text-orange-500 dark:bg-orange-300\/10 dark:text-orange-200\">require()<\/span> offers more flexibility for conditional loading scenarios. Choose the method that best suits your workflow.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<h4>Load the package in the Library.<\/h4>\n<p>Before a package can be used in Coding, that package must be loaded in the current R environment. You should also load a package that was previously installed but is not available in the current R environment. A package is loading using the following Command.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;r&quot;,&quot;mime&quot;:&quot;text\/x-rsrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">library (\u201cpackage Name\u201d, lib.loc = \u201cpath to library\u201d)\r\n\r\n# Load the package named \u201cXML\u201d\r\n\r\ninstall.packages (\u201cE: \/XML_3.98-1.3.zip\u201d, repos = NULL, type = \u201csource\u201d)<\/pre>\n<h2>FAQ<\/h2>\n<div id=\"rank-math-rich-snippet-wrapper\"><div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-1\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is an R package?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>It\u2019s a bundle of R functions, data, documentation and (optionally) compiled code to extend R\u2019s capabilities.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-2\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I install a package in R?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use install.packages(\"packageName\") for CRAN, or methods for Bioconductor\/GitHub. Then, load it via library(packageName).<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-3\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Where are R\u2019s package repositories?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The main one is Comprehensive R Archive Network (CRAN); others include Bioconductor and GitHub.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>R packets are a set of R functions that match the sample data and code. They are stored in the R directory under a &#8221; library &#8221; directory. R packages are a set of R Functions; R installs a set of packages. More packages can be added later; That is, when they are needed for [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":1742,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[174],"tags":[36,3324],"class_list":["post-1741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-r-studio","tag-ftp","tag-r"],"acf":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/posts\/1741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/comments?post=1741"}],"version-history":[{"count":8,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/posts\/1741\/revisions"}],"predecessor-version":[{"id":263853,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/posts\/1741\/revisions\/263853"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/media\/1742"}],"wp:attachment":[{"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/media?parent=1741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/categories?post=1741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ded9.com\/de\/wp-json\/wp\/v2\/tags?post=1741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}