otter is a small collection of functions that are useful for me, Ott, and hopefully for others too. Sharing is caring!
Currently otter provides rtf_to_df(), which parses RTF files and
extracts embedded tables into a data frame. It automatically detects
header rows, handles multi-page and multi-table RTF output, and supports
non-UTF-8 encodings.
You can install the development version of otter from GitHub with:
# install.packages("pak")
pak::pak("ottvahtrik/otter")rtf_to_df() reads an RTF table and returns its contents as a data
frame:
library(otter)
path <- system.file("extdata", "example.rtf", package = "otter")
rtf_to_df(path, include_header = TRUE)
#> Name Value
#> 1 Alice 10
#> 2 Bob 20If the RTF file contains multiple distinct tables, use table_index to
select one of them:
multi_path <- system.file("extdata", "multi_table_example.rtf", package = "otter")
rtf_to_df(multi_path, include_header = TRUE, table_index = 2L)
#> C D
#> 1 3 4