5
$\begingroup$

Simula to this post, is there a way to convert an org-mode table (say in the form of a string) to a Wolfram Dataset? So that for example this:

| Title          | Notes            |
|----------------+------------------|
| A title.       | Some notes.      |
| Another title. | Some more notes. |

gets converted into

Dataset[{<| "Title" -> "A title.", "Notes" -> "Some notes." |>, <| "Title" -> "Another title.", "Notes" -> "Some more notes."  }]

?

$\endgroup$

1 Answer 1

7
$\begingroup$
orgmode = "| Title          | Notes            |
  |----------------+------------------|
  | A title.       | Some notes.      |
  | Another title. | Some more notes. |";

{keys, vals} = {First @ #, Rest @ #} &[DeleteCases[""] /@ StringTrim /@ 
   StringSplit[Drop[StringSplit[orgmode, "\n"], {2}], "|"]]

{{"Title", "Notes"}, {{"A title.", "Some notes."}, {"Another title.", "Some more notes."}}}

ds = Dataset[AssociationThread[keys, #] & /@ vals]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ kglr: I am getting the following error w/AssociationThread when using this with the example: here. $\endgroup$
    – George
    Commented Dec 30, 2019 at 16:06
  • $\begingroup$ @George, pls try the updated version. $\endgroup$
    – kglr
    Commented Dec 30, 2019 at 16:22
  • $\begingroup$ kglr: Fixed! Thanks! $\endgroup$
    – George
    Commented Dec 30, 2019 at 16:34

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.