如何从源代码安装 R 包?

发布于 2024-08-06 04:56:25 字数 268 浏览 6 评论 0原文

一位朋友向我发送了关于 使用 R 抓取《纽约时报》的网页。我真的很想尝试一下。然而,第一步是从源安装一个名为 [RJSONIO][2] 的包。

我对 R 相当了解,但我不知道如何从源代码安装包。

我运行的是 macOS (OS X)。

A friend sent me along this great tutorial on webscraping The New York Times with R. I would really love to try it. However, the first step is to install a package called [RJSONIO][2] from source.

I know R reasonably well, but I have no idea how to install a package from source.

I'm running macOS (OS X).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

几味少女 2024-08-13 04:56:25

如果您在本地有该文件,则使用 install.packages() 并设置 repos=NULL

install.packages(path_to_file, repos = NULL, type="source")

其中 path_to_file 代表完整路径,文件名:

  • 在 Windows 上,它看起来像这样:“C:\\RJSONIO_0.2-3.tar.gz”
  • 在 UNIX 上,它看起来像这样:“/home/blah/RJSONIO_0.2-3.tar.gz”

If you have the file locally, then use install.packages() and set the repos=NULL:

install.packages(path_to_file, repos = NULL, type="source")

Where path_to_file would represent the full path and file name:

  • On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
  • On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz".
病女 2024-08-13 04:56:25

下载源包,打开 Terminal.app,导航到当前包含该文件的目录,然后执行:

R CMD INSTALL RJSONIO_0.2-3.tar.gz

请注意,只有在以下情况下才会成功:a)包不需要编译或 b)所需的系统工具用于编译的存在。请参阅:R for Mac OS X

Download the source package, open Terminal.app, navigate to the directory where you currently have the file, and then execute:

R CMD INSTALL RJSONIO_0.2-3.tar.gz

Do note that this will only succeed when either: a) the package does not need compilation or b) the needed system tools for compilation are present. See: R for Mac OS X

私藏温柔 2024-08-13 04:56:25

您可以直接从存储库安装(请注意 type="source"):

install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")

You can install directly from the repository (note the type="source"):

install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
暗恋未遂 2024-08-13 04:56:25

用于从源安装旧版本软件包的补充方便(但微不足道)的提示。

首先,如果您调用“install.packages”,它总是从存储库安装最新的软件包。如果你想安装旧版本的软件包,比如说为了兼容性,你可以调用 install.packages("url_to_source", repo=NULL, type="source")。例如:

install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")

无需手动将包下载到本地磁盘并切换到命令行或从本地磁盘安装,我发现它非常方便并且简化了调用(一步)。

另外:您可以将此技巧与 devtools 库的 dev_mode 结合使用,以管理不同版本的包:

参考:doc devtools

A supplementarily handy (but trivial) tip for installing older version of packages from source.

First, if you call "install.packages", it always installs the latest package from repo. If you want to install the older version of packages, say for compatibility, you can call install.packages("url_to_source", repo=NULL, type="source"). For example:

install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")

Without manually downloading packages to the local disk and switching to the command line or installing from local disk, I found it is very convenient and simplify the call (one-step).

Plus: you can use this trick with devtools library's dev_mode, in order to manage different versions of packages:

Reference: doc devtools

情话墙 2024-08-13 04:56:25

来自 CRAN,您可以直接从 GitHub 安装存储库地址。因此,如果您想要 https://github.com/twitter/AnomalyDetection 上的包,使用

library(devtools)
install_github("twitter/AnomalyDetection")

就可以了。

From CRAN, you can install directly from a GitHub repository address. So if you want the package at https://github.com/twitter/AnomalyDetection, using

library(devtools)
install_github("twitter/AnomalyDetection")

does the trick.

听闻余生 2024-08-13 04:56:25

此外,您可以使用 --binary 选项构建二进制包。

R CMD build --binary RJSONIO_0.2-3.tar.gz

In addition, you can build the binary package using the --binary option.

R CMD build --binary RJSONIO_0.2-3.tar.gz
呆橘 2024-08-13 04:56:25

如果您有自己编写的源代码、从 GitHub 下载(克隆)或以其他方式从其他来源复制或移动到您的计算机,则安装包/库的一个简单方法是:

在 R 中,

就像这样简单:

# install.packages("devtools")
devtools::install('path/to/package')

从终端

此处,您可以克隆 GitHub 存储库并使用以下命令进行安装:

git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"

或者,如果您已经安装了 devtools,则可以跳过该步骤首先,克隆存储库并运行:

R -e "devtools::install('path/to/package')"

请注意,如果您使用的是 ubuntu,请在安装 devtools 之前安装这些系统库(否则开发工具将无法正确安装)。

apt-get update
apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev -y

If you have source code you wrote yourself, downloaded (cloned) from GitHub, or otherwise copied or moved to your computer from some other source, a nice simple way to install the package/library is:

In R

It's as simple as:

# install.packages("devtools")
devtools::install('path/to/package')

From terminal

From here, you can clone a GitHub repo and install it with:

git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"

Or if you already have devtools installed, you can skip that first bit and just clone the repo and run:

R -e "devtools::install('path/to/package')"

Note that if you're on ubuntu, install these system libraries before installing devtools (or devtools won't install properly).

apt-get update
apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev -y
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文