HomeОбразованиеRelated VideosMore From: MarinStatsLectures-R Programming & Statistics

How to Install Packages in R (R Tutorial 1.12)

546 ratings | 173279 views
Learn how to find and install packages for R, using the "install.packages" command or menu options in RStudio. This video is a tutorial for programming in R Statistical Software for beginners. Here is an overview of the topics discussed in this video. You can click on the time stamp to jump to the specific topic. 0:00:12 what are packages in R and why use them 0:00:46 how to access help menu for packages in R when using the "install.packages" command 0:01:00 how to install packages in R using "install.packages" command when you know the name of the package 0:01:53 how to install packages in R using "install.packages" command when you don't know the name of the package 0:02:48 how to load the library of commands and functions for a package in R 0:03:17 how to access and download packages for R from 'R-project.org' website 0:04:30 how to access help menu for a specific package in R 0:04:57 how to remove a package from R using "remove.packages" command 0:05:11 how to install packages in R using the menus in RStudio
Html code for embedding videos on your blog
Text Comments (123)
Sharifah Diana (27 days ago)
epiR doesn't exist in Malaysia so i need to download it from a different country source. But you didn't show us HOW to download it off the r project website!!
rjanyolivia (3 months ago)
thank you again, ur tutorial erally help me and save my life
sumit kumar (4 months ago)
What should I do if a package I need has been removed from the CRAN repository but it's present in archive?
bran cliff (4 months ago)
Mke your videos are incredibly usefull an easy ! thanks a lot !!
Katherine G Carpio (8 months ago)
how can I fix this? > install.packages("ggtplot2") Warning in install.packages("ggtplot2") : 'lib = "C:/Program Files/R/R-3.4.3/library"' is not writable Error in install.packages("ggtplot2") : unable to install packages >
Alex (1 month ago)
Did you figure it out? im getting the same thing
Morten Espelid (8 months ago)
Maybe your user does not have the rights to write to that folder. So maybe using user with more rights or give your user the rights will help...?
Deo Kumar (1 year ago)
Hi Marin, I need to install package tabulizerjars and tabulizer in RStudio on Ubuntu16.04 for reading pdf in tabular form. i have tried many times to install it. but unfortunately i am unable to install it. please help if you can. i am beginner in R, Thank you.
Saddam M. (1 year ago)
Than you very much for your help full lecture series. Can you please make a video on how to extract Netcdf file? Thank you.
ThePowerExcess (1 year ago)
Thank you for your video, very informative. But you could drop the intro. How would one click on a 'how to install packages in R' video and not know what R or a package is? I
Eucharista Martin (1 year ago)
Hi Marin, I installed the package. But its downloaded in the local temp folder. Will this work ? > install.packages("IPSUR") Installing package into ‘C:/Users/eucha/OneDrive/Documents/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.4/IPSUR_1.5.zip' Content type 'application/zip' length 1626548 bytes (1.6 MB) downloaded 1.6 MBpackage ‘IPSUR’ successfully unpacked and MD5 sums checkedThe downloaded binary packages are in  C:\Users\eucha\AppData\Local\Temp\Rtmp2ZD06P\downloaded_packages >
abhishek soni (1 year ago)
The same is popping up with me, Marin can you give us a solution for this?
chirag singal (1 year ago)
hey sir am using windows and am not able to install packages what should i do?
31415926535equalspi (1 year ago)
Thanks, exactly what I needed in first 2 minutes.
Yan Xu (1 year ago)
I am a beginner on programming. I just follow the instructions to install RCurl and XML packages. But every time i close the R, next time he ask me to re-install again.
Toka Zhu (1 year ago)
I should have realized you are Canadian. Thanks so much!
Zach Miller (1 year ago)
Here because of college statistics -_-
Safiya Abubakar (1 year ago)
Hi Mike, thank you for these awesome R studio videos. Interestingly enough, most of the code that did not work for me I was able to spot my mistakes using you online tutorials. May I know if you have tutorials on error bars on barplots? Thank you for you help.
Yiyi Hu (1 year ago)
This video saved my life!!! Thank you so much!!!
sujatha gangireddy (2 years ago)
sir your videos excellent when will you start videos on how to work on packages like plyr,dplyr please sir do
Mohsin Waqas (1 year ago)
Sir, I also want to work on these packages. kindly work on it.
thanks +sujatha gangireddy , we may work on those at some point, but i the short term, we have a few other topics we're working on.
Shivam Gupta (2 years ago)
when i use command "install.packages()" in my console window.I gt this error "Error in install.packages : argument "pkgs" is missing, with no default". So please help me..?
Carlos Linares (2 years ago)
thanks I was having the same problem
great to hear +Jay Mehta ! yeah, that's the things with software, it is constantly being updated, so small changes occur...but the heart of the software is always the same, so apart from some aesthetics, the concepts and syntax will remaining tact
Jay Mehta (2 years ago)
Thanks a lot, Marin. I was struggling with the same and thought to see the comments if someone else was facing the same problem. The tutorial is great. I see some changes as I am using RStudio Version 0.99.903. But still extremely helpful. Appreciate it.
Hi +Shivam Gupta , R no longer displays a list of all packages when you enter that command. if you know the name of the package you want to install, then just enter *install.packages("PackageName")* , and if you don't know the name, you can go to www.r-project.org, click on "CRAN", select your mirror/location and then you will find a link to "Packages", and there, you will can find a list of all of the packages for R (or at least all of the packages that are in the CRAN repository).
ashish anand Jha (2 years ago)
hey Marin, thanks for awesome video, i have a doubt when i try to download epiR package is not available for version R 3.3.1..so how can i download it?
pink pearl (2 years ago)
Saved my bacon again! Great work!
Mohsin Waqas (1 year ago)
install.packages("dplyr") Installing package into ‘C:/Users/Mohsin/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/dplyr_0.5.0.zip' Content type 'application/zip' length 2520548 bytes (2.4 MB) downloaded 2.4 MB package ‘dplyr’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\Mohsin\AppData\Local\Temp\Rtmp2loVfQ\downloaded_packages > library(dplyr) Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union Warning message: package ‘dplyr’ was built under R version 3.2.5
good to hear +pink pearl !
nikkixxxo (2 years ago)
Hi, I am a beginner in R, and am trying to install the 'Dunn's test' package. I have downloaded the .tar.gz and the zip file for this package from https://cran.r-project.org/web/packages/dunn.test/, but when I try to install it, I keep getting the same error message : Error in normalizePath(path.expand(path), winslash, mustWork) : path[1]="\\data.adir.hull.ac.uk\home4\421\421134\R\win-library\3.3": The system cannot find the file specified I had originally got the files saved on a memory stick, but after seeing this messaged I copied them to the folder that it is looking in, but still the same error message is all I get. Any ideas?! Thanks!
Hi +nikkixxxo , the easiest way to install a package is directly thru R (or RStudio), and not to tray and download the zip file, or something like that. in R (or RStudio) if you enter the command *install.packages(dunn.test)* this should take care of installing the package for you (you may need to complete a few prompts along the way, but it should be pretty straightforward). you will then have to load the library for the package to use any of the command in it...just enter the command *library(dunn.test)* , and you should be good to go. in RStudio, you can also download packages using the menus, so you can try this as well if you're having difficulty doing it with commands. in the *Tools* menu you should see an option for *Install Packages...* , and if yu select this, you should be able to install the package using the menu prompts.
Keny Maciel (2 years ago)
very good
good to hear!
Keny Maciel (2 years ago)
+MarinStatsLectures ... You helped me so much. I had successfully COLNAMES. Thank you...
Hi +Keny Maciel da Silva , there are a few ways to do that.  if you've already attached the data, and you want to just "rename" that one variable, you can just assign it to X, e.g. *X <- Varia...* .  You can also reassign all of the column names for the entire dataset using the colnames command.  Suppose your data (named Data) has 3 columns/variables, and you want to rename them to be "X1", "X2" and "X3", you can use: *colnames(Data)* *<-* *c("X1", "X2", "X3")*
Keny Maciel (2 years ago)
+MarinStatsLectures.. Can you help me, it's very simple, for me of course :). How I can change the column name? EX: My column is "VariaÃ.Ã.o....", I need to change for X. Thank you so much!!
thanks +Keny Maciel da Silva !
sinda aicha (2 years ago)
Thank you very much.. I was learning R by myself and that helped me pretty much Good continuation
cochinodos (2 years ago)
It's worth noting that this video series qualifies as awesome ;-) Thanks a lot Mike!
Thank you +cochinodos !
Z Dax (3 years ago)
your a fellow Canadian! really good quality videos, short to the point videos.
thanks +Ev Erlton !
ARNAB ROY (3 years ago)
How do I set proxy setting for installing R packages?
Hi +ARNAB ROY , I'm not sure on this error exactly, but it sounds like you weren't able to access where the package is stored.  id suggest to try changing the mirror you use, and see if you are able to download the package from a different source.
ARNAB ROY (3 years ago)
+MarinStatsLectures Below is the error it is showing: install.packages("ggplot2") Warning in install.packages : cannot open: HTTP status was '407 Proxy Authentication Required' Warning in install.packages : cannot open: HTTP status was '407 Proxy Authentication Required' Warning in install.packages : unable to access index for repository http://ftp.iitm.ac.in/cran/src/contrib Warning in install.packages : cannot open: HTTP status was '407 Proxy Authentication Required' Warning in install.packages :
Hi +ARNAB ROY , if you've already installed a package once, R probably won't ask you again for a mirror/location...so it may not be asking you because it already knows. but anyway, here's how you can set/change the "mirror/location" in Studio. go to the *RStudio Menu* and from there select *Preferences* and then you should see an option for *Packages*...select that. and inside that menu, you should see an option for *CRAN Mirror (Change)*. select to change that, and select the location you like (usually the one nearest to you....or, select the o-cloud option)
Tanushree Dutta (3 years ago)
As I tried it I got the following statement from R.Please help me out in understan ding what it means and how to rectify it. Warning in install.packages :   'lib = "C:/Program Files/R/R-3.2.1/library"' is not writable
Morten Espelid (8 months ago)
Maybe your user does not have the rights to write to that folder. So maybe using user with more rights or give your user the rights will help...?
Hi +Tanushree Dutta , i'm not sure what the error is, and it's hard to troubleshoot some of these errors from a distance. it sounds like the error is saying that you don't have the 'permissions' to save things into that folder on your computer. you will probably have to change read/write privileges on your computer while logged in as administrator.
ravikar kumar (3 years ago)
install.packages() Error in install.packages : argument "pkgs" is missing, with no default.     I am trying to install Quandl.   and I am getting error  package ‘bitops’ successfully unpacked and MD5 sums checked package ‘xts’ successfully unpacked and MD5 sums checked Error in install.packages : missing value where TRUE/FALSE need     Please help.
Paweł Kacprzak (2 years ago)
Thanks a lot for a clarification!
Hi +Paweł Kacprzak , in older versions of R that was the case, but in newer versions, it no longer returns a list of available packages.  to view all packages, you will have to go to www.r-project.org, then click on "CRAN" and from there select your mirror/location, and then you can click on "packages", and there you will find a list of all available packages.
Paweł Kacprzak (2 years ago)
+MarinStatsLectures In the video you showed that install.packages() can be used without arguments and then let us browse packages in GUI.
ravikar kumar (3 years ago)
Thanks. 
Hi +ravikar kumar , it's always hard to trouble shoot an error from a distance.  id suggest trying the following, which may solve the problem.  clear the workspace in RStudio (by clicking on the broom icon in the top right corner), and then exit RStudio.  re-open RStudio and try installing it again.  but this time, try using the menus to do this.  go to "TOOLS", and then select "INSTALL PACKAGES", and follow the menus from there.  there is a good chance that this will solve the problem, but as i said, it's hard to tell without being able to actually work on your computer to try and figure out why you're getting the error message.  good luck!
Barbara Bustamante (3 years ago)
Thank you u for your great job!
you're welcome +Barbara Bustamante !
Shubhangi Gupta (3 years ago)
Please help me!! I'm getting this error after installing the package.. > help("install.packages") >  > install.packages("epiR") Installing package into ‘C:/Users/SIMMI/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/epiR_0.9-62.zip' Content type 'application/zip' length 257044 bytes (251 KB) downloaded 251 KB package ‘epiR’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\SIMMI\AppData\Local\Temp\Rtmp4gAVL6\downloaded_packages i don't know what am I supposed to do now please help me
you're welcome +Shubhangi Gupta 
Shubhangi Gupta (3 years ago)
+MarinStatsLectures Thank you It's working now :)
Hi +Shubhangi Gupta , it looks like you have downloaded and installed it correctly (you can see it says there "downloaded" as well as "package epiR successfully unpacked...'. all you need to do now is type *library(epiR)* to load the library into R, and you can start working with the package.
Alexander (3 years ago)
Can you use Sublime Text 3 with R?
I'm not sure if you can +Stealth_Bomber_B2 . if you try it out and get it working with R, id love to hear about it!
Anusha Pippari (3 years ago)
Hi,  Thanks for the amazing videos, these are indeed very helpful. I have a question, do we always have to use the mirror closest to our location? If I'm from India, how is different if I use 0-cloud mirror instead of the one which is close to my location?
Mohsin Waqas (1 year ago)
library(tidyr) Attaching package: ‘tidyr’ The following object is masked from ‘package:magrittr’: extract Warning message: package ‘tidyr’ was built under R version 3.2.5
Anusha Pippari (3 years ago)
Thanks! 
Thanks +Anusha Pippari ! the "0-cloud" mirror is something new to R...i believe it acts as a mirror close to you, but i can't claim to be an expert on exactly what it is. but i believe that selecting that should work in place of the closest mirror to you.
Helio Filho (3 years ago)
thanks a lot
you're welcome +Helio Filho !
Helio Filho (3 years ago)
thaks a lot
you're welcome +Helio Filho !
Alvin R (3 years ago)
This is exactly what I needed to know!! Thanks Mike for your excellent Tutorial.
You're welcome +Alvin R
Roy Yali (3 years ago)
Disculpe, yo he intentado instalar los paquetes "rgdal" y "RCurl" en R y no los reconoce y cargan pero no se instalan, eso me pasa en Linux; en Windows los he instalado y me corren normal. Alguna idea para solucionar esto, gracias
Hi +Roy Yali , it's difficult to troubleshoot these things from a distance.  in theory, if you are typing *install.packages("rgdal")* in the command line in R, and selecting a "mirror" that is close to you, it should be able to install the package fine.  typing *library(rgdal)* should help confirm if the package was installed correctly or not.  beyond that, I'm not sure what else may be the issue.  good luck.
Anvika Kumar (3 years ago)
I have completed my assignments watching all of ur videos . U hav explained it so well, truly amazing.....
Thanks +Anvika Kumar , we appreciate that!
Anvika Kumar (3 years ago)
Actually sir i tried the other method as in downloading through the website. The packages have got downloaded by i dnt noe how to proceed further.
Anvika Kumar (3 years ago)
sure sir. Thank u for ur help.
Hi +Anvika Kumar , it sounds like you're taking the right steps.  maybe you just have to do it when you have a better wifi connection.  and doing it directly through R is gonna be easier than downloading the package separately.  good luck!
Anvika Kumar (3 years ago)
Yes sir I had tried that firstly but i guess due to slow wifi connection the packages are not getting downloaded. I am not able to proceed after choosing the country location in the CRAN .
have you tried what i mentioned in my last response?  you haven't mentioned if you did that or not, but doing as i mention to you below will solve your problem.  in R, first you should install the package by typing *install.packages("tseries")* in the command line of R.  after its installed, you must load the library in an R session if you want to use the commands in the package: *library(tseries)*
Anvika Kumar (3 years ago)
Sir, I have installed packages from the r-projects.org , but when i opened help(package = tseries) which i had downloaded it is showing no such package available. Kindly help me with this.
Hi +Anvika Kumar , that error is coming up because the package hasn't been installed.  i would suggest to try installing the package again *install.packages("tseries")* .  you can load the library afterwards to make sure it was installed correctly using *library(tseries)* .  the help menu should work once it has been installed:  *help(package=tseries)*
MaxCL (3 years ago)
Hi again. I get the following error using install.packages("epiR") from a local mirror: ------------------ > install.packages("epiR") trying URL 'http://dirichlet.mat.puc.cl/bin/macosx/mavericks/contrib/3.1/epiR_0.9-62.tgz' Content type 'application/x-gzip' length 259774 bytes (253 Kb) opened URL ================================================== downloaded 253 Kb tar: Failed to set default locale The downloaded binary packages are in /var/folders/7k/4dgfz_jn5c753vclwqfzgb5m0000gn/T//RtmpSCCLjY/downloaded_packages --------------------- How can I get this right? Thanks in advance
MaxCL (3 years ago)
Thanks again! You are right. It is working.
Hi +Maximiliano Contreras , it looks like it has downloaded correctly (i see there is says "the downloaded packages are in...").  have you tried loading the library using *library(epiR)*, and then try to use any of the commands in the package?  id suggest to check that, as from what i see here, it looks like you have successfully installed the package.
Keith Win (3 years ago)
Hello Marin, when I tried to choose which package to install, i got below error.  But I was able to install epiR package.   TY.  install.packages() Error in install.packages : argument "pkgs" is missing, with no default
Hi +bigholmes31 , nope it doesn't really matter as long as it was installed and you're able to use the package.  it's most likely because you've installed a package before, and selected a mirror then, and R remembers that and uses that as the default mirror.
bigholmes31 (3 years ago)
+MarinStatsLectures Hey Mike, when I did the install.packages("epiR"), I did not receive a list of mirrors, but the package was indeed installed.  Is there any particular reason for this? Does it matter? Thanks!
Hi +Keith Win , yeah in older versions of R, typing install.packages() would return a list of all packages, but newer versions of R do not do that.  to see a list of all packages, you have to go to the R-project website, and look at the list of all packages there.
Maya (3 years ago)
Thank you SO much for all your efforts. You just made my life a whole lot easier. THANK YOU THANK YOU THANK YOU.
You're welcome +Maya Och , glad we could help!
Madiha Aslam (3 years ago)
 Thank you so much for the most helpful tutorials on R. I would like to make a request if you can come up with RHadoop Tutorials. Or you can explain how to install hadoop and show some map reduce jobs using R. You indeed have the best knowledge of R. 
Madiha Aslam (3 years ago)
Thank you so much . That's a great help indeed. 
Thanks +Madiha Aslam !  i know Hadoop in concept, but not well enough to make any quality tutorials about using it with R.  but you can check out the following resource, as they have some pretty good material here: http://www.r-bloggers.com/search/hadoop
maxpiller000 (3 years ago)
I would like to thank u very much for your efforts ! You just make life easier for people eager for learning. Thanks again and may allah bless u !
maxpiller000 (3 years ago)
+MarinStatsLectures You are most welcome Brother :) Big Thanks from Morocco :)
Thanks +maxpiller000 , we really appreciate that!
sanjeeb kumar (4 years ago)
Hi while doing install.packages() Below error is throwing..Can you help me out. Error in install.packages : argument "pkgs" is missing, with no default
+greatsea you have surely come across more contradictory things in your life haven't you? one thing i didn't make completely clear in my reply above is that the video was made using an older version of R (as i created the video about a year ago).  in some of the older versions of R, you will get a pop-up of the available packages (as you see happen in the video).  in newer versions of R, this is not the case, and you will have to look at the website www.r-project.org to see a list of available packages (i also show this in the video).
greatsea (4 years ago)
+MarinStatsLectures But did you not say that you can leave the parens blank and R will return to you the packages that are available.  Come to think of it, I can think of nothing more contradictory than what you said in the video and what you said in the comment.
Hi +sanjeeb kumar , the error message is because you are using the install.packages command to install a package, but you are not giving any package name for R to install.  In the video i show that typing *install.packages()* will return a list of available packages, but this was in an older version of R, and newer versions of R do not return the pop-up menu of available packages.  For example, use *install.packages("car")* to install the "companion to applied regression, car" package.  or, you would use *install.packages("epiR")* to install the epic package.  You have to find the package you want to install, and then insert the package name inside that command, and make sure the package name is inside " ".  You can find a list of available packages by checking www.r-project.org.  i show where this list can be found in the video.
dhanunjai gandavarapu (4 years ago)
I am not getting the packages names in rstudio andI getting the packages in R prg but not in r studio. How to change the disk drive in R  to store the working directory
Pratik Sawant (4 years ago)
Great work man, really enjoyed your videos and I have learned a lot through these videos. Thank you. :)
Thanks, we've put a lot of work into them!  Good to hear you've found them helpful.
E-ANDRES RICO-P (4 years ago)
Hello Great tutorial, I´m tryin to install the package RGDA but i have this                 lib = "C:/Program Files/R/R-3.0.2/library"' is not writable. I dont know what to do. Any help please. Thank you!!!
Hi +E-ANDRES RICO-P , thanks for watching!  its always hard to trouble-shoot these things from a distance...but here's a few things that may help you get it sorted out.  first off, there is not an R-package called "RGDA", so that may be it.  there is a package called "rgdal", so maybe that's the one you wanted?  also, package names are case-sensitive, so using caps or lowercase will make a difference.  about half-way through the video, i show how you can find the entire list of all packages available in R, so you can check that out to make sure you are using the correct name of the package you want to install.  hope that helps...good luck.
SoHoTandCool (4 years ago)
hello Marin, thanks for the videos. i have a quick question / problem. the epiR package isn't available for the latest R. how can i follow along with your lectures now? thanks. 
Hi +SoHoTandCool , i've checked and the eipR package has been updated for the latest version of R and should be available (i just updated R and re-installed epiR without any trouble).  When installing the package, you should make sure you have " around the package name, and also that the R is capital for this package.  the command will be *install.packages("epiR")*  You can also just directly install it using the menus in Rstudio.   As a side note, i only use the epiR package in Tutorial 4.8 (Relative Risk, Odds Ratios and Risk Difference), so you wont need it to do any other things in R that i show, apart from these specific topics.
Walt Bismarck (4 years ago)
Hi, thanks for making these videos. Sorry for not able to make it work, but I tried installing packages as instructed and my RStudio would just freeze up. No Cran Mirror pop-up or anything. It does work on the pure RGui, but not RStudio. Do you have any idea what might be causing the issue?
Hi +Al Rez, thanks for watching!  So, it sounds like you are at least able to install packages using the command line, just not the menus in RStudio? From a distance, its difficult to troubleshoot what the issue may be.  I do know that  once you select your CRAN mirror in R, it will remember your location, and you likely wont have to enter that again (whether using the command-line or the RStudio menus).  It may just be the case that you've already specified your mirror, and R no longer asks for it.  You can change your default mirror using the RStudio "preference" menu.  You can see the net video ("Customizing R Studio", tutorial 1.11) to see how to do this.
Hi Josh, I believe the 'mirror' you are using is the NiCS in Oak Ridge, TN. When I try to access this mirror, I am unable to...i believe there is some issue with that particular mirror and maybe their server is down or something. I'm also not able to install the "psych" package using that mirror. You should try using another mirror close to you, such as the one in TX or MO. Those ones both worked for me. Good luck, let us know how it goes!

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.