0

According to the docs if a file filename has a location in it like this, using the form (org-table-get-remote-range NAME-OR-ID FORM)

* Location
  :PROPERTIES:
  :CUSTOM_ID: Location
  :END:

  | a | b |
  |---+---|
  | 1 | 2 |

it should be possible to reference the table from another file using (org-table-get-remote-range "[[#Location][file:~/filename::#Location]]" "@I+1$1")

If the table is in another file, it ignores the table's #+NAME and uses the first table under the link.

I have tried it in so many ways and always get the error Can't find remote table "[[#Location][file:~/filename::#Location]]". I have even copied the links using org-store-linkandorg-insert-link` to ensure the references are right, but still get the error.

I am beginning to think that unless I've got the syntax wrong the code for accessing a table in another file is buggy.

1 Answer 1

1

The documentation of org-table-get-remote-range says that the name-or-id argument is either the name (as specified by #+name:) of a table in the current file or it is an ID that specifies some heading, possibly in the same file but possibly in a different file, in which case the argument refers to the first table found in that entry.

Here's an example: I have two files foo.org and bar.org. bar.org looks like this:


* bar
:PROPERTIES:
:ID:       2cca19d4-2df7-41f8-a653-ad1baeecc455
:END:


|  a |    b |      c |
|----+------+--------|
|  1 |    1 |      1 |
|  8 |   64 |    512 |
| 15 |  225 |   3375 |
| 22 |  484 |  10648 |
| 29 |  841 |  24389 |
| 36 | 1296 |  46656 |
| 43 | 1849 |  79507 |
| 50 | 2500 | 125000 |

where the ID property was created by calling org-id-get-create.

Then you can refer to the table in bar.org from the file foo.org as follows:

* using a remote call in a table formula
#+name: foo
|     a | b | c |
|-------+---+---|
|     1 |   |   |
|   512 |   |   |
|  3375 |   |   |
| 10648 |   |   |
| 24389 |   |   |
#+TBLFM: $1 = '(identity remote(2cca19d4-2df7-41f8-a653-ad1baeecc455, @@#$3))

With the exception of the ID usage, this is pretty much from the
[manual](https://orgmode.org/org.html#References): copy the third column of the remote table into the first
column of this table (or as much of it as fits).


* Using a call to org-table-get-remote-range from lisp code

Here is a call to =org-table-get-remote-range to illustrate:

#+begin_src elisp :results drawer
  ;; get the last row of the remote table
  (org-table-get-remote-range "2cca19d4-2df7-41f8-a653-ad1baeecc455"  "@>$1..@>$>")
#+end_src

#+RESULTS:
:results:
(50 2500 125000)
:end:

Some relevant settings which you should examine with describe-variable (C-h v): org-id-track-globally is t (the default), org-id-method is uuid, org-id-prefix is nil - you might want to change the last one, but the other two should be left at their defaults.

Note that CUSTOM_ID is different from ID and is not useful in this case: it is only useful to label a target for an internal link unambiguously.

3
  • Thanks. I thought NAME-or-ID referred to the filename in addition to the CUSTOM_ID that the table is under. I had in mind Excel references which are made of the filename as well as the range and I thought org tables are similar. I think I will make a request of it. It seems logical, and the ID only works if Emacs has read that file before.
    – vfclists
    Aug 24, 2022 at 19:15
  • What do you mean "... the ID only works if Emacs has read that file before"?
    – NickD
    Aug 25, 2022 at 21:15
  • If the file is moved after the ID is generated, won't Emacs lose track of the ID? If a file is opened and has IDs does Emacs re-index the ID database? Is there a command to re-index the ID database?
    – vfclists
    Aug 27, 2022 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.