By You install a package in R with the function — wait for it — install.packages. Who could’ve guessed? So, to install the fortunes package, for example, you simply give the name of the package as a string to the install.packages function. The fortunes package contains a whole set of humorous and thought-provoking quotes from mailing lists and help sites. You install the package like this: install.packages('fortunes') R may ask you to specify a CRAN mirror. Because everyone in the whole world has to access the same servers, CRAN is mirrored on more than 80 registered servers, often located at universities. Pick one that’s close to your location, and R will connect to that server to download the package files.
![Package Package](/uploads/1/2/5/3/125384373/226534943.png)
In RStudio, you can set the mirror by choosing Tools→Options. Next, R gives you some information on the installation of the package: Installing package(s) into 'D:/R/library'(as 'lib' is unspecified). Opened URL downloaded 165 Kb package 'fortunes' successfully unpacked and MD5 sums checked. It tells you which directory (called a library) the package files are installed in, and it tells you whether the package was installed successfully. Granted, it does so in a rather technical way, but the word successfully tells you everything is okay. After a while, you can end up with a collection of many packages. If R loaded all of them at the beginning of each session, that would take a lot of memory and time.
![Disk Disk](http://genetics.emory.edu/labs/epstein/software/BiasedUrn/R-console-packages-local.png)
Installing R Packages. Installing R Packages. Jeffrey Leek Johns Hopkins Bloomberg School of Public Health. When you download R from the Comprehensive R Archive Network (CRAN), you get that ``base' R system. Installing an R Package. Packages can be installed with the install.packages() function in R.
So, before you can use a package, you have to load it into R by using the library function. You load the fortunes package like this: library(fortunes) You don’t have to put single quotation marks around the package name when using library, but it may be wise to do so.
Now you can use the functions from this package at the command line, like this: fortune('This is R') The library is the directory where the packages are installed. Never, ever call a package a library. That’s a mortal sin in the R community.
Take a look at the following, and never forget it again: fortune(161) You can use the fortune function without arguments to get a random selection of the fortunes available in the package. It’s a nice read. If you want to unload a package, you’ll have to use some R magic.
The detach function will let you do this, but you have to specify that it’s a package you’re detaching, like this: detach(package:fortunes).
Installing Packages from CRAN Packages distributed via the Comprehensive R Archive Network (CRAN) extend the functionality of R. If you have chosen to interact with R through RStudio, then these directions explain how to install package from within RStudio.
If you have not chosen to use RStudio, then goto these directions for installing packages within R for. Open RStudio.
( If RStudio is not installed, then follow these directions to install RStudio for or.). In the lower-right pane of RStudio, select the Packages tab and the Install button.
Press Install. RStudio should now install these packages plus all packages that these depend on.
This may take several minutes and you should see several “package ‘xxx’ successfully unpacked and MD5 sums checked” messages. Depending on your priveleges on your machine, you may get a warning at this point about a library that “is not writable” and then be prompted with a dialog box asking “Would you like to use a personal library instead?” You can select Yes on this dialog box. A second dialog box will appear with a question that starts with “Would you like to create a personal library.” You can also select Yes on this dialog box. Installing FSA and FSAdata The FSA and FSAdata packages are distributed on CRAN and can be installed using the directions above.