Skip to contents

juptext() provides a convenient R wrapper for the Python jupytext API allowing the user to convert between any of the supported formats from within R.

Usage

jupytext(input, to, output = .with_ext(input, to), quiet = FALSE)

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 output is 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 over to. By default, the output file path is set by taking the input file path and replacing the file extension with to.

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.16.0/0/bin/conda create --yes --prefix /home/runner/.cache/R/basilisk/1.16.0/jupytextR/0.1.1/env 'python=3.10' --quiet -c conda-forge
#> + /home/runner/.cache/R/basilisk/1.16.0/0/bin/conda install --yes --prefix /home/runner/.cache/R/basilisk/1.16.0/jupytextR/0.1.1/env 'python=3.10' -c conda-forge
#> + /home/runner/.cache/R/basilisk/1.16.0/0/bin/conda install --yes --prefix /home/runner/.cache/R/basilisk/1.16.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'
#> Converting /tmp/RtmpRTXnRq/file194a6589fc54.Rmd to /tmp/RtmpRTXnRq/file194a6589fc54.ipynb