Packages in R Language

In this tutorial, we are going to learn about the Packages in R Language, what actually a package in the r programming language means, access the library path, etc.
Submitted by Bhavya Sri Khandrika, on December 06, 2020

The R language is well popularly used in many machine learning applications due to its durability and user-friendly environment. The programmers will feel at ease due to the multiple features available in R. Coming to the above said features here let us make an attempt to teach the main importance of one such feature in the R language i.e., packages in R language.

Packages

They are the collection of the R functions. Also, one should include the sample data along with the compiled code under these packages. Thus, adding all these three components together are called as the packages in the R language. R stores all of these three attributes under the name of libraries. The library is something that resembles a directory. When the user installs R on a system for the first time, then as a part of the default process the R environment installs the predefined packages in the R.

Also, the development team of the R states that programmers have a provision of installing other packages as a part of custom settings once the prior installation of the R completes in a particular system. Besides that, the extra packages which are later installed in the system as per the user requirement have their predefined functionality set as per the code written. When the users start the R console for the first time after the installation of the R programming language in his or her system then in the initial stages only the predefined packages are available for use. Whereas whenever the programmer explicitly installs the custom packages then he or she needs to declare their usage explicitly in the program in order to specify the compiler about the need for customs packages installed in the program execution.

Packages in R Language

Image source: https://static.javatpoint.com/tutorial/r/images/r-packages.png

Here the above picture is about the steps that need to be followed while working with both default and explicitly downloaded packages in the R.

First, the user needs to check the availability of the default packages installed on the computer system. Then he or she needs to install the extra packages from the CRAN website as per their requirement. Once the installation is completed then the programmer needs to load the custom packages on the console explicitly.

What actually a package in the r programming language means?

The packages in the R are like the store hub of the r functions stored in them. The library is the directory that acts as the storage place of all the packages available in the R language. The library in the computer system consists of all the necessary files that associate with the packages in R. Now let us discuss each step stated in the above lines in a brief way:

The initial step is the user needs to check the availability of the packages that are by default installed on the computer during the time of installation of the R bundle into the system. To get the complete information regarding the inbuilt packages in the R, there is a command that helps the user to accomplish and acquire the result.

Access the library path

With the help of the following state command, the user will be able to access the path of the R library in his or her PC or laptop.

libpaths():

This command gives the following result. However, the outcome depends purely on the local settings that are available on the individual's pc or the laptop:

[1] "c:/users/includehelp/r language/documents/r/win-library/3.6"
[2] "c:/program files/r/r-3.6.1/library"

The following user command will assist them in knowing much about the pre-installed packages in the user PC or laptop.

library (): 

This command will enable the user to get acquainted with the installed packages on the system after the default installation of the R programming language bundle.

Packages in library 'c:/program files/r/r-3.6.1/library':

There are several packages that fall under the above-given path location. The following are some of them.

base The Base Package in the R language
utils The Utils Package of the R language
tools The necessary tools required for the Package Development is found in this specific package.
tcltk The Tcl/Tk Interface is enabled using this package
survival The Survival Analysis package in R language
stats4 The statistical functions that uses the S4 Classes are found here.
stats The Stats Package of the R Language
splines The Regression spline functions as well as the classes related to them are found in this package.
spatial Package has functions that are useful for both the Kriging and Point Pattern Analysis process.
rpart Package that consists functions related to the recursive partitioning and also for the analysis of regression Trees.
parallel Supports and provides the functions for the Parallel computations and analysis in R language.
nnet Assist in feeding the forward Neural Networks in the analysis part.
nlme The functions or the computational platform related to both linear and the nonlinear mixed effects models is provided by this package.
mgcv Package that has functions, that are used in the smoothness estimation.
methods The formal or commonly used classes and methods in the R language.
Matrix This particular package has sparse and the dense matrices both classes and methods in it.
MASS The extra support functions and additional datasets that are mainly used in working with Venables and Ripley's MASS.
lattice The Trellis Graphics used in the R language.
KernSmooth The Functions that are useful for the Kernel Smoothing Supporting Wand & Jones (1995).
grid The Grid Graphics functions or package available in R programming language.
grDevices This package deals with the R graphics devices and other supporting functions for other attributes colour and fonts in the pictorial representation.
graphics The Graphics Package of the R programming language.
foreign The read data will be stored by 'Minitab', 'SAS', 'Stata', 'Systat', 'dBase',etc.
datasets It is the Dataset Package that is found in R programming language.
compiler Compiler package deals with the R compiler functions.
codetools This package is mainly advantageous in the code analysis in the R language.
cluster Mainly useful in the cluster analysis.
class This particular package deals with the functions that are necessary for the classification.

Fine, we have completed the second step too. Now the time has come to worry about the loading of the custom installed packages in the console. Here the R enables the flexibility for the user by providing them with the inbuilt command for the loading part. The functions in the library can be called thus can perceive the packages. The below command is used in identifying the packages that are loaded during the execution on the console:

search()

The obtained result when the above function is executed is as follows:

  • ".GlobalEnv"
  • "package:datasets"
  • "package:utils"

Next step is to install a new package in the R programming language. Mainly there are two ways in which the new packages can be installed in the R platform. One main way to directly install it from the CRAN directory. Whereas if we consider the other alternative method, here the programmer needs to download the custom packages as per his or her requirement and need. Later the downloaded packages can be manually installed in the computer system or PC.

Further let us start with the direct installation of the packages from the CRAN directory.

Installation of the packages directly from CRAN directly

The development team of the R programming language is taking several steps in assisting the users and making them comfortable while they work with the R environment. Therefore, they made several changes in the R platform such that the users or the programmers are enjoying the inbuilt feature of directly installing the packages with the following piece of code that is written on the console.

install.packages("Package Name")
 
# Installation of the package named "XML" into the R platform
install.packages("XML")

Well, the packages are installed directly with the above code. But when the user wishes to install them manually then the following code will help them in achieving their moto.

Installation of the packages manually

As part of this process the programmers or the users need to install the required packages manually. Later the downloaded packages need to be saved in the device in the zip file format.

The final step of this procedure is running the below code on the R console.

install.packages(file_name_with_path, repos = NULL, type = "source")

# To Install the package named "XML" which is manually installed 
# and saved in the local device in the zip file format.
install.packages("E:/XML_3.98-1.3.zip", repos = NULL, type = "source")

Load the Packages into the Library

Now we have seen the ways how to install the packages both directly and manually. The later step is to load the packages into the R library. To use the installed packages and to use them at the time of execution of the programs we need to load the packages on to the R environment.

The following code will enable the task of loading the packages into the R console is as follows:

library("package Name", lib.loc = "path to library")

# the task is to load the package named "XML" into the R console
install.packages("E:/XML_3.98-1.3.zip", repos = NULL, type = "source")

Thus, this particle article has covered the topics related to the usage of the packages in the R programming language.




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.