Learn how to install and load packages in R Programming. #R #coding #Programming

A lot of functions are already available with the base installation of R and they are usually used for numeric calculations, statistical analyses, plotting and visualisations. These functions can be used immediately and do not require you to load any libraries. However, there are times that you might need to use more specialised techniques in your assessment and the tool sets are contained within packages (also referred to as libraries). There are a number of packages that are included with the base distribution of R and you will need to load them before you can begin to use them. In order to know what is available in your R, you would have to use the following function.

#In this example, I will try to call up a page detailing the installed packages within the R. 
R> installed.packages(priority="base")
     Package     LibPath                              Version Priority
base      "base"      "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
compiler  "compiler"  "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
datasets  "datasets"  "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
graphics  "graphics"  "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
grDevices "grDevices" "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
grid      "grid"      "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
methods   "methods"   "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
parallel  "parallel"  "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
splines   "splines"   "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
stats     "stats"     "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
stats4    "stats4"    "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
tcltk     "tcltk"     "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
tools     "tools"     "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
utils     "utils"     "C:/Program Files/R/R-4.0.3/library" "4.0.3" "base"  
          Depends Imports                      LinkingTo
base      NA      NA                           NA       
compiler  NA      NA                           NA       
datasets  NA      NA                           NA       
graphics  NA      "grDevices"                  NA       
grDevices NA      NA                           NA       
grid      NA      "grDevices, utils"           NA       
methods   NA      "utils, stats"               NA       
parallel  NA      "tools, compiler"            NA       
splines   NA      "graphics, stats"            NA       
stats     NA      "utils, grDevices, graphics" NA       
stats4    NA      "graphics, methods, stats"   NA       
tcltk     NA      "utils"                      NA       
tools     NA      NA                           NA       
utils     NA      NA                           NA       
          Suggests                                     Enhances         
base      "methods"                                    NA               
compiler  NA                                           NA               
datasets  NA                                           NA               
graphics  NA                                           NA               
grDevices "KernSmooth"                                 NA               
grid      "lattice"                                    NA               
methods   "codetools"                                  NA               
parallel  "methods"                                    "snow, nws, Rmpi"
splines   "Matrix, methods"                            NA               
stats     "MASS, Matrix, SuppDists, methods, stats4"   NA               
stats4    NA                                           NA               
tcltk     NA                                           NA               
tools     "codetools, methods, xml2, curl, commonmark" NA               
utils     "methods, xml2, commonmark"                  NA               
          License           License_is_FOSS License_restricts_use OS_type
base      "Part of R 4.0.3" NA              NA                    NA     
compiler  "Part of R 4.0.3" NA              NA                    NA     
datasets  "Part of R 4.0.3" NA              NA                    NA     
graphics  "Part of R 4.0.3" NA              NA                    NA     
grDevices "Part of R 4.0.3" NA              NA                    NA     
grid      "Part of R 4.0.3" NA              NA                    NA     
methods   "Part of R 4.0.3" NA              NA                    NA     
parallel  "Part of R 4.0.3" NA              NA                    NA     
splines   "Part of R 4.0.3" NA              NA                    NA     
stats     "Part of R 4.0.3" NA              NA                    NA     
stats4    "Part of R 4.0.3" NA              NA                    NA     
tcltk     "Part of R 4.0.3" NA              NA                    NA     
tools     "Part of R 4.0.3" NA              NA                    NA     
utils     "Part of R 4.0.3" NA              NA                    NA     
          MD5sum NeedsCompilation Built  
base      NA     NA               "4.0.3"
compiler  NA     NA               "4.0.3"
datasets  NA     NA               "4.0.3"
graphics  NA     "yes"            "4.0.3"
grDevices NA     "yes"            "4.0.3"
grid      NA     "yes"            "4.0.3"
methods   NA     "yes"            "4.0.3"
parallel  NA     "yes"            "4.0.3"
splines   NA     "yes"            "4.0.3"
stats     NA     "yes"            "4.0.3"
stats4    NA     NA               "4.0.3"
tcltk     NA     "yes"            "4.0.3"
tools     NA     "yes"            "4.0.3"
utils     NA     "yes"            "4.0.3"

The page will show you a list of all the installed packages within the R and it is up to you to load one package before you can start using it.

#Use this function to load the library of your choice and I have chosen the library "graphics" for this example. 
R> library("graphics")
R>
#If you entered the command properly and command prompt will show as normal. In this example, I purposely spelt wrongly and we will encounter the following error message. 
R> library("graphic")
R>Error in library("graphic") : there is no package called ‘graphic’

There are a lot of useful libraries that are contributed by other users and programmers and you would have to install these packages in order to make use of them.

#Use the following function in order to install a package that is not found within your base installation of R. In this example, I decided to perform mathematical calculations using univariate and multivariate spatio-temporal random effects models for point-referenced data using Markov chain Monte Carlo, so I will go for "spBayes" that is the package to do just that. 
R>install.packages("spBayes")
#If the command is run successfully, the console will start to show you the running output as the procedure complete. 

Every so often, you also might want to check for updates to your packages therefore, you could use the following function to check.

R>update.packages()
#If the command is run successfully, the console will start to show you the running output as the procedure complete. 
Google Workspace is the new G Suite, integrates many ...
Google Workspace
The only productivity tool you’ll ever need!

Don’t you wish you could IMPROVE PRODUCTIVITY and INCREASE COLLABORATION among your staff while doing away with all the hassle? After trying out so many productivity and office tools, I discovered that Google Workspace is the BEST TOOL for both remote and on-site working!

Click on the Google Workspace logo and start growing!

Apart from using the Google Workspace, I want to provide you with even more EXCITING VALUE for your company’s GROWTH and EXPANSION. Today, I am giving out two promotional codes that you could apply and start SAVING MORE MONEY!

PlansPromotional Codes
Google Workspace Business Starter PlanEAAY74Q979XD49K
Google Workspace Business Standard PlanYATVPVG39EFFFGW
Each promotion code provides 10% off the first year on either Google Workspace Business Starter plan or Google Workspace Business Standard plan*.

Click here to start GROWING NOW!

Leave a comment

Design a site like this with WordPress.com
Get started