如何从源代码安装 R 包?
一位朋友向我发送了关于 使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您在本地有该文件,则使用
install.packages()
并设置repos=NULL
:其中
path_to_file
代表完整路径,文件名:“C:\\RJSONIO_0.2-3.tar.gz”
。“/home/blah/RJSONIO_0.2-3.tar.gz”
。If you have the file locally, then use
install.packages()
and set therepos=NULL
:Where
path_to_file
would represent the full path and file name:"C:\\RJSONIO_0.2-3.tar.gz"
."/home/blah/RJSONIO_0.2-3.tar.gz"
.下载源包,打开 Terminal.app,导航到当前包含该文件的目录,然后执行:
请注意,只有在以下情况下才会成功: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:
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
您可以直接从存储库安装(请注意
type="source"
):You can install directly from the repository (note the
type="source"
):用于从源安装旧版本软件包的补充方便(但微不足道)的提示。
首先,如果您调用“install.packages”,它总是从存储库安装最新的软件包。如果你想安装旧版本的软件包,比如说为了兼容性,你可以调用 install.packages("url_to_source", 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:
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
来自 CRAN,您可以直接从 GitHub 安装存储库地址。因此,如果您想要
https://github.com/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
, usingdoes the trick.
此外,您可以使用
--binary
选项构建二进制包。In addition, you can build the binary package using the
--binary
option.如果您有自己编写的源代码、从 GitHub 下载(克隆)或以其他方式从其他来源复制或移动到您的计算机,则安装包/库的一个简单方法是:
在 R 中,
就像这样简单:
从终端
从此处,您可以克隆 GitHub 存储库并使用以下命令进行安装:
或者,如果您已经安装了 devtools,则可以跳过该步骤首先,克隆存储库并运行:
请注意,如果您使用的是 ubuntu,请在安装 devtools 之前安装这些系统库(否则开发工具将无法正确安装)。
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:
From terminal
From here, you can clone a GitHub repo and install it with:
Or if you already have devtools installed, you can skip that first bit and just clone the repo and run:
Note that if you're on ubuntu, install these system libraries before installing devtools (or devtools won't install properly).