R - Package

1 - About

R functionality is divided into a number of packages.

The package contained in the “base” system include utils, stats, datasets, graphics, grDevices, grid, methods, tools, parallel, compiler, splines, tcltk, stats4. And

The package recommended are boot, class, cluster, codetools, foreign, KernSmooth, lattice, mgcv, nlme, rpart, survival, MASS, spatial, nnet, Matrix.

There are about 4000 packages on the CRAN repository

3 - Popularity

  1. plyrTools for splitting, applying and combining data
  2. digest Create cryptographic hash digests of R objects
  3. ggplot2 An implementation of the Grammar of Graphics
  4. colorspace - Color Space Manipulation
  5. stringr Make it easier to work with strings

4 - Management

4.1 - libPath

?.libPaths
# Search path for package
.libPaths()
[1] "C:/R/R-3.5.0/library"
  • Add a path to libPath
.libPaths( c( .libPaths(), "~/userLibrary") )

4.2 - Install

Download and install Package with the following command from cran

install.packages("psych") 
install.packages("stringr", dependencies=TRUE)
  • From GitHub if not in Cran with devtools.
if (!require('devtools')) install.packages('devtools')
devtools::install_github("ropensci/plotly")
devtools::install_github('apache/[email protected]', subdir='R/pkg')
  • From the local disk
cd $PACKAGE
R -e "devtools::install('.')"

See also: librarian - install, update, and attach packages from CRAN and GitHub in the same function call.

4.3 - Uninstall / Remove

remove.packages(pkgs, lib)
 
# Example
remove.packages("sparklyr")

where:

4.4 - Installation location

Package are installed locally on Windows at: USER_HOME\Documents\R\win-library\

4.5 - Meta

The meta (description) of the package are in the DESCRIPTION file.

Example for sparklyr

Package: sparklyr
Type: Package
Title: R Interface to Apache Spark
Version: 0.5.4
[email protected]: c(
    person("Javier", "Luraschi", email = "[email protected]", role = c("aut", "cre")),
    person("Kevin", "Ushey", role = "aut", email = "[email protected]"),
    person("JJ", "Allaire", role = "aut", email = "[email protected]"),
    person(family = "RStudio", role = c("cph")),
    person(family = "The Apache Software Foundation", role = c("aut", "cph"))
    )
Maintainer: Javier Luraschi <[email protected]>
Description: R interface to Apache Spark, a fast and general engine for big data
    processing, see <http://spark.apache.org>. This package supports connecting to
    local and remote Apache Spark clusters, provides a 'dplyr' compatible back-end,
    and provides an interface to Spark's built-in machine learning algorithms.
License: Apache License 2.0 | file LICENSE
URL: http://spark.rstudio.com
BugReports: https://github.com/rstudio/sparklyr/issues
LazyData: TRUE
RoxygenNote: 6.0.0
Depends: R (>= 3.1.2)
Imports: methods, lazyeval (>= 0.2.0), dplyr (>= 0.5.0), DBI (>= 0.6),
        readr (>= 0.2.0), digest, config, rappdirs, assertthat,
        rprojroot, withr, httr, jsonlite, base64enc
Suggests: testthat, RCurl, janeaustenr
NeedsCompilation: no
Packaged: 2017-04-25 06:40:26 UTC; javierluraschi
Author: Javier Luraschi [aut, cre],
  Kevin Ushey [aut],
  JJ Allaire [aut],
  RStudio [cph],
  The Apache Software Foundation [aut, cph]
Repository: CRAN
Date/Publication: 2017-04-25 07:24:39 UTC
Built: R 3.3.3; ; 2017-04-28 11:22:35 UTC; windows

4.6 - Load

To load package, use the library function

library(psych)

4.7 - Unload

detach("package:RJDBC", unload = TRUE)

4.8 - Verify is a package is loaded

search()
 [1] ".GlobalEnv"        "tools:rstudio"     "package:stats"     "package:graphics" 
 [5] "package:grDevices" "package:utils"     "package:datasets"  "package:methods"  
 [9] "Autoloads"         "package:base"     

4.9 - Creating a package

4.10 - Documentation

Get the help on one package

help(package=boot)

5 - Documentation / Reference

lang/r/package.txt · Last modified: 2018/06/11 20:08 by gerardnico