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$
6
$\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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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