After reading Mapping rpy2 objects to arbitrary python objects I thought the following would allow the conversion of Python None to 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)
However, it fails with the Trace:
NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'NoneType'>'
How can this be handled?
Nones auto-converted toNA,NULLor another R construct. Converter is the proper pattern here and is distinct from manual conversion as in the question linked by @PacketLoss