Hi everybody, how is it going.
In this tutorial we will learn to install
packages in R and I will be using famous and
widely used RStudio IDE for this purpose.
Although there are many ways that we can choose
from to install packages in R, but I will
restrict to only two methods because not only
these are easy but also solve the most purposes.
The first method is to use R script editor
on RStudio and on the script editor we can
type the native function install dot packages.
The moment we type install, Rscript editor
will start showing the suggested function
in the little popped up window.
Now, we either can select one of these functions
of our choice by mouse click or using keyboard
keys up and down arrows we can highlight the
function and then if we hit tab key, the highlighed
function will be selected and printed on the
script editor.
Since first suggested function is what I want,
so when I hit keyboard's tab key, the function
is completed and printed on the script editor.
Then in the selected function on script editor,
let's say we want to install famous ggplot
package, which is very widely used for beautiful
scientific plotting puprposes, so the moment
when we start typing this package name starting
with small letter 'g', the editor will start
showing the list of suggested packages who's
names start with 'g' and further typing another
letter 'g' will shorten the list of all the
packages which contain double g at the beginning
in their names as what we can see on the screen.
Just highlight the package which we are interested,
which in our case is 'ggplot2' and hit tab
key to complete the command on the script.
Please note, the name is a compulsory argument
that we need to pass to the native function
install dot packages for it to go 
to cran, search for the package name and if
found then download the package and install
it for any future use.
The other, although not compulsory, but in
my personal opinion, that you should do, it
so type the argument dependencies and set
its value to true as shown on the screen.
in word true, leter 't' should be typed as
capital letter otherwise the execution of
the code will through errors becase of teh
reason that R is case sensitive and True is
a reserve value within R.
By supplying second argument with a value
true means we are asking R to execute the
function to install the given package name
and also all of its dependencies.
The current package which is being installed
might have some functions which will depend
upon some other functions that are available
in other packages and hence we need to install
these as well to be able to perfectly work
on all the functionalities of this package
such as ggplot2 in our case.
Of course, we must be connected to internet
for 
these exercises.
Please note if the package is not available
of the cran, the function will return and
error message that the package is not available.
And this might happen in the case when the
package name we typed is not in the same format
as the package name on the cran.
Be advised and be carefull R is case sensitive.
so please take care of case sensitivity in
R.
So when we execute this code, either by hitting
the run button on RStudio, or by using short
cut keys control and enter, we can see that
the downloading and installing process starts
and finish in few seconds, depending upon
the internet speed we might have.
Although this method of installing the packages
looks easy but it gets complex when we want
to install multiple complex and hence the
second method, which we will see in a while,
becomes much handy for installing multiple
packages.
In this case, what we do is to look for the
packages tab in the right side bottom pane
and select this tab.
We can observe two tabs underneath this packages
tab.
One is for installing the new packages and
the other one is to update the currently installed
packages.
Since this tutorial is focused on installing
the packages, we will click on install tab
which will pop up 'install packages' window
with couple of options.
The first option is to install from and default
is set for CRAN repository.
Second option is where we type the package
names and each of these is separated by a
space.
third option is where these packages will
be installed and this is set as default location
from R's installation folder.
Last option is whether or not dependencies
need to be installed and if check box ticked,
like we are seeing on the screen, it will
install all the dependencies as it is set
to TRUE.
So let's type a couple of packages names supposing
that we need to install these, the first package
being dplyr which is a data wrangling package
from RStudio and another being caret which
is machine learning package in R.
Did you notice, when we type the package name,
how in the pop up list we get suggested by
the package names starting with the typed
letter or letters, we can just simple complete
the name on the box by selecting the relevant
name and hit tab or mouse click.
Next we provide a space after this name and
type the next package name, select it from
the list.
We can keep going this way of typing the list
of packages that we need to install and once
we are done , click on install button on this
popup window and wait until R finishes the
process of downloading and installing the
packages.
And That's it.
Congratulations, you have learned both the
methods of installing packages in R.
If you liked this video hit like button, and
also subscribe my channel, if you had not
done so far, so that you could get early notifications
of my future video releases.
Please do share this video with your friends
and colleague if you think this could help
them too and write in comment section below
what would you like to learn next.
See you in the next video.
Thank you and Happy Learning.
