From: "Charles C. Berry" <ccberry@ucsd.edu>
To: Xebar Saram <zeltakc@gmail.com>
Cc: org mode <emacs-orgmode@gnu.org>, Philip Hudson <phil.hudson@iname.com>
Subject: Re: convert rmarkdown (rmd) files to orgmode?
Date: Thu, 21 Jul 2016 09:27:10 -0700 [thread overview]
Message-ID: <alpine.OSX.2.20.1607210901420.518@charles-berrys-macbook.local> (raw)
In-Reply-To: <CAOQHXPp4yt4rHCd1Mv-h-G=7pb_3a8Dx4PdHg6K4nM3gZ+_Vsw@mail.gmail.com>
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
prev parent reply other threads:[~2016-07-21 16:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-20 4:28 convert rmarkdown (rmd) files to orgmode? Xebar Saram
[not found] ` <CAJ1MqVF4Cq3ogH34P6AtSf0-ZX7ic=tApuX-ad=+14pLF7p1Aw@mail.gmail.com>
2016-07-20 11:15 ` Xebar Saram
2016-07-20 17:20 ` Charles C. Berry
2016-07-20 17:29 ` Xebar Saram
2016-07-20 17:42 ` Charles C. Berry
2016-07-20 18:00 ` Xebar Saram
2016-07-21 6:48 ` Xebar Saram
2016-07-21 16:27 ` Charles C. Berry [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.OSX.2.20.1607210901420.518@charles-berrys-macbook.local \
--to=ccberry@ucsd.edu \
--cc=emacs-orgmode@gnu.org \
--cc=phil.hudson@iname.com \
--cc=zeltakc@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).