R、Python:在 rpy2 上安装软件包 [英] R, Python: install packages on rpy2

查看:37
本文介绍了R、Python:在 rpy2 上安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 rpy2 库在我的 Python 脚本中使用 R 并且我需要一个 不在 R 的默认安装中.我该如何安装?

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

不起作用.

在 Python 上:

<预><代码>>>>install.packages("DirichletReg", repos="http://r-forge.r-project.org")回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中NameError:未定义名称安装"

来自 R:

>install.packages("DirichletReg", repos="http://r-forge.r-project.org")将软件包安装到‘/usr/local/lib/R/site-library’(因为lib"未指定)警告信息:在 getDependencies(pkgs, dependencies, available, lib) 中:包DirichletReg"不可用(适用于 R 版本 2.14.1)

解决方案

这个怎么样

<预><代码>>>>将 rpy2.interactive 导入为 r>>>r.importr("utils")>>>package_name = "DirichletReg">>>r.packages.utils.install_packages(package_name)

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")

won't work.

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

And from 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)

解决方案

How about this

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

这篇关于R、Python:在 rpy2 上安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆