emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] convert rmarkdown (rmd) files to orgmode?


From: Charles C. Berry
Subject: Re: [O] convert rmarkdown (rmd) files to orgmode?
Date: Thu, 21 Jul 2016 09:27:10 -0700
User-agent: Alpine 2.20 (OSX 67 2015-01-07)

On Wed, 20 Jul 2016, Xebar Saram wrote:

Hi again

Chuck:

is there a way to modify you nice code regex code snippet to simultaneously
change all example blocks to R blocks in a converted rmd>org file?
so when executing the block all example blocks:


#+BEGIN_EXAMPLE
    help.search("rnorm")
#+END_EXAMPLE

will turn into R blocks

#+BEGIN_SRC R :session Rorg  :results none
    help.search("rnorm")
#+END_SRC


The obvious thing is to do this with two additional `replace' operations.

Interactively, you can use `replace-string' to do this, since those are fixed strings and there are no backreferences to worry about. I think there is a dired-mode incantation that would allow you to do this on all files in a directory if you wanted.

But see the docstring for 'replace-string' which shows a better incantation for programmatically doing the changes.

IMO, you would be better served by doiing this in a scripting language like bash or python, but even R could do it.

One reason for using a scripting language is that unless you are a wiz at elisp, it is easier to report back the changes that are made in context; if you convert something that truly *is* an example block, you want to know about it so you can back out that change. Also, it is possible that the R code in the file you are converting will contain characters that will foil the regexp matching and you really need to catch those.

I'd be tempted to do it in R - at least in part - so I could parse() the result to check that it is valid code. The ESS suite has some parsing capabilities, but if you do not already know them using R will be a lot easier. An example block that does not produce valid code might be something you should leave as an example block.

Write a script that does all the conversion including the pandoc bit. Then run that at the command line.

Chuck




reply via email to

[Prev in Thread] Current Thread [Next in Thread]