Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (62 sloc) 3.309 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#----------------------------------------------------------------------------------------------
# File: basic-package-management.R
# Date: 04-15-2012
# Author: Eric Nantz
# URL: https://github.com/thercast/package_admin/blob/master/basic-package-management.R
# Email: theRcast@gmail.com
# Purpose: Demonstrate how to install, browse, update, and search documentation for packages
# www.r-podcast.org/the-r-podcast-episode-5-basic-package-management
# License: Creative Commons Attribution-ShareAlike 3.0 Unported License
#----------------------------------------------------------------------------------------------

#---------------------------------------------------------
# How to see what packages are currently installed
#---------------------------------------------------------

# display new window with all packages currently installed
library()

# obtain matrix of all installed packages
package.matrix <- installed.packages()

# row names are the same as the package name, which is redundant
rownames(package.matrix) <- NULL

# convert this matrix into a data frame for processing
package.dataframe <- data.frame(package.matrix)

# if you only want columns of the package name and version
package.dataframe[, c("Package", "Version", "Built")]

# this returns the set of packages included in my default installation of R
# you may need to change the LibPath to reflect your installation
package.dataframe[package.dataframe$LibPath=="/usr/lib/R/library", c("Package", "LibPath", "Version")]
base.packages <- package.dataframe[package.dataframe$LibPath=="/usr/lib/R/library", c("Package", "LibPath", "Version")]

#--------------------------------------------------------
# What packages are loaded by default when launching R?
#--------------------------------------------------------

sort(getOption("defaultPackages"))
length(getOption("defaultPackages"))

#----------------------------------------------------------
# How to install the ggplot2 package
#----------------------------------------------------------

install.packages("ggplot2")

#-----------------------------------------------------------
# How to load the survival package into your R session
#-----------------------------------------------------------

library(survival)

#---------------------------------------------------------
# access help and vignettes for a package (if they exist)
#---------------------------------------------------------

help(package="survival")
browseVignettes(package="survival")

#--------------------------------------------------------
# how to unload a package from your session
# - Note: this does not uninstall a package permanently
#--------------------------------------------------------

detach(package="survival")

#----------------------------------------------------------
# How to uninstall a package (I rarely have to do this)
#
#----------------------------------------------------------

#remove.packages(package="foo")

#------------------------------------------------------------
# How to update packages: use update.packages function
# - Note: if you don't want R to prompt you to answer yes/no
# for each package eligible for an update, use the
# argument ask=FALSE
#------------------------------------------------------------

update.packages(ask=FALSE)

Something went wrong with that request. Please try again.