我通过 rpy2
库在我的 Python 脚本中使用 R
,我需要一个 package 不在 R 的默认安装中.如何安装?
I'm using R
in my Python script through the rpy2
library and I need a package that is not in the default installation of R. How can I install it?
install.packages("DirichletReg", repos="http://r-forge.r-project.org")
不会工作.
在 Python 上:
On Python:
>>> install.packages("DirichletReg", repos="http://r-forge.r-project.org")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'install' is not defined
来自 R:
> install.packages("DirichletReg", repos="http://r-forge.r-project.org")
Installing package(s) into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘DirichletReg’ is not available (for R version 2.14.1)
这个怎么样
>>> import rpy2.interactive as r
>>> r.importr("utils")
>>> package_name = "DirichletReg"
>>> r.packages.utils.install_packages(package_name)
这篇关于R,Python:在 rpy2 上安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!