* convert rmarkdown (rmd) files to orgmode?
@ 2016-07-20 4:28 Xebar Saram
[not found] ` <CAJ1MqVF4Cq3ogH34P6AtSf0-ZX7ic=tApuX-ad=+14pLF7p1Aw@mail.gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Xebar Saram @ 2016-07-20 4:28 UTC (permalink / raw)
To: org mode
[-- Attachment #1: Type: text/plain, Size: 190 bytes --]
Hi all
anyone know of a way to convert rmarkdown (rmd) files to orgmode?
im preparing a R course and lots of cool examples in R are in rmd format so
it could be very useful to me
best
Z
[-- Attachment #2: Type: text/html, Size: 309 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
[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
0 siblings, 1 reply; 8+ messages in thread
From: Xebar Saram @ 2016-07-20 11:15 UTC (permalink / raw)
To: Philip Hudson, org mode
[-- Attachment #1: Type: text/plain, Size: 1036 bytes --]
thx phil
the Rmd format is actually quite different than md so that conversion didnt
go well
i ended up doing a 2 step conversion:
in R (via the GUI or through R -e command line), first convert the Rmd
files to md files:
require(knitr) # required for knitting from rmd to md
require(markdown) # required for md to html
knit('test.rmd', 'test.md') # creates md file
then use pandoc to convert the md files to org:
pandoc -o test.org test.md
this gives an almost 1:1 org file
thx
Z
On Wed, Jul 20, 2016 at 1:08 PM, Philip Hudson <phil.hudson@iname.com>
wrote:
> pandoc -f markdown -t org myfile.rmd
>
> On 20 July 2016 at 05:28, Xebar Saram <zeltakc@gmail.com> wrote:
> > Hi all
> >
> > anyone know of a way to convert rmarkdown (rmd) files to orgmode?
> >
> > im preparing a R course and lots of cool examples in R are in rmd format
> so
> > it could be very useful to me
> >
> > best
> >
> > Z
>
>
>
> --
> Phil Hudson http://hudson-it.ddns.net
> @UWascalWabbit PGP/GnuPG ID: 0x887DCA63
>
[-- Attachment #2: Type: text/html, Size: 2034 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-20 11:15 ` Xebar Saram
@ 2016-07-20 17:20 ` Charles C. Berry
2016-07-20 17:29 ` Xebar Saram
0 siblings, 1 reply; 8+ messages in thread
From: Charles C. Berry @ 2016-07-20 17:20 UTC (permalink / raw)
To: Xebar Saram; +Cc: org mode, Philip Hudson
On Wed, 20 Jul 2016, Xebar Saram wrote:
> thx phil
>
> the Rmd format is actually quite different than md so that conversion didnt
> go well
>
I tried this
pandoc -f markdown -t org input-file.Rmd -o output-file.org
then I opened `output-file.org' and put this src block at the very top:
#+BEGIN_SRC emacs-lisp :results silent
(replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
"#+name: \\1
,#+begin_src R
\\2
,#+end_src")
#+END_SRC
When I execute that code block, all the converted code chunks become src
blocks.
This isn't perfect as chunk options are appended to the `#+NAME:...' line,
but if you want to play with the regexp's you can probably get it to pick
those out and put them on a separate line. Or just write another src block
with another `replace-regexp' to fix those lines.
With a little effort you can write a command file for `sed' to do what the
code block above does and then pipe the pandoc output to that command like
this:
: pandoc -f markdown -t org input-file.Rmd | \
: sed -f convert-chunks > output-file.org
and you have an org document ready (or almost ready) to go.
HTH,
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-20 17:20 ` Charles C. Berry
@ 2016-07-20 17:29 ` Xebar Saram
2016-07-20 17:42 ` Charles C. Berry
0 siblings, 1 reply; 8+ messages in thread
From: Xebar Saram @ 2016-07-20 17:29 UTC (permalink / raw)
To: Charles C. Berry; +Cc: org mode, Philip Hudson
[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]
thx for the tips!
when i try to run the source block :
#+BEGIN_SRC emacs-lisp :results silent
(replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
"#+name: \\1
,#+begin_src R
\\2
,#+end_src")
#+END_SRC
i just get a nil in the message area. what am i missing?
thx
Z
On Wed, Jul 20, 2016 at 8:20 PM, Charles C. Berry <ccberry@ucsd.edu> wrote:
> On Wed, 20 Jul 2016, Xebar Saram wrote:
>
> thx phil
>>
>> the Rmd format is actually quite different than md so that conversion
>> didnt
>> go well
>>
>>
> I tried this
>
> pandoc -f markdown -t org input-file.Rmd -o output-file.org
>
> then I opened `output-file.org' and put this src block at the very top:
>
> #+BEGIN_SRC emacs-lisp :results silent
> (replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
> "#+name: \\1
> ,#+begin_src R
> \\2
> ,#+end_src")
>
> #+END_SRC
>
> When I execute that code block, all the converted code chunks become src
> blocks.
>
> This isn't perfect as chunk options are appended to the `#+NAME:...' line,
> but if you want to play with the regexp's you can probably get it to pick
> those out and put them on a separate line. Or just write another src block
> with another `replace-regexp' to fix those lines.
>
> With a little effort you can write a command file for `sed' to do what the
> code block above does and then pipe the pandoc output to that command like
> this:
>
> : pandoc -f markdown -t org input-file.Rmd | \
> : sed -f convert-chunks > output-file.org
>
> and you have an org document ready (or almost ready) to go.
>
>
> HTH,
>
> Chuck
>
>
[-- Attachment #2: Type: text/html, Size: 2655 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-20 17:29 ` Xebar Saram
@ 2016-07-20 17:42 ` Charles C. Berry
2016-07-20 18:00 ` Xebar Saram
0 siblings, 1 reply; 8+ messages in thread
From: Charles C. Berry @ 2016-07-20 17:42 UTC (permalink / raw)
To: Xebar Saram; +Cc: org mode, Philip Hudson
On Wed, 20 Jul 2016, Xebar Saram wrote:
> thx for the tips!
>
> when i try to run the source block :
>
> #+BEGIN_SRC emacs-lisp :results silent
> (replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
> "#+name: \\1
> ,#+begin_src R
> \\2
> ,#+end_src")
>
> #+END_SRC
>
> i just get a nil in the message area. what am i missing?
>
Nothing!
The `:results silent' should suppress any output.
Anyway, what you should see is that the code chunks that pandoc placed
inside equal signs like
: ={r my-name} code =
are now in src blocks.
I think you need to put the src block at the top or add a
: (goto-char (point-min))
as its first line to be sure it converts all the code chunks.
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-20 17:42 ` Charles C. Berry
@ 2016-07-20 18:00 ` Xebar Saram
2016-07-21 6:48 ` Xebar Saram
0 siblings, 1 reply; 8+ messages in thread
From: Xebar Saram @ 2016-07-20 18:00 UTC (permalink / raw)
To: Charles C. Berry; +Cc: org mode, Philip Hudson
[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]
ahh i see what you mean.
thats a cool tip yet i find i have to find/replace also for images,
find/replace to change example blocks to R code blocks etc which is quite
tedious since i have about 50 of these converted Rmd to org files :)
ill keep investigating this and report back
thx so much for the tips! :)
Z
On Wed, Jul 20, 2016 at 8:42 PM, Charles C. Berry <ccberry@ucsd.edu> wrote:
> On Wed, 20 Jul 2016, Xebar Saram wrote:
>
> thx for the tips!
>>
>> when i try to run the source block :
>>
>> #+BEGIN_SRC emacs-lisp :results silent
>> (replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
>> "#+name: \\1
>> ,#+begin_src R
>> \\2
>> ,#+end_src")
>>
>> #+END_SRC
>>
>> i just get a nil in the message area. what am i missing?
>>
>>
>
> Nothing!
>
> The `:results silent' should suppress any output.
>
> Anyway, what you should see is that the code chunks that pandoc placed
> inside equal signs like
>
> : ={r my-name} code =
>
> are now in src blocks.
>
> I think you need to put the src block at the top or add a
>
> : (goto-char (point-min))
>
> as its first line to be sure it converts all the code chunks.
>
>
> Chuck
>
[-- Attachment #2: Type: text/html, Size: 1835 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-20 18:00 ` Xebar Saram
@ 2016-07-21 6:48 ` Xebar Saram
2016-07-21 16:27 ` Charles C. Berry
0 siblings, 1 reply; 8+ messages in thread
From: Xebar Saram @ 2016-07-21 6:48 UTC (permalink / raw)
To: Charles C. Berry; +Cc: org mode, Philip Hudson
[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]
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
thx!
Z
On Wed, Jul 20, 2016 at 9:00 PM, Xebar Saram <zeltakc@gmail.com> wrote:
> ahh i see what you mean.
>
> thats a cool tip yet i find i have to find/replace also for images,
> find/replace to change example blocks to R code blocks etc which is quite
> tedious since i have about 50 of these converted Rmd to org files :)
> ill keep investigating this and report back
>
> thx so much for the tips! :)
>
> Z
>
> On Wed, Jul 20, 2016 at 8:42 PM, Charles C. Berry <ccberry@ucsd.edu>
> wrote:
>
>> On Wed, 20 Jul 2016, Xebar Saram wrote:
>>
>> thx for the tips!
>>>
>>> when i try to run the source block :
>>>
>>> #+BEGIN_SRC emacs-lisp :results silent
>>> (replace-regexp "^=[{]r \\([^}]*\\)[}]\\(.*\\)=$"
>>> "#+name: \\1
>>> ,#+begin_src R
>>> \\2
>>> ,#+end_src")
>>>
>>> #+END_SRC
>>>
>>> i just get a nil in the message area. what am i missing?
>>>
>>>
>>
>> Nothing!
>>
>> The `:results silent' should suppress any output.
>>
>> Anyway, what you should see is that the code chunks that pandoc placed
>> inside equal signs like
>>
>> : ={r my-name} code =
>>
>> are now in src blocks.
>>
>> I think you need to put the src block at the top or add a
>>
>> : (goto-char (point-min))
>>
>> as its first line to be sure it converts all the code chunks.
>>
>>
>> Chuck
>>
>
>
[-- Attachment #2: Type: text/html, Size: 3032 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: convert rmarkdown (rmd) files to orgmode?
2016-07-21 6:48 ` Xebar Saram
@ 2016-07-21 16:27 ` Charles C. Berry
0 siblings, 0 replies; 8+ messages in thread
From: Charles C. Berry @ 2016-07-21 16:27 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-07-21 16:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.