Skip to content

NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'pathlib.PosixPath'>' #116

@1498507164-lab

Description

@1498507164-lab

I'm encountering error below when i run these code
`%%R -i h5ad_file

message("Converting H5AD to H5Seurat...")
SeuratDisk::Convert(h5ad_file, dest = "h5seurat", overwrite = TRUE)
message("Reading H5Seurat...")
h5seurat_file <- gsub(".h5ad", ".h5seurat", h5ad_file)
seurat <- SeuratDisk::LoadH5Seurat(h5seurat_file, assays = "RNA")
message("Read Seurat object:")
seurat`

`NotImplementedError Traceback (most recent call last)
Cell In[4], line 1
----> 1 get_ipython().run_cell_magic('R', '-i h5ad_file', '\nmessage("Converting H5AD to H5Seurat...")\nSeuratDisk::Convert(h5ad_file, dest = "h5seurat", overwrite = TRUE)\nmessage("Reading H5Seurat...")\nh5seurat_file <- gsub(".h5ad", ".h5seurat", h5ad_file)\nseurat <- SeuratDisk::LoadH5Seurat(h5seurat_file, assays = "RNA")\nmessage("Read Seurat object:")\nseurat\n')

File ~/miniforge3/lib/python3.12/site-packages/IPython/core/interactiveshell.py:2572, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2570 with self.builtin_trap:
2571 args = (magic_arg_s, cell)
-> 2572 result = fn(*args, **kwargs)
2574 # The code below prevents the output from being displayed
2575 # when using magics with decorator @output_can_be_silenced
2576 # when the last Python token in the expression is a ';'.
2577 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/miniforge3/lib/python3.12/site-packages/rpy2/ipython/rmagic.py:896, in RMagics.R(self, line, cell, local_ns)
894 with localconverter(converter) as cv:
895 for arg in ','.join(args.input).split(','):
--> 896 self._import_name_into_r(arg, ro.globalenv, local_ns)
898 if args.display:
899 try:

File ~/miniforge3/lib/python3.12/site-packages/rpy2/ipython/rmagic.py:424, in RMagics._import_name_into_r(self, arg, env, local_ns)
422 val = _find(rhs, self.shell.user_ns)
423 if val is not None:
--> 424 env[lhs] = val

File ~/miniforge3/lib/python3.12/site-packages/rpy2/robjects/environments.py:35, in Environment.setitem(self, item, value)
34 def setitem(self, item: str, value: typing.Any) -> None:
---> 35 robj = conversion.get_conversion().py2rpy(value)
36 super(Environment, self).setitem(item, robj)

File ~/miniforge3/lib/python3.12/functools.py:912, in singledispatch..wrapper(*args, **kw)
908 if not args:
909 raise TypeError(f'{funcname} requires at least '
910 '1 positional argument')
--> 912 return dispatch(args[0].class)(*args, **kw)

File ~/miniforge3/lib/python3.12/site-packages/rpy2/robjects/numpy2ri.py:140, in nonnumpy2rpy(obj)
135 return ro.default_converter.py2rpy(obj)
136 elif original_converter is None:
137 # This means that the conversion module was not "activated".
138 # For now, go with the default_converter.
139 # TODO: the conversion system needs an overhaul badly.
--> 140 return ro.default_converter.py2rpy(obj)
141 else:
142 # The conversion module was "activated"
143 return original_converter.py2rpy(obj)

File ~/miniforge3/lib/python3.12/functools.py:912, in singledispatch..wrapper(*args, **kw)
908 if not args:
909 raise TypeError(f'{funcname} requires at least '
910 '1 positional argument')
--> 912 return dispatch(args[0].class)(*args, **kw)

File ~/miniforge3/lib/python3.12/site-packages/rpy2/robjects/conversion.py:240, in _py2rpy(obj)
238 if isinstance(obj, _rinterface_capi.SupportsSEXP):
239 return obj
--> 240 raise NotImplementedError(
241 "Conversion 'py2rpy' not defined for objects of type '%s'" %
242 str(type(obj))
243 )

NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'pathlib.PosixPath'>'`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions