VSCode R notebook to R script for tracking shortcut

June 26, 2024 by Kinh Nguyen

.ipynb is great for many reasons, one of them is more than most for me: when working with several (say 10) different projects, it helps to remind what you had done much better than looking at R scripts.

A small drawback is the tracking, with git for example, is not convenient despite VSCode provides a very specific diff view.

Moreover, sometime you might want to have pure R code just to submit it a long running job on a HPC or remote server.

My workflow is working in notebook, write and report it with quarto, and track with pure R with a VScode’s shortcut as below:

	"key": "cmd+shift+C",
	"command": "workbench.action.terminal.sendSequence",
	"args": {

	"text": "R -e 'setwd(\\"${fileDirname}\\");rmarkdown::convert\_ipynb(\\"${fileBasename}\\");knitr::purl(\\"${fileBasenameNoExtension}.Rmd\\",

which export the current .ipynb to a R file with the same name in the same directory.

This remove the need of jupytext for me.


comments powered by Disqus