From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles C. Berry" Subject: Re: convert rmarkdown (rmd) files to orgmode? Date: Thu, 21 Jul 2016 09:27:10 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGp0-0001za-6Y for emacs-orgmode@gnu.org; Thu, 21 Jul 2016 12:27:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQGov-00085d-Tn for emacs-orgmode@gnu.org; Thu, 21 Jul 2016 12:27:37 -0400 Received: from iport-acv3-out.ucsd.edu ([132.239.0.4]:57826) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQGov-00085W-HC for emacs-orgmode@gnu.org; Thu, 21 Jul 2016 12:27:33 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Xebar Saram Cc: org mode , Philip Hudson 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