简体   繁体   English

在 Python Jupyter notebook 中使用 rpy2 安装 Bioconductor 包

[英]Install Bioconductor package using rpy2 in Python Jupyter notebook

I'm trying to install "pcaMethods" from Bioconductor using rpy2 in a Python Jupyter notebook.我正在尝试在 Python Jupyter 笔记本中使用 rpy2 从 Bioconductor 安装“pcaMethods”。

This is what I tried这是我试过的

from rpy2.robjects.packages import importr
utils = importr('utils')
utils.install_packages('mice') # all of this works
base = importr('base')
base.source("http://www.bioconductor.org/biocLite.R")
biocinstaller = importr("BiocInstaller") # this doesn't work
biocinstaller.biocLite("pcaMethods") # this doesn't work

# load the installed package
pcaMethods = importr("pcaMethods")

This is the error I get when I try to install pcaMethods :这是我尝试安装pcaMethods时遇到的错误:

Error in if (answer %in% allowed) break : argument is of length zero

Anyone know what I'm doing wrong?有谁知道我做错了什么?

This introduction comes from this SO question :这个介绍来自这个SO问题

"argument is of length zero" is a very specific problem that comes from one of my least-liked elements of R. Let me demonstrate the problem: “参数长度为零”是一个非常具体的问题,它来自我最不喜欢的 R 元素之一。让我演示一下这个问题:

> FALSE == "turnip"
[1] FALSE
> TRUE == "turnip"
[1] FALSE
> NA == "turnip"
[1] NA
> NULL == "turnip"
logical(0)

As you can see, comparisons to a NULL not only don't produce a boolean value, they don't produce a value at all - and control flows tend to expect that a check will produce some kind of output.如您所见,与 NULL 的比较不仅不会产生布尔值,而且根本不会产生值 - 并且控制流倾向于期望检查会产生某种输出。 When they produce a zero-length output... "argument is of length zero".当它们产生零长度输出时......“参数的长度为零”。

Taking it from here, it seems that one of your lines evoke this behavior.从这里开始,您的一条台词似乎引起了这种行为。 I guess there's something about the library paths of the interactive R versus the R used from rpy, that does not match in your case.我猜想交互式 R 的库路径与 rpy 中使用的 R 有一些关系,这与您的情况不匹配。

It is also important to note, that you should do the installation process only once, during the first execution of your code:同样重要的是要注意,在第一次执行代码期间,您应该只执行一次安装过程:

base.source("http://www.bioconductor.org/biocLite.R")
biocinstaller = importr("BiocInstaller") # this doesn't work
biocinstaller.biocLite("pcaMethods") # this doesn't work

Later on you only need to load the package稍后你只需要加载包

# load the installed package
pcaMethods = importr("pcaMethods")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM