且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用导入器从 Python 中的 R 包中调用函数

更新时间:2023-02-18 13:08:21

您只导入了基本模块,需要完全导入它.你会认为 Python 会自动做到这一点,但显然它不会.请参阅此 SO 答案.

You're only importing the base module, and need to import it entirely. You'd think Python would do that automatically, apparently it doesn't. See this SO answer.

from mRMRr import *
from datasets import *

啊,是的,这适用于显式 python 模块.我认为调用子包函数的语法可能不同.试试这个.

Ah, yeah that applies to explicit python modules. I think the syntax of calling on functions of sub-packages is possibly different. Try this.

import rpy2.robjects.packages as packages
datasets = packages.importr('datasets')
mtcars = packages.data(datasets).fetch('mtcars')['mtcars']