{
"cells": [
{
"cell_type": "markdown",
"id": "lesser-purchase",
"metadata": {},
"source": [
"# Convert RMarkdown files to Jupyter Notebook\n",
"> Convert your work from RStudio to generate blog posts\n",
"\n",
"- toc: true\n",
"- branch: master\n",
"- badges: true\n",
"- comments: true\n",
"- author: Francesco Gastaldello\n",
"- categories: [first steps, R, jupyter]"
]
},
{
"cell_type": "markdown",
"id": "stretch-knitting",
"metadata": {},
"source": [
"Many of the people at CorrelAid come from a R background. Even you (the reader) could be more familiar to the R world than to the Python one.
\n",
"To help you all to easily display your work on the Correlaid blog, here we will introduce a couple of methods to convert R Mardown files into Jupyter Notebook ones.\n",
"\n",
"These are:\n",
"\n",
"* [Jupytext](https://jupytext.readthedocs.io/en/latest/install.html): a Python package that provides two-way conversion between Jupyter Notebooks and several other text-based formats like Markdown documents or scripts.\n",
"* [Notedown](https://pypi.org/project/notedown/): a simple tool to create IPython notebooks from markdown (and r-markdown)."
]
},
{
"cell_type": "markdown",
"id": "cosmetic-progressive",
"metadata": {},
"source": [
"## Working with Jupytext\n",
"\n",
"### Installation\n",
"\n",
"To install `Jupytext`, open a terminal (Unix) or a command line window (Windows) and run:\n",
"```\n",
"pip install jupytext --upgrade\n",
"```\n",
"\n",
"If you use `conda` instead, run:\n",
"```\n",
"conda install jupytext -c conda-forge\n",
"```\n",
"\n",
"### Convert a R Markdown file\n",
"\n",
"Once the package is installed, using the same Python distro that is used for your Jupyter Notebook/JupyerLab, you can convert a R Markdown file by following these steps:\n",
"\n",
"1. Open a terminal (Unix) or a command line window (Windows).\n",
"2. Navigate to your `script.Rmd` file location.\n",
"3. Run `jupytext --to notebook script.Rmd` to have a `script.ipynb` file.\n",
"4. Make sure that the conversion is correct by opening the newly created notebook via Jupyter Notebook/JupyterLab.\n",
"5. Share your content on the CorrelAid blog!\n",
"\n",
"Please refer to the [project page](https://jupytext.readthedocs.io/en/latest/install.html) for further references."
]
},
{
"cell_type": "markdown",
"id": "complicated-inflation",
"metadata": {},
"source": [
"## Working with notedown\n",
"\n",
"### Installation\n",
"\n",
"To install `notedown`, open a terminal (Unix) or a command window (Windows) and run:\n",
"```\n",
"pip install notedown\n",
"```\n",
"\n",
"### Convert a R Markdown file\n",
"\n",
"Once the package is installed, make sure that you have `knitr` instaled as well with your `R` instance.
\n",
"In a terminal (Unix) or command window (Windows) run:\n",
"```\n",
"notedown script.Rmd --knit > script.ipynb\n",
"```\n",
"\n",
"Before sharing your content, make sure that the conversion is correct by opening the newly created notebook via Jupyter Notebook/JupyterLab.\n",
"\n",
"Please refer tot he [project page](https://pypi.org/project/notedown/) for further references."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}