Closed ramadatta closed 1 month ago
Running {zellkonverter} in a Jupyter notebook can be sometimes problematic. It seems like for some reason R doesn't see adata
as a Python object. Do you have anndata2ri installed? What happens if you just print adata
in an R chunk?
Yes, I have anndata2ri
installed.
I have tried in a new notebook fresh and I get this:
%%R
adata
---------------------------------------------------------------------------
RRuntimeError Traceback (most recent call last)
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/rpy2/ipython/rmagic.py:401, in RMagics.eval(self, code)
400 r_expr = ri.parse(code)
--> 401 value, visible = ri.evalr_expr_with_visible(
402 r_expr
403 )
404 except (ri.embedded.RRuntimeError, ValueError) as exception:
405 # Otherwise next return seems to have copy of error.
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/rpy2/rinterface.py:196, in evalr_expr_with_visible(expr, envir)
195 if error_occured[0]:
--> 196 raise embedded.RRuntimeError(_rinterface._geterrmessage())
197 res = conversion._cdata_to_rinterface(r_res)
RRuntimeError: Fehler in (function (expr, envir = parent.frame(), enclos = if (is.list(envir) || :
Objekt 'adata' nicht gefunden
During handling of the above exception, another exception occurred:
RInterpreterError Traceback (most recent call last)
Cell In[10], line 1
----> 1 get_ipython().run_cell_magic('R', '', '\nadata\n')
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2515, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2513 with self.builtin_trap:
2514 args = (magic_arg_s, cell)
-> 2515 result = fn(*args, **kwargs)
2517 # The code below prevents the output from being displayed
2518 # when using magics with decorator @output_can_be_silenced
2519 # when the last Python token in the expression is a ';'.
2520 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/rpy2/ipython/rmagic.py:978, in RMagics.R(self, line, cell, local_ns)
976 if not e.stdout.endswith(e.err):
977 print(e.err)
--> 978 raise e
979 finally:
980 if self.device in DEVICES_STATIC:
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/rpy2/ipython/rmagic.py:943, in RMagics.R(self, line, cell, local_ns)
941 return_output = False
942 else:
--> 943 text_result, result, visible = self.eval(code)
944 text_output += text_result
945 if visible:
File /opt/homebrew/Caskroom/mambaforge/base/envs/singlecell/lib/python3.11/site-packages/rpy2/ipython/rmagic.py:407, in RMagics.eval(self, code)
404 except (ri.embedded.RRuntimeError, ValueError) as exception:
405 # Otherwise next return seems to have copy of error.
406 warning_or_other_msg = self.flush()
--> 407 raise RInterpreterError(code, str(exception),
408 warning_or_other_msg)
409 finally:
410 ro._print_deferred_warnings()
RInterpreterError: Failed to parse and evaluate line '\nadata\n'.
R error message: "Fehler in (function (expr, envir = parent.frame(), enclos = if (is.list(envir) || : \n Objekt 'adata' nicht gefunden"```
I think this is because you haven't passed adata
to your R chunk using the --i
option. See the example in the best practices book https://www.sc-best-practices.org/introduction/interoperability.html#accessing-r-from-python.
Thanks @lazappi. Let me work on this and come back!
@ramadatta I will close this unless you want to add anything?
@lazappi Hi Luke, I moved on with the issue by using sceasy
. This issue can be closed. Many thanks for your help!
Hi Luke,
Thanks for zellkonverter.
I downloaded one of the h5ad objects from here and ran the following code in jupyter notebook.
I can see the adata features:
but the
AnnData2SCE
command throws me below error:May I kindly know how I can fix this error? Many thanks in advance!