Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a library and a package in R?

Tags:

r

packages

In R what is the difference between a library and a package?

I have come across posts where people refer to packages within a library. Based on this idea I interpret it that a package lives in a library (i.e I store my packages with a designated library). However I get confused when I want to use package 'x'.

  • I am under the imperssion I need to call the library function to get package 'x' to be in use ?
  • And once I have have called upon package 'x' the functions of package 'x' then become available to me ?
like image 281
user3754366 Avatar asked Nov 13 '14 02:11

user3754366


People also ask

What is difference between library and package?

However, it is often assumed that while a package is a collection of modules, a library is a collection of packages. Oftentimes, developers create Python libraries to share reusable code with the community.

What is the use of packages & libraries in R example?

Packages in R Programming language are a set of R functions, compiled code, and sample data. These are stored under a directory called “library” within the R environment. By default, R installs a group of packages during installation.

What is use of library () in R programming?

Data Visualization using R Programming They are stored under a directory called "library" in the R environment. By default, R installs a set of packages during installation. More packages are added later, when they are needed for some specific purpose.

What does package mean in R?

R packages are extensions to the R statistical programming language. R packages contain code, data, and documentation in a standardised collection format that can be installed by users of R, typically via a centralised software repository such as CRAN (the Comprehensive R Archive Network).


2 Answers

In R, a package is a collection of R functions, data and compiled code. The location where the packages are stored is called the library. If there is a particular functionality that you require, you can download the package from the appropriate site and it will be stored in your library. To actually use the package use the command "library(package)" which makes that package available to you. Then just call the appropriate package functions etc.

like image 161
Rainer Berger Avatar answered Sep 28 '22 10:09

Rainer Berger


1. Package

Package extends basic R functionality and standardizes the distribution of code. For example, a package can contain a set of functions relating to a specific topic or tasks.

Packages can be distributed as SOURCE (a directory with all package components), BINARIES (contains files in OS-specific format) or as a BUNDLE (compressed file containing package components, similar to source).

The most basic package, for example created with,

library(devtools)
create("C:/Users/Documents/R-dev/MyPackage")

contains:

R/ directory where all the R code goes to, and DESCRIPTION and NAMESPACE metadata files.

2. Library

Library is a directory where the packages are stored. You can have multiple libraries on your hard drive.

To see which libraries are available (which paths are searched for packages):

.libPaths()

And to see which packages are there:

lapply(.libPaths(), dir)

To use package ‘x’, it first has to be installed in a package library. This can be done for example, with:

install.packages(‘x’) # to install packages from CRAN

or

R CMD INSTALL Xpackagename.tar.gz #to install directly from source

Once installed it has to be loaded into memory with library(x) or require(x).

like image 41
USER_1 Avatar answered Sep 28 '22 09:09

USER_1