Learn R Programming

orgutils (version 0.5-2)

toOrg: Generate Org-mode Markup

Description

Transform R objects into Org-mode objects.

Usage

toOrg(x, ...)

# S3 method for org print(x, ...)

# S3 method for data.frame toOrg(x, row.names = NULL, ...)

# S3 method for Date toOrg(x, inactive = FALSE, ...)

# S3 method for POSIXt toOrg(x, inactive = FALSE, ...)

Value

A character vector, usually with class org. In some cases, class character is additionally attached.

To save it to a file, use writeLines.

Arguments

x

an object

row.names

NULL, logical or character. If TRUE, row.names of x are added as the first column, with column name "row.names". If a character string, the string is used as the column name. See Examples.

If NULL, row.names are added when they are not 1, 2, ... (i.e. row numbers).

If FALSE, row.names are not added.

inactive

logical: use inactive timestamps? See https://orgmode.org/manual/Creating-timestamps.html .

...

other arguments

Author

Enrico Schumann

Details

Transforms an object x into character vectors with Org markup. Most useful when x is a data.frame.

toOrg is meant for snippets of code, not for producing whole Org documents.

When you work with POSIXt, make sure that a potential timezone does not cause trouble: Org does not support timezones.

References

Org mode manual https://orgmode.org/manual/index.html

See Also

toLatex, function as.orgtable in microplot

Examples

Run this code
toOrg(data.frame(a = 1:3, row.names = LETTERS[1:3]))
## =>  | row.names | a |
##     |-----------+---|
##     | A         | 1 |
##     | B         | 2 |
##     | C         | 3 |

toOrg(data.frame(a = 1:3))
## =>  | a |
##     |---|
##     | 1 |
##     | 2 |
##     | 3 |

toOrg(data.frame(a = 1:3), row.names = TRUE)
## =>  | row.names | a |
##     |-----------+---|
##     | 1         | 1 |
##     | 2         | 2 |
##     | 3         | 3 |


toOrg(data.frame(a = 1:5), row.names = "row numbers")
## =>  | row numbers | a |
##     |-------------+---|
##     | 1           | 1 |
##     | 2           | 2 |
##     | 3           | 3 |
##     | 4           | 4 |
##     | 5           | 5 |

if (FALSE) {
writeLines(toOrg(data.frame(a = 1:3)), "~/Desktop/my_table.org")}

## Dates/Times
toOrg(as.Date("2015-01-01"))                   ## <2015-01-01 Thu>
toOrg(as.Date("2015-01-01"), inactive = TRUE)  ## [2015-01-01 Thu]
toOrg(Sys.time())                              ## <2017-03-20 Mon 13:23:18>

## Convert Org dates to Date

## see ?strptime: Each input string is processed as far as
##                necessary for the format specified: any
##                trailing characters are ignored.
d <- toOrg(as.Date("2015-01-01"))
as.Date(d, "<%Y-%m-%d")

Run the code above in your browser using DataLab