Convert Jupyter Notebooks to (R)Markdown, Julia, Python or R scripts and vice-versa
Source:R/jupytext.R
jupytext.Rdjuptext() provides a convenient R wrapper for the Python
jupytext API
allowing the user to convert between any of the
supported formats from within R.
Arguments
- input
File path to the input file.
- to
The format to convert to, should be a file extension for any of the Supported Languages. Ignored if
outputis specified- output
The full path to where the converted file should be written. The format is derived from the file extension of
output. Takes precedence overto. By default, the output file path is set by taking theinputfile path and replacing the file extension withto.- quiet
Logical, whether to show an informative message about which file is getting converted.
Value
The file path to the output file, invisibly. This function is mainly called for its side effects.
Details
Internally, this function calls the Python jupytext.read on the input file and then
writes it to the desired format using jupytext.write, using the
jupytext API.
Examples
library(jupytextR)
## Create toy RMarkdown file
rmd_data <- "Hi **Markdown**!
```{r}
print(\"Hi R Markdown!\")
```
"
rmd_file <- tempfile(fileext = ".Rmd")
writeLines(rmd_data, rmd_file)
## Convert Rmd file to a jupyter notebook
jupytext(rmd_file, to = "ipynb")
#> + /home/runner/.cache/R/basilisk/1.20.0/0/bin/conda create --yes --prefix /home/runner/.cache/R/basilisk/1.20.0/jupytextR/0.1.1/env 'python=3.10' --quiet -c conda-forge --override-channels
#> + /home/runner/.cache/R/basilisk/1.20.0/0/bin/conda install --yes --prefix /home/runner/.cache/R/basilisk/1.20.0/jupytextR/0.1.1/env 'python=3.10' -c conda-forge --override-channels
#> + /home/runner/.cache/R/basilisk/1.20.0/0/bin/conda install --yes --prefix /home/runner/.cache/R/basilisk/1.20.0/jupytextR/0.1.1/env -c conda-forge 'python=3.10' 'python=3.10' 'jupytext=1.14.6' 'nbformat=5.9.0' 'toml=0.10.2' 'PyYAML=6.0' 'markdown-it-py=2.2.0' 'mdit-py-plugins=0.4.0' --override-channels
#> Converting /tmp/RtmptgxsYS/file1e7d3d6055c9.Rmd to /tmp/RtmptgxsYS/file1e7d3d6055c9.ipynb