(1) Explanatory Notes. The terms
package and library tend to be used interchangeably in R literature.
These terms refer to the compiled chunks of downloadable content
that developers and users create to increase the functionality
of R. These packages are what make R so attractive and so
capable. As an example, consider a fictional researcher, Dr.
Smarty Pants at the University of Jupiter’s Moon. Dr. Smarty
Pants wants to do a new statistical technique, called the
Wiz-Magic Decomposition analysis or WMD for short.
Unfortunately, because WMD is so new, Dr. Smarty Pants can not
find WMD in any of the existing statistical software available.
But, Dr. Smarty Pants is an R user. So, no matter who Dr. Smarty
Pants happens to be, where he or she happens to be, and no
matter what analysis he or she wants to perform; any individual,
like Dr. Smarty Pants, can write the code to perform the desired
analysis and send it to CRAN as a new package/library. CRAN will
then check it to make sure it works, has proper documentation,
and post it so that everyone can then use the newest most
advanced techniques, like WMD. You might think this process
takes a great deal of time, but it does not. As of this writing,
according to CRAN there are a few thousand packages available and it is
very likely that within a week, new packages will be available.
Remember, packages are not just new analysis; many are very
specific and may include better ways to do existing functions
(e.g. the AMORE package is described as “A MORE flexible neural
network package”). Furthermore, packages get updated to increase
functionality or ease of use. Keep in mind, all packages and all
new versions of R are completely free. So, you’re now likely
wondering, how do I get and use these packages? First, open R if
it is not already.
(2) To download and install packages,
you must have R open and you must have an internet connection.
Next, click on ‘Packages’ at the top of the R Console.

Take note
of the options here, you will likely use two of them most
frequently; ‘Install Package(s)…’ and ‘Update packages…’ The
base install of R comes with a few core packages. We are
interested in installing new/different packages; so, click on
‘Install Package(s)…’ You will then be prompted to select a CRAN
mirror site from which to download packages. I suggest selecting
a location close to the physical location of your computer. Once
you select a mirror site, you will be presented with an
alphabetical list of all the available packages. Before you
choose, please take a minute to read the following
paragraph.
The first time you install R on your
machine, it is recommended you install all the packages
available. This can take a few hours, but it is well worth it to
avoid searching for specific packages when you need them. An
easy way to do this is to select (‘left mouse click’) the
package listed at the top, then scroll down to the last package
listed and use ‘Shift – left mouse click’ to select the last
package; this will select all of them. You can let the computer
download and install them over night or during a long afternoon
spent in meetings or class.
(3) Now choose the Hmisc package;
then click ‘OK’. You will notice in the R Console, packages will
be downloaded first, in the appropriate location, and then they
will be installed—which gives the message “package ‘Hmisc’
successfully unpacked and MD5 sums checked”. You will also
notice a message telling you where the temporary file is located
which contains the downloaded package(s). You could delete this
temp file after all the packages are installed, but it can be
useful to take note of it in the unlikely event your internet
connection gets interrupted during download. If your connection
is interrupted, you can still install the packages that were
downloaded successfully by clicking on ‘Packages’ then ‘Install
package(s) from local zip files…’.
(4) Updating packages. Now that you
have the Hmisc package installed, you need to update. This may
seem silly because you just installed it, but remember with a
few thousand
packages it becomes time consuming to update all of them when a
new version of R is released and you may not have the most
recent version of a package. So, click on ‘Packages’ and then
‘Update packages…’. If you have not done so already in this
session of R (e.g. if you closed R and just re-opened it), you
will need to choose a mirror site. You will then be prompted
with a list of packages that can be updated. I generally choose
all the available packages to make sure I have the most
functionally up-to-date software. Once you choose which/all
packages, click ‘Ok’ and you will notice a similar series of
messages in the console showing the download and install of the
updated packages.
We will be using the Hmisc package/library
in the next set of
notes on using a package/library; but in future
notes/tutorials we will need a variety of package—again, it is
highly recommended you download and install all of the available
packages.