Sie sind auf Seite 1von 3

4/8/13

R FAQ: How can I manage R packages?

Help the Stat Consulting Group by

giving a gift

stat > r > faq >

You're not lost. We have a new look but the same content.

R FAQ How can I manage R packages?


R is a statistical software made up of many user-written packages. The base version of R that is downloaded allows the user to get started in R, but anyone performing data analysis will quickly exhaust the capabilities of base R and need to install additional packages. Here are some basic commands for managing R packages.

Which packages do I already have?


To see what packages are installed, use the installed.packages() command. This will return a matrix with a row for each package that has been installed. Below, we look at the first 5 rows of this matrix.

i n s t a l l e d . p a c k a g e s ( ) [ 1 : 5 , ] P a c k a g e L i b P a t h V e r s i o n P r i o r i t y b a s e " b a s e " " C : / P R O G R A ~ 1 / r / R 2 1 1 ~ 1 . 1 / l i b r a r y "" 2 . 1 1 . 1 "" b a s e " b o o t " b o o t " " C : / P R O G R A ~ 1 / r / R 2 1 1 ~ 1 . 1 / l i b r a r y "" 1 . 2 4 2 "" r e c o m m e n d e d " c a r " c a r " " C : / P R O G R A ~ 1 / r / R 2 1 1 ~ 1 . 1 / l i b r a r y "" 2 . 0 2 " N A c l a s s " c l a s s " " C : / P R O G R A ~ 1 / r / R 2 1 1 ~ 1 . 1 / l i b r a r y "" 7 . 3 2 " " r e c o m m e n d e d " c l u s t e r" c l u s t e r "" C : / P R O G R A ~ 1 / r / R 2 1 1 ~ 1 . 1 / l i b r a r y "" 1 . 1 2 . 3 "" r e c o m m e n d e d " D e p e n d s I m p o r t sL i n k i n g T o b a s e N A N A N A b o o t " R( > =2 . 9 . 0 ) ,g r a p h i c s ,s t a t s " N A N A c a r " R( > =2 . 1 . 1 ) ,s t a t s ,g r a p h i c s ,M A S S ,n n e t ,s u r v i v a l "N A N A c l a s s " R( > =2 . 5 . 0 ) ,s t a t s ,u t i l s " " M A S S " N A c l u s t e r" R( > =2 . 9 . 0 ) ,s t a t s ,g r a p h i c s ,u t i l s " N A N A S u g g e s t s E n h a n c e sO S _ t y p eL i c e n s e B u i l t b a s e N A N A N A " P a r to fR2 . 1 1 . 1 "" 2 . 1 1 . 1 " b o o t " s u r v i v a l " N A N A " U n l i m i t e d " " 2 . 1 1 . 1 " c a r " a l r 3 ,l e a p s ,l m t e s t ,s a n d w i c h ,m g c v ,r g l "N A N A " G P L( > =2 ) " " 2 . 1 1 . 1 " c l a s s N A N A N A " G P L 2|G P L 3 " " 2 . 1 1 . 1 " c l u s t e rN A N A N A " G P L( > =2 ) " " 2 . 1 1 . 1 "
From this output, we will first focus on the Package and Priority columns. The Package column gives the name of the package and the Priority column indicates what is needed to use functions from the package.

If Priority is "base", then the package is already installed and loaded, so all of its functions are available upon opening R. If Priority is "recommended", then the package was installed with base R, but not loaded. Before using the commands from this package, the user will have to load it with the library command, e.g. library(boot). If Priority is NA, then the package was installed by the user, but not loaded. Before using the commands from this package, the user will have to load it with the library command, i.e., library(car).

Have I installed a specific package?


Sometimes, you might want to know if you have already installed a specific package. Let's say we want to check if we have installed the package "boot". Instead of checking the entire list of installed packages, we can do the following. a < i n s t a l l e d . p a c k a g e s ( ) p a c k a g e s < a [ , 1 ] i s . e l e m e n t ( " b o o t " ,p a c k a g e s ) [ 1 ]T R U E

How can I add or delete packages?


Any package that does not appear in the installed packages matrix must be installed and loaded before its functions can be used. A package can be installed using install.packages("<pack age name> "). A package can be removed using remove.packages("<pack age name> ").

What packages are available?


The list of available R packages is constantly growing. The actual list can be obtained using available.packages(). This returns a matrix with a row for each package.

p< -a v a i l a b l e . p a c k a g e s ( ) d i m ( p ) [ 1 ]2 5 5 3 p [ 1 : 5 , ]
www.ats.ucla.edu/stat/r/faq/packages.htm 1/3

1 2

4/8/13

R FAQ: How can I manage R packages?

P a c k a g e V e r s i o nP r i o r i t yD e p e n d s A C C L M A " A C C L M A " " 1 . 0 " N A N A A D G o f T e s t " A D G o f T e s t " " 0 . 1 " N A N A A E R " A E R " " 1 . 1 7 "N A " R( > =2 . 5 . 0 ) ,s t a t s ,c a r( > =2 . 0 1 ) ,F o r m u l a( > =0 . 2 0 ) , A G S D e s t " A G S D e s t " " 1 . 0 " N A " l d b o u n d s " A I C c m o d a v g" A I C c m o d a v g "" 1 . 1 1 " N A N A L i n k i n g T o A C C L M A N A A D G o f T e s t N A A E R N A A G S D e s t N A A I C c m o d a v gN A S u g g e s t s A C C L M A N A A D G o f T e s t N A A E R " b o o t ,d y n l m ,e f f e c t s ,f o r e i g n ,i n e q ,K e r n S m o o t h ,l a t t i c e , \ n M A S S ,m l o g i t ,n l m e ,n n e t ,n A G S D e s t N A A I C c m o d a v g" l m e 4 ,M A S S ,n l m e ,n n e t " E n h a n c e sO S _ t y p eL i c e n s e F i l eR e p o s i t o r y A C C L M A N A N A " G P L 2 " N A " h t t p : / / c r a n . s t a t . u c l a . e d u / b i n / w i n d o w s / c o n t r i b / 2 . 1 1 A D G o f T e s t N A N A " G P L " N A " h t t p : / / c r a n . s t a t . u c l a . e d u / b i n / w i n d o w s / c o n t r i b / 2 . 1 1 A E R N A N A " G P L 2 " N A " h t t p : / / c r a n . s t a t . u c l a . e d u / b i n / w i n d o w s / c o n t r i b / 2 . 1 1 A G S D e s t N A N A " G P L( > =2 ) " N A " h t t p : / / c r a n . s t a t . u c l a . e d u / b i n / w i n d o w s / c o n t r i b / 2 . 1 1 A I C c m o d a v gN A N A " G P L( > =2) "N A " h t t p : / / c r a n . s t a t . u c l a . e d u / b i n / w i n d o w s / c o n t r i b / 2 . 1 1
These first five (of 2,553) available packages illustrate that the package names are often acronyms and rarely reveal what the package functions do. A list of the packages available through CRAN including a short package description can be found at CRAN's Contributed Packages page.

What functions and datasets are in a package?


It is easy to access some quick documentation for a package from R with the help command. This opens an R window with package information followed by a list of functions and datasets.

h e l p ( p a c k a g e = " M A S S " )

Once a package is loaded, the help command can also be used with all functions and datasets listed here, e.g. help(Null). How to cite this page Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.

www.ats.ucla.edu/stat/r/faq/packages.htm

2/3

4/8/13
I D R E R E S E AR C H T E C H N O L O G Y G R O U P

R FAQ: How can I manage R packages?

High Performance Computing

GIS Mapshare Visualization 3D Modeling Technology Sandbox Tech Sandbox Access Data Centers

Statistical Computing Classes Conferences Reading Materials IDRE Listserv IDRE Resources Social Sciences Data Archive

High Performance Computing Statistical Computing GIS and Visualization

Hoffman2 Cluster Hoffman2 Account Application Hoffman2 Usage Statistics UC Grid Portal UCLA Grid Portal Shared Cluster & Storage About IDRE

ABOUT
2013 UC Regents

CONTACT

NEWS

EVENTS

OUR EXPERTS

Terms of Use & Privacy Policy

www.ats.ucla.edu/stat/r/faq/packages.htm

3/3

Das könnte Ihnen auch gefallen