windows 通过命令行安装二进制压缩的 R 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7075709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install binary zipped R package via command line
提问by Kai
I am trying to install zipped binary R packages via command line on a windows 7 machine with
我正在尝试通过命令行在 Windows 7 机器上安装压缩的二进制 R 包
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?
但它不起作用。我读到 CMD INSTALL 不能用于安装二进制包。那么如何通过命令行安装二进制包呢?
回答by moldovean
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.
file.choose() 命令将显示一个窗口,允许您选择下载它的 .zip 文件或 tar.gz 文件。当您在 Windows 机器上没有足够的权限并且像我一样从闪存驱动器运行 R 时,此命令非常有用。
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.
在运行此命令之前,将要安装的 zip 文件重命名为要使用的包名称也很有用。
回答by Gavin Simpson
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
前端来运行代码,就像在运行的 R 会话中一样。假设您要安装的软件包foo.zip
位于当前工作目录中。我可能Rscript
在这里滥用,但它对我有用:
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.
如果二进制包不在运行脚本的目录中,则需要提供该二进制包的路径。repos = NULL
是install.packages()
从本地文件开始工作的技巧。阅读?install.packages
有关您可能想要指定的其他参数的更多信息,尤其是lib
. 请注意,这样做时您不会从自动依赖项解析中受益 - 您需要一个repo
,如果您提供一个,R 将尝试下载包。
You are right about R CMD INSTALL
; the R Installation and Administration manual has the following in Section 6.3:
你是对的R CMD INSTALL
;R 安装和管理手册在第 6.3 节中有以下内容:
To install packages from source in a Unix-alike use
R CMD INSTALL -l /path/to/library pkg1 pkg2 ...
在类 Unix 使用中从源代码安装软件包
R CMD INSTALL -l /path/to/library pkg1 pkg2 ...
回答by Outlier
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:
@moldovean 的答案的补充:我曾经保存压缩文件(从 temp 复制到 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
And R installed all packages automatically from zipped files. Now I can update all of them with one command only(google it)
R 自动从压缩文件安装所有包。现在我可以只用一个命令更新所有这些(谷歌它)