I love knitr::spin()
and code cells for my dev experience. However, there are a few edge-cases that made the function insufficient.
#'
roxygen-style documentation would create problems since they would be interpreted as markdown.- With
ark
, jupytext style notebooks will be advantageous and as such, supporting# %% [markdown]
would be beneficial. - If
# %%
is on the start of a line in a string, this would cause problems (unlikely, but still)
This function streamlines this proceess by rewriting the code from first-principles:
- The function parses the source code using tree-sitter (see history for using R's
parse
function) - The code is iterated line-by-line and uses a state-machine to properly parse everything.
You can see a demo with temp.R
which I've intentionally writen to highlight difficulties that knitr::spin
has