简体   繁体   中英

Install Bioconductor package using rpy2 in Python Jupyter notebook

I'm trying to install "pcaMethods" from Bioconductor using rpy2 in a Python Jupyter notebook.

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 :

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 :

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

> 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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