R,Python的:安装在rpy2包(R, Python: install packages on

2019-06-26 09:50发布

我使用R通过我的Python脚本rpy2库,我需要一个包 ,是不是在河的默认安装如何安装呢?

install.packages("DirichletReg", repos="http://r-forge.r-project.org")

将无法正常工作。

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)

Answer 1:

这个怎么样

>>> import rpy2.interactive as r
>>> r.importr("utils")
>>> package_name = "DirichletReg"
>>> r.packages.utils.install_packages(package_name)


Answer 2:

里卡多的答案不再起作用。

若要从Python的安装:

from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('DirichletReg')

utils包是R.utils包,其文档可以在这里找到: https://CRAN.R-project.org/package=R.utils

正如我上次编辑的, 该文件还称这样做。



文章来源: R, Python: install packages on rpy2