R tools for handling Org (https://orgmode.org/) files
and markup: a generic function toOrg for transforming
R objects into Org markup (currently with methods for
dataframes, dates and times) and a function for reading
tables from Org files into data.frames.
To install the package from a running R session, type:
install.packages('orgutils', type = 'source',
repos = c('https://enricoschumann.net/R',
getOption('repos')))or clone/build the GitHub version.
Transform a data.frame into an Org table.
df <- data.frame(numbers = 1:5, row.names = LETTERS[1:5])
dfnumbers A 1 B 2 C 3 D 4 E 5
require("orgutils")
toOrg(df)| row.names | numbers | |-----------+---------| | A | 1 | | B | 2 | | C | 3 | | D | 4 | | E | 5 |
There is also a toOrg method for dates (class Date)
and times (classes POSIXct and POSIXlt).
toOrg(as.Date("2016-1-1"))<2016-01-01 Fri>
For inactive timestamps set the argument inactive to TRUE.
toOrg(as.POSIXct("2016-1-1 10:00:00"), inactive = TRUE)[2016-01-01 Fri 10:00:00]
Create an Org file with a table and read the table. Here ist
the file (note that R understands multiline strings).
tmp <-
"#+TITLE: A Table
Next comes a table.
#+name: test_table
| a | b |
|---+---|
| 1 | 2 |
| 3 | 4 |
That was a table.
"Write the file.
fname <- tempfile("testfile", fileext = ".org")
writeLines(tmp, fname)readOrg reads the org table and interprets it as a
data.frame.
require("orgutils")
readOrg(fname, table.name = "test_table")a b 1 1 2 2 3 4