In R
what is the difference between a library and a package?
在R中,库和包之间有什么区别?
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'.
我遇到过人们在库中引用包的帖子。根据这个想法,我将其解释为一个包存在于一个库中(即我用指定的库存储我的包)。但是,当我想使用包'x'时,我感到困惑。
- I am under the imperssion I need to call the library function to get package 'x' to be in use ?
- 我需要调用库函数来获取包'x'才能使用吗?
- And once I have have called upon package 'x' the functions of package 'x' then become available to me ?
- 一旦我调用了包'x',包'x'的功能就可以使用了?
2 个解决方案
#1
12
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.
在R中,包是R函数,数据和编译代码的集合。存储包的位置称为库。如果您需要特定功能,则可以从相应的站点下载该程序包,它将存储在您的库中。要实际使用该软件包,请使用命令“library(package)”,该命令使您可以使用该软件包。然后只需调用相应的包函数等。
#2
3
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.
包扩展了基本的R功能并标准化了代码的分发。例如,包可以包含与特定主题相关的一组功能。
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).
包可以作为SOURCE(包含所有包组件的目录),BINARIES(包含OS特定格式的文件)或BUNDLE(包含包组件的压缩文件,类似于源)进行分发。
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.
所有R代码所在的R /目录,以及DESCRIPTION和NAMESPACE元数据文件。
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:
要使用包'x',首先必须将其安装在包库中。例如,这可以通过以下方式完成:
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)
.
安装后,必须使用库(x)或require(x)将其加载到内存中。
#1
12
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.
在R中,包是R函数,数据和编译代码的集合。存储包的位置称为库。如果您需要特定功能,则可以从相应的站点下载该程序包,它将存储在您的库中。要实际使用该软件包,请使用命令“library(package)”,该命令使您可以使用该软件包。然后只需调用相应的包函数等。
#2
3
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.
包扩展了基本的R功能并标准化了代码的分发。例如,包可以包含与特定主题相关的一组功能。
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).
包可以作为SOURCE(包含所有包组件的目录),BINARIES(包含OS特定格式的文件)或BUNDLE(包含包组件的压缩文件,类似于源)进行分发。
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.
所有R代码所在的R /目录,以及DESCRIPTION和NAMESPACE元数据文件。
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:
要使用包'x',首先必须将其安装在包库中。例如,这可以通过以下方式完成:
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)
.
安装后,必须使用库(x)或require(x)将其加载到内存中。