emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* running a source code by name
@ 2018-05-28 11:13 Julian M. Burgos
  2018-05-28 14:35 ` Eric S Fraga
  2018-05-28 22:58 ` Nick Dokos
  0 siblings, 2 replies; 8+ messages in thread
From: Julian M. Burgos @ 2018-05-28 11:13 UTC (permalink / raw)
  To: emacs-orgmode

Dear list,

I have an org file with an R source code block.  I want to have a second
code block with an elisp call to run that first code.  Something like this



#+begin_src emacs-lisp :results silent :tangle no

... Some elisp code to run the "myRcode" block.

#+end_src


#+NAME: myRcode
#+beg in_src R :results silent :tangle no

... My R code here

#+end_src

What would be the best way to do it?

Many thanks,

Julian


--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Botnsjávarsviðs / Demersal Division
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: julian.burgos@hafogvatn.is

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 11:13 running a source code by name Julian M. Burgos
@ 2018-05-28 14:35 ` Eric S Fraga
  2018-05-28 16:25   ` Berry, Charles
  2018-05-28 22:58 ` Nick Dokos
  1 sibling, 1 reply; 8+ messages in thread
From: Eric S Fraga @ 2018-05-28 14:35 UTC (permalink / raw)
  To: Julian M. Burgos; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 552 bytes --]

On Monday, 28 May 2018 at 11:13, Julian M. Burgos wrote:
> Dear list,
>
> I have an org file with an R source code block.  I want to have a second
> code block with an elisp call to run that first code.  Something like this
>
>
> #+begin_src emacs-lisp :results silent :tangle no
>
> ... Some elisp code to run the "myRcode" block.

Something along the lines of:

    (org-babel-goto-named-src-block "myRcode")
    (org-babel-execute-src-block)

should do the job?

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.6-591-gee336b

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 14:35 ` Eric S Fraga
@ 2018-05-28 16:25   ` Berry, Charles
  2018-05-28 20:16     ` John Kitchin
  0 siblings, 1 reply; 8+ messages in thread
From: Berry, Charles @ 2018-05-28 16:25 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: Julian M. Burgos, emacs-orgmode



> On May 28, 2018, at 7:35 AM, Eric S Fraga <esflists@gmail.com> wrote:
> 
> On Monday, 28 May 2018 at 11:13, Julian M. Burgos wrote:
>> Dear list,
>> 
>> I have an org file with an R source code block.  I want to have a second
>> code block with an elisp call to run that first code.  Something like this
>> 
>> 
>> #+begin_src emacs-lisp :results silent :tangle no
>> 
>> ... Some elisp code to run the "myRcode" block.
> 
> Something along the lines of:
> 
>    (org-babel-goto-named-src-block "myRcode")
>    (org-babel-execute-src-block)
> 
> should do the job?

Maybe wrap it in 

	(save-excursion ... ) 

or use 

	(org-sbe "myRcode")

or

	(org-babel-ref-resolve "myRcode") 

which both can also pass :var args.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 16:25   ` Berry, Charles
@ 2018-05-28 20:16     ` John Kitchin
  2018-05-28 20:30       ` Berry, Charles
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2018-05-28 20:16 UTC (permalink / raw)
  To: Berry, Charles; +Cc: Eric S Fraga, Julian M. Burgos, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]

Here is yet another variation, that may be suitable for what you want:


#+name: myPyCode
#+BEGIN_SRC python
print('Hello')
#+END_SRC


#+BEGIN_SRC emacs-lisp :var results=myPyCode
results
#+END_SRC

#+RESULTS:
: Hello


John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


On Mon, May 28, 2018 at 9:25 AM, Berry, Charles <ccberry@ucsd.edu> wrote:

>
>
> > On May 28, 2018, at 7:35 AM, Eric S Fraga <esflists@gmail.com> wrote:
> >
> > On Monday, 28 May 2018 at 11:13, Julian M. Burgos wrote:
> >> Dear list,
> >>
> >> I have an org file with an R source code block.  I want to have a second
> >> code block with an elisp call to run that first code.  Something like
> this
> >>
> >>
> >> #+begin_src emacs-lisp :results silent :tangle no
> >>
> >> ... Some elisp code to run the "myRcode" block.
> >
> > Something along the lines of:
> >
> >    (org-babel-goto-named-src-block "myRcode")
> >    (org-babel-execute-src-block)
> >
> > should do the job?
>
> Maybe wrap it in
>
>         (save-excursion ... )
>
> or use
>
>         (org-sbe "myRcode")
>
> or
>
>         (org-babel-ref-resolve "myRcode")
>
> which both can also pass :var args.
>
> HTH,
>
> Chuck
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2467 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 20:16     ` John Kitchin
@ 2018-05-28 20:30       ` Berry, Charles
  2018-05-30  6:59         ` Julian M. Burgos
  0 siblings, 1 reply; 8+ messages in thread
From: Berry, Charles @ 2018-05-28 20:30 UTC (permalink / raw)
  To: John Kitchin; +Cc: Eric S Fraga, Julian M. Burgos, emacs-orgmode

OK, I have to note that this will also do the job that the OP requested:

#+begin_src emacs-lisp :results silent :var result=myRcode

#+end_src

although it seems a little strange to write an empty src block for its side effects.

I suppose I should have suggested this in the first place:

#+begin_src emacs-lisp :results silent :noweb yes
<<myRcode()>>
#+end_src

although the return value from the noweb reference could be troublesome depending on what else is included in the latter src block.

Chuck

> On May 28, 2018, at 1:16 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> 
> Here is yet another variation, that may be suitable for what you want:
> 
> 
> #+name: myPyCode
> #+BEGIN_SRC python
> print('Hello')
> #+END_SRC
> 
> 
> #+BEGIN_SRC emacs-lisp :var results=myPyCode
> results
> #+END_SRC
> 
> #+RESULTS:
> : Hello
> 
> 
> John
> 
> -----------------------------------
> Professor John Kitchin 
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
> 
> 
> On Mon, May 28, 2018 at 9:25 AM, Berry, Charles <ccberry@ucsd.edu> wrote:
> 
> 
> > On May 28, 2018, at 7:35 AM, Eric S Fraga <esflists@gmail.com> wrote:
> > 
> > On Monday, 28 May 2018 at 11:13, Julian M. Burgos wrote:
> >> Dear list,
> >> 
> >> I have an org file with an R source code block.  I want to have a second
> >> code block with an elisp call to run that first code.  Something like this
> >> 
> >> 
> >> #+begin_src emacs-lisp :results silent :tangle no
> >> 
> >> ... Some elisp code to run the "myRcode" block.
> > 
> > Something along the lines of:
> > 
> >    (org-babel-goto-named-src-block "myRcode")
> >    (org-babel-execute-src-block)
> > 
> > should do the job?
> 
> Maybe wrap it in 
> 
>         (save-excursion ... ) 
> 
> or use 
> 
>         (org-sbe "myRcode")
> 
> or
> 
>         (org-babel-ref-resolve "myRcode") 
> 
> which both can also pass :var args.
> 
> HTH,
> 
> Chuck
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 11:13 running a source code by name Julian M. Burgos
  2018-05-28 14:35 ` Eric S Fraga
@ 2018-05-28 22:58 ` Nick Dokos
  1 sibling, 0 replies; 8+ messages in thread
From: Nick Dokos @ 2018-05-28 22:58 UTC (permalink / raw)
  To: emacs-orgmode

"Julian M. Burgos" <julian.burgos@hafogvatn.is> writes:

> Dear list,
>
> I have an org file with an R source code block.  I want to have a second
> code block with an elisp call to run that first code.  Something like this
>
>
> #+begin_src emacs-lisp :results silent :tangle no
>
> ... Some elisp code to run the "myRcode" block.

(org-sbe myRcode)

Untested.

>
> #+end_src
>
> #+NAME: myRcode
> #+beg in_src R :results silent :tangle no
>
> ... My R code here
>
> #+end_src
>
> What would be the best way to do it?
>
> Many thanks,
>
> Julian
>
>
> --
> Julian Mariano Burgos, PhD
> Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
> Marine and Freshwater Research Institute
> Botnsjávarsviðs / Demersal Division
> Skúlagata 4, 121 Reykjavík, Iceland
> Sími/Telephone : +354-5752037
> Bréfsími/Telefax:  +354-5752001
> Netfang/Email: julian.burgos@hafogvatn.is
>
>

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-28 20:30       ` Berry, Charles
@ 2018-05-30  6:59         ` Julian M. Burgos
  2018-05-30 16:16           ` Berry, Charles
  0 siblings, 1 reply; 8+ messages in thread
From: Julian M. Burgos @ 2018-05-30  6:59 UTC (permalink / raw)
  To: Berry, Charles; +Cc: Eric S Fraga, emacs-orgmode, John Kitchin

Thanks guys.  A combination of org-babel-goto-named-src-block and
org-babel-execute-src-block did the trick.

I am building an org template to create html presentations using the R
package xaringan.  In my case each slide is a markdown source block.
The elisp block tangles everything into a Rmd file, and the R block runs
rmarkdown::render and opens the resulting html file in a browser.

Thanks again. :)

Berry, Charles writes:

> OK, I have to note that this will also do the job that the OP requested:
>
> #+begin_src emacs-lisp :results silent :var result=myRcode
>
> #+end_src
>
> although it seems a little strange to write an empty src block for its side effects.
>
> I suppose I should have suggested this in the first place:
>
> #+begin_src emacs-lisp :results silent :noweb yes
> <<myRcode()>>
> #+end_src
>
> although the return value from the noweb reference could be troublesome depending on what else is included in the latter src block.
>
> Chuck
>
>> On May 28, 2018, at 1:16 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
>>
>> Here is yet another variation, that may be suitable for what you want:
>>
>>
>> #+name: myPyCode
>> #+BEGIN_SRC python
>> print('Hello')
>> #+END_SRC
>>
>>
>> #+BEGIN_SRC emacs-lisp :var results=myPyCode
>> results
>> #+END_SRC
>>
>> #+RESULTS:
>> : Hello
>>
>>
>> John
>>
>> -----------------------------------
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fkitchingroup.cheme.cmu.edu&data=02%7C01%7C%7Cfdaa27b411604ed32a0108d5c4d9fa01%7C8e105b94435e4303a61063620dbe162b%7C0%7C0%7C636631362846470731&sdata=4K%2B96NBf5KPaoz13laaAR0%2FaqY2FlefTLy%2BPXy6YtO8%3D&reserved=0
>>
>>
>> On Mon, May 28, 2018 at 9:25 AM, Berry, Charles <ccberry@ucsd.edu> wrote:
>>
>>
>> > On May 28, 2018, at 7:35 AM, Eric S Fraga <esflists@gmail.com> wrote:
>> >
>> > On Monday, 28 May 2018 at 11:13, Julian M. Burgos wrote:
>> >> Dear list,
>> >>
>> >> I have an org file with an R source code block.  I want to have a second
>> >> code block with an elisp call to run that first code.  Something like this
>> >>
>> >>
>> >> #+begin_src emacs-lisp :results silent :tangle no
>> >>
>> >> ... Some elisp code to run the "myRcode" block.
>> >
>> > Something along the lines of:
>> >
>> >    (org-babel-goto-named-src-block "myRcode")
>> >    (org-babel-execute-src-block)
>> >
>> > should do the job?
>>
>> Maybe wrap it in
>>
>>         (save-excursion ... )
>>
>> or use
>>
>>         (org-sbe "myRcode")
>>
>> or
>>
>>         (org-babel-ref-resolve "myRcode")
>>
>> which both can also pass :var args.
>>
>> HTH,
>>
>> Chuck
>>
>>
>>
>>
>>


--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Botnsjávarsviðs / Demersal Division
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: julian.burgos@hafogvatn.is

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: running a source code by name
  2018-05-30  6:59         ` Julian M. Burgos
@ 2018-05-30 16:16           ` Berry, Charles
  0 siblings, 0 replies; 8+ messages in thread
From: Berry, Charles @ 2018-05-30 16:16 UTC (permalink / raw)
  To: Julian M. Burgos; +Cc: Eric S Fraga, emacs-orgmode, John Kitchin



> On May 29, 2018, at 11:59 PM, Julian M. Burgos <julian.burgos@hafogvatn.is> wrote:
> 
> I am building an org template to create html presentations using the R
> package xaringan.  In my case each slide is a markdown source block.
> The elisp block tangles everything into a Rmd file, and the R block runs
> rmarkdown::render and opens the resulting html file in a browser.
> 

Oh. 

Maybe ox-ravel would save you some steps.  It can turn *.org into *.Rmd with R, C/C++, and other language chunks.

For examples, see the slidify.org and demos.org files at 

https://github.com/chasberry/orgmode-accessories

HTH,

Chuck

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-30 16:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-28 11:13 running a source code by name Julian M. Burgos
2018-05-28 14:35 ` Eric S Fraga
2018-05-28 16:25   ` Berry, Charles
2018-05-28 20:16     ` John Kitchin
2018-05-28 20:30       ` Berry, Charles
2018-05-30  6:59         ` Julian M. Burgos
2018-05-30 16:16           ` Berry, Charles
2018-05-28 22:58 ` Nick Dokos

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).