阅读后 将rpy2对象映射为任意的python对象 我想下面的内容可以让Python的None转换为R的NULL。
import rpy2.robjects.conversion as cv
import rpy2.robjects as robjs
from rpy2.robjects import default_converter
from rpy2.robjects.packages import importr
r_base = importr("base")
def _none2null(none_obj):
return robjs.r("NULL")
none_converter = cv.Converter("None converter")
none_converter.py2rpy.register(None, _none2null)
with cv.localconverter(default_converter + none_converter):
filesl = r_base.list_files(pattern=None)
然而,它在追踪中失败了。
NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'NoneType'>'
如何处理这个问题?