通过命令行安装二进制压缩 R 包

发布于 2024-11-30 07:28:21 字数 158 浏览 0 评论 0原文

我正在尝试通过命令行在 Windows 7 计算机上安装压缩的二进制 R 包,

R CMD INSTALL packagename

但它不起作用。我读到 CMD INSTALL 不能用于安装二进制包。那么如何通过命令行安装二进制包呢?

I am trying to install zipped binary R packages via command line on a windows 7 machine with

R CMD INSTALL packagename

but it doesn't work. I read that CMD INSTALL can't be used to install binary packages. So how can I install binary packages via command line?

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

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

发布评论

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

评论(3

彼岸花似海 2024-12-07 07:28:21

对于像我这样的新手来说,一个简单的替代方案是:

 install.packages(file.choose(), repos=NULL)

file.choose() 命令将显示一个窗口,允许您选择下载文件的 .zip 文件或 tar.gz 文件。
当您在 Windows 计算机上没有足够的权限并像我一样从闪存驱动器运行 R 时,此命令非常有用。

在运行此命令之前,将要安装的 zip 文件重命名为要使用的包名称也很有用。

An alternative for newbies like me that is hassle free would be:

 install.packages(file.choose(), repos=NULL)

The file.choose() command will show a window allowing you to choose the .zip file or the tar.gz file where you downloaded it.
This command is very useful when you don't have enough rights on a Windows machine and run R from a flash drive like myself.

It is also useful before running this command to RENAME the zip file you are going to install into the package name that you intend to use.

暗地喜欢 2024-12-07 07:28:21

您可以使用 Rscript 前端来运行代码,就像在正在运行的 R 会话中一样。假设您要安装的包是当前工作目录中的 foo.zip 。我可能在这里滥用 Rscript,但它对我有用:

Rscript -e "install.packages('foo.zip', repos = NULL)"

如果二进制包不在脚本运行的目录中,则需要提供二进制包的路径。 repos = NULL 是让 install.packages() 从本地文件工作的技巧。阅读 ?install.packages 了解有关您可能想要指定的其他参数的更多信息,尤其是 lib。请注意,执行此操作时,您不会从自动依赖项解析中受益 - 您需要一个repo,如果您提供一个,R 将尝试下载包。

你对R CMD INSTALL的看法是正确的; R 安装和管理手册的第 6.3 节中有以下内容:

在类似 Unix 的用途中从源代码安装软件包

 R CMD INSTALL -l /path/to/library pkg1 pkg2 ...

You can use the Rscript front end to run code as if it were in a running R session. Say the package you want to install is foo.zip in the current working directory. I'm probably abusing Rscript here, but it works for me:

Rscript -e "install.packages('foo.zip', repos = NULL)"

You need to supply the path to the binary package if it is not in the directory where there script is running. repos = NULL is the trick to get install.packages() to work from a local file. Read ?install.packages for more info on other arguments you might want to specify, especially lib. Note that you don't benefit from automatic dependency resolution when doing this - you need a repo for that and if you supply one, R will try to download packages.

You are right about R CMD INSTALL; the R Installation and Administration manual has the following in Section 6.3:

To install packages from source in a Unix-alike use

    R CMD INSTALL -l /path/to/library pkg1 pkg2 ...
鹤舞 2024-12-07 07:28:21

对@moldovean 的回答的补充:
我曾经保存压缩文件(从临时文件复制到 R 下载文件夹以供将来参考)。
当我将 R 从 2.15.1 更新到 3.0.1 时,我运行以下命令以方便安装:

setwd("C:/Downloads/R Packages");
packages<-dir();
install.packages(x, repos=NULL) #where x is the name of package

R 会自动从压缩文件安装所有包。现在我可以只用一个命令更新所有这些(谷歌它)

An addition to @moldovean's answer:
I used to save the zipped file(copy from temp to a R download folder for future reference).
When I updated R from 2.15.1 to 3.0.1, I run these commands for easy installation:

setwd("C:/Downloads/R Packages");
packages<-dir();
install.packages(x, repos=NULL) #where x is the name of package

And R installed all packages automatically from zipped files. Now I can update all of them with one command only(google it)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文