R/read_trimmed_lines.R

Defines functions read_trimmed_lines

Documented in read_trimmed_lines

#' Read lines, thereby trimming empty spaces around the strings and removing empty lines
#' @param file A text file
#' @param skipNul Skip NULL line (passed to \code{readLines})
#' @param ... Other paratmers than \code{skipNul} passed to readLines
#'
#' @return Character vector of trimmed, non-empty lines.
#' @examples
#' lines <- "  ABC \n\tHBV\n\nFCB  \n\n"
#' trimmedLines <- read_trimmed_lines(textConnection(lines))
#' stopifnot(identical(trimmedLines, c("ABC", "HBV", "FCB")))
#' @export
read_trimmed_lines <- function(file, skipNul=TRUE, ...) {
    lines <- readLines(file, skipNul=skipNul, ...)
    lines <- trim(lines)
    lines <- setdiff(lines, "")
    return(lines)
}

Try the ribiosIO package in your browser

Any scripts or data that you put into this service are public.

ribiosIO documentation built on Feb. 20, 2026, 5:09 p.m.