R/read.R

Defines functions read_pb read_boost_ini

Documented in read_boost_ini read_pb

#' Functions to read files
#'
#' @description
#' `read_boost_ini()` reads an INI-like config file of boost::program_options.
#' @param file filename or text
#' @rdname read
#' @export
read_boost_ini = function(file) {
  tsv = readr::read_delim(file, "=", col_names = c("key", "val"), comment = "#", trim_ws = TRUE) |>
    dplyr::summarize(dplyr::across(tidyselect::everything(), \(x) paste0(x, collapse = "\t"))) |>
    paste0(collapse = "\n")
  readr::read_tsv(I(tsv))
}

#' @description
#' `read_pb()` reads paste board to a character.
#' @rdname read
#' @export
read_pb = function() {
  readr::read_file(I(pipe("pbpaste")))
}
heavywatal/rwtl documentation built on April 29, 2024, 2:02 a.m.