Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert_ipynb silently drops raw cells with no format in metadata #2587

Open
4 of 5 tasks
katrinabrock opened this issue Feb 10, 2025 · 3 comments
Open
4 of 5 tasks

Comments

@katrinabrock
Copy link

katrinabrock commented Feb 10, 2025

Description

Because of this line, if a python notebook has a raw type cell that does not have format specified in the metadata, that cell is completely omitted when convert_ipynb transforms the notebook to rmd. IMO this is inconsistent with how raw cells are described in jupyter docs as well as how jupyterhub handles them. Testing with jupyterhub (I tested with server version 6.5.4), content in raw cells that are not specified as latex or html get transferred verbatim into both formats. Example below.

Suggested Resolutions

  • If this is the expected behavior, it would be nice for it to be documented in help text of convert_ipynb function. Currently, raw cells are not mentioned at all.
  • Otherwise, it would be nice to give users a way to pass these cells through in some way. IMO ideal would be for the user to be able to chose whether to put raw cells directly into the Rmd as though they were Rmd or to put them in in code not running code blocks.

MRE

Python Notebook
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "17e25b19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "regular code cell\n"
     ]
    }
   ],
   "source": [
    "print('regular code cell')"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bea4ed8a",
   "metadata": {},
   "source": [
    "print('raw cell')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4545441e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
RMarkdown actual result
---
title: An R Markdown document converted from "mre.ipynb" 
output: html_document
---

```{python}
print('regular code cell')
```

Backslashes added so it will show up properly on github.

Rmarkdown expected result
---
title: An R Markdown document converted from "mre.ipynb" 
output: html_document
---

```{python}
print('regular code cell')
```
print('raw cell')
jupyterhub html result

Image

jupyterhub latex result

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown") ?

Session Info ``` xfun::session_info('rmarkdown') R version 4.3.2 (2023-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.3 LTS, RStudio 0

Locale:
LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8
LC_COLLATE=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8
LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C
LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

Package version:
base64enc_0.1.3 bslib_0.8.0 cachem_1.1.0 cli_3.6.3
digest_0.6.37 evaluate_1.0.1 fastmap_1.2.0 fontawesome_0.5.3
fs_1.6.5 glue_1.8.0 graphics_4.3.2 grDevices_4.3.2
highr_0.11 htmltools_0.5.8.1 jquerylib_0.1.4 jsonlite_1.8.9
knitr_1.49 lifecycle_1.0.4 memoise_2.0.1 methods_4.3.2
mime_0.12 R6_2.5.1 rappdirs_0.3.3 rlang_1.1.4
rmarkdown_2.29 sass_0.4.9 stats_4.3.2 tinytex_0.54
tools_4.3.2 utils_4.3.2 xfun_0.49 yaml_2.3.10

Pandoc version: 3.6

</details>
@yihui
Copy link
Member

yihui commented Feb 10, 2025

Sounds like the fix should be simple enough. Do you mean that we return(x) instead of return() here?

if (length(fmt) != 1) return()

@katrinabrock
Copy link
Author

Yes, and maybe line 109 as well. I can make a PR if you agree this is a bug.

@yihui
Copy link
Member

yihui commented Feb 11, 2025

Sure. Please do. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants