17/05: reading org-mode tables into R

Tags:

I don't do a lot of manual data entry, but when I do I like to use tables in org-mode, which takes care of alignment and provides some convenient keyboard shortcuts for moving around the table, adding and deleting columns and row, etc. To get the data into R , you could export the table to a plain-text format, or you can use the following function in R, which uses sed to strip out all the org-mode formatting:



The function only works if there's one table in the file, or if all the tables have the same number of columns. The sed command can be used from the shell, of course, but you may have to play with the escaping depending on your shell and sed version (GNU sed is very different from BSD sed) - the double backslashes are necessary to pass '\\' to R, and '\\t' will be expanded to tabs.

Comments