Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

R Programming

R PACKAGES AND HELP


This slide deck is only for educational purpose.
Disclaimer
 This presentation is purely for academic purpose and does not carry any
commercial value.

 All images used in this presentation are property of respective image holders.
Images are used only for indicative purpose and does not carry any other
meaning. 2
PACKAGES
Check R Version

R.Version() provides detailed

EXAMPLE
> R.version()
information about the version
> version
of R running.
Packages and Why?
R functions and datasets are stored in packages.
Contents of packages are available only when datasets are loaded.

Packages are required –


 To increase efficiency of memory as packages are used as and
when required
 To aid package developers, who are protected from name
clashes with other code.
Available R Packages

# Get list of packages in the console


> available.packages()
EXAMPLES

# View list of packages in the console


> View(available.packages())

# Get summary of packages


> summary(available.packages())
Get List of Installed R Packages
List of Packages with Row Names List of Packages without Row Names

# Get list of packages # Get list of packages


> installed.packages() > installed.packages()
EXAMPLES

EXAMPLES
# View list of packages # View list of packages
> View(installed.packages()) > View(installed.packages())

# Get summary of packages # Get summary of packages


> summary(installed.packages()) > summary(installed.packages())
Install New R Packages

# Install single package


EXAMPLES

> install.packages(‘cluster')

# Install multiple packages


> install.packages(c("ncdf4", "RNetCDF")
Update R Packages

EXAMPLE # Update all installed packages


> update.packages()
Load and Attach Package

# Load and attach package


> library(splines)

EXAMPLES # Load and attach package


> require(splines)

# Remove package
> detach("package:splines")
Search Package

# Get the list of currently loaded or


attached packages
EXAMPLES > search()

# Get path of attached packages


> searchpaths()
HELP
Help on Function
# Get offline help on machine
> help()

# Get offline help on model (Example model - glm)


EXAMPLES

> help(glm)
> ?glm

# Search function with incomplete name


> apropos("GLM")

# Search function from Internet


> RSiteSearch("GLM")
Help on Example and Demo

# Get sample example of model (Example model - glm)


EXAMPLES

> example(glm)

# Get sample demo on model (Example model - glm and plotmath)


> demo(glm)
> demo(plotmath)
LIST AND REMOVE OBJECT
Get List and Remove Objects

# List all objects in current # Remove individual object


workspace > x <- 1
> ls() > y <- c(1,2,3)
EXAMPLES

EXAMPLES
> rm(x)
# Removes all objects from the > rm(y)
current workspace (R memory)
> rm(list=ls()) # Remove multiple objects
> rm(x,y)
SAVE AND LOAD COMMAND
HISTORY
Save and Load Command History

# Various commands used during operations in


EXAMPLES

console can be saved and used again.


> savehistory(file = ".Rhistory")
> loadhistory(file = ".Rhistory")
Q&A

You might also like