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

Leading encoding comments creeps into RMarkdown file #576

Closed
alcrene opened this issue Jul 25, 2020 · 3 comments · Fixed by #583
Closed

Leading encoding comments creeps into RMarkdown file #576

alcrene opened this issue Jul 25, 2020 · 3 comments · Fixed by #583
Milestone

Comments

@alcrene
Copy link

alcrene commented Jul 25, 2020

This is a somewhat opposite problem to #241. When the Jupytext metadata includes the file encoding, the leading comment for Python scripts is erroneously included in RMarkdown files.

Steps to reproduce in JupyterLab:

  1. Create a notebook. A single markdown cell, with say "α", will suffice. The relevant Jupytext metadata is
 "metadata": {
  "jupytext": {
   "formats": "ipynb,Rmd"
  },
  1. Pair the notebook with an RMarkdown file. Note that the export is fine; the RMarkdown looks as follows:
---
jupyter:
  jupytext:
    formats: ipynb,Rmd
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.2'
      jupytext_version: 1.5.0
---

α
  1. Add an encoding entry to the metadata. One way to do this is:
    1. Additionally pair the notebook with a Python script. It will include the line # -*- coding: utf-8 -*- because of the unicode character.
    2. Edit the Python script (e.g. write "αb") and save.
    3. Reopen the notebook in Jupyter and save. A dialog will ask to overwrite; click yes. Now the notebook metadata reads
 "metadata": {
  "jupytext": {
   "encoding": "# -*- coding: utf-8 -*-",
   "formats": "ipynb,Rmd,py:light"
  },
  1. In addition, the RMarkdown is now invalid because it begins with the Python encoding line:
# -*- coding: utf-8 -*-
---
jupyter:
  jupytext:
    formats: ipynb,Rmd,py:light
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.2'
      jupytext_version: 1.5.0
---

αb
@mwouts
Copy link
Owner

mwouts commented Jul 27, 2020

Thank you @alcrene for the detailed report! That is very helpful. I think I should be able to reproduce this unwanted behavior easily in a test (given that you've done all the work above 👍). I will let you know when the fix is available.

@mwouts
Copy link
Owner

mwouts commented Jul 30, 2020

Hi @alcrene , this should be solved in the development version. If you wish, you can give it a try with

pip install git+https://github.com/mwouts/jupytext.git

Thank you again for reporting it!

@alcrene
Copy link
Author

alcrene commented Aug 5, 2020

Thank you for the rapid fix ! I just tested with my original use case, and as far as I can tell it works as intended.

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

Successfully merging a pull request may close this issue.

2 participants