emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* using a table from one org-file as a variable in a code block in another org-file
@ 2012-11-26 16:47 John Kitchin
  2012-11-26 17:32 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: John Kitchin @ 2012-11-26 16:47 UTC (permalink / raw)
  To: emacs-orgmode

Hi everyone,

I have been using tables as variables for codeblocks on an org-file, e.g.
#+tblname: class-data
| user      | oxide | xc |
| jkitchin  | TiO2  | LDA|
...

#+BEGIN_SRC python :var data=class-data
from pylab import *
import numpy as np

vol = [x[1]  if x[1] != '' else np.nan for x in data]
B = [x[2] if x[2] != '' else np.nan for x in data  ]

scatter(vol, B)
xlabel('Volume ($\AA^3$)')
ylabel('Bulk modulus (GPa)')
title('All polymorphs of all oxides for all functionals')
show()
#+END_SRC

This is a fantastic feature, since I can have some code that is
expensive to run create the table, but then have analysis code that is
quick, since it only reads the table.

But, sometimes the tables are defined in other org-files.  Is there a
way to specify a table from another org-file in the variable header?

Something like this would be pretty handy:

:var ./org-file.org::class-data

Especially if I could click on it, and have it open the other org-file
with point at the table!

Any thoughts? Thanks,

John

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

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

* Re: using a table from one org-file as a variable in a code block in another org-file
  2012-11-26 16:47 using a table from one org-file as a variable in a code block in another org-file John Kitchin
@ 2012-11-26 17:32 ` Eric Schulte
  2012-11-27  0:50   ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2012-11-26 17:32 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Hi everyone,
>
> I have been using tables as variables for codeblocks on an org-file, e.g.
> #+tblname: class-data
> | user      | oxide | xc |
> | jkitchin  | TiO2  | LDA|
> ...
>
> #+BEGIN_SRC python :var data=class-data
> from pylab import *
> import numpy as np
>
> vol = [x[1]  if x[1] != '' else np.nan for x in data]
> B = [x[2] if x[2] != '' else np.nan for x in data  ]
>
> scatter(vol, B)
> xlabel('Volume ($\AA^3$)')
> ylabel('Bulk modulus (GPa)')
> title('All polymorphs of all oxides for all functionals')
> show()
> #+END_SRC
>
> This is a fantastic feature, since I can have some code that is
> expensive to run create the table, but then have analysis code that is
> quick, since it only reads the table.
>
> But, sometimes the tables are defined in other org-files.  Is there a
> way to specify a table from another org-file in the variable header?
>
> Something like this would be pretty handy:
>
> :var ./org-file.org::class-data
>
> Especially if I could click on it, and have it open the other org-file
> with point at the table!
>
> Any thoughts? Thanks,
>

Hi John,

This feature does exist, and your guess at the syntax is almost correct.
To reference a variable named foo1 in a file named foo.org you would use
the following syntax, ":var data=foo.org:foo1".

See the attached foo.org and bar.org files for an example (in order to
work they must be in the same directory).

I'll make a note to mention this functionality in the documentation.

Best,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: foo.org --]
[-- Type: text/x-org, Size: 62 bytes --]


#+name: foo1
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: bar.org --]
[-- Type: text/x-org, Size: 125 bytes --]


#+begin_src sh :var data=foo.org:foo1
  echo "$data"
#+end_src

#+RESULTS:
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |


[-- Attachment #4: Type: text/plain, Size: 296 bytes --]


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

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: using a table from one org-file as a variable in a code block in another org-file
  2012-11-26 17:32 ` Eric Schulte
@ 2012-11-27  0:50   ` John Kitchin
  0 siblings, 0 replies; 3+ messages in thread
From: John Kitchin @ 2012-11-27  0:50 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

That is pretty awesome! Thanks!

John

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



On Mon, Nov 26, 2012 at 12:32 PM, Eric Schulte <schulte.eric@gmail.com> wrote:
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> Hi everyone,
>>
>> I have been using tables as variables for codeblocks on an org-file, e.g.
>> #+tblname: class-data
>> | user      | oxide | xc |
>> | jkitchin  | TiO2  | LDA|
>> ...
>>
>> #+BEGIN_SRC python :var data=class-data
>> from pylab import *
>> import numpy as np
>>
>> vol = [x[1]  if x[1] != '' else np.nan for x in data]
>> B = [x[2] if x[2] != '' else np.nan for x in data  ]
>>
>> scatter(vol, B)
>> xlabel('Volume ($\AA^3$)')
>> ylabel('Bulk modulus (GPa)')
>> title('All polymorphs of all oxides for all functionals')
>> show()
>> #+END_SRC
>>
>> This is a fantastic feature, since I can have some code that is
>> expensive to run create the table, but then have analysis code that is
>> quick, since it only reads the table.
>>
>> But, sometimes the tables are defined in other org-files.  Is there a
>> way to specify a table from another org-file in the variable header?
>>
>> Something like this would be pretty handy:
>>
>> :var ./org-file.org::class-data
>>
>> Especially if I could click on it, and have it open the other org-file
>> with point at the table!
>>
>> Any thoughts? Thanks,
>>
>
> Hi John,
>
> This feature does exist, and your guess at the syntax is almost correct.
> To reference a variable named foo1 in a file named foo.org you would use
> the following syntax, ":var data=foo.org:foo1".
>
> See the attached foo.org and bar.org files for an example (in order to
> work they must be in the same directory).
>
> I'll make a note to mention this functionality in the documentation.
>
> Best,
>
>
>
>>
>> John
>>
>> -----------------------------------
>> John Kitchin
>> Associate Professor
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> http://kitchingroup.cheme.cmu.edu
>>
>
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte
>

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

end of thread, other threads:[~2012-11-27  0:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-26 16:47 using a table from one org-file as a variable in a code block in another org-file John Kitchin
2012-11-26 17:32 ` Eric Schulte
2012-11-27  0:50   ` John Kitchin

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