R/nm_read_table.R

Defines functions nm_read_table

Documented in nm_read_table

#' @importFrom methods setAs

suppressWarnings(
  suppressMessages(
    methods::setAs("character", "dummy.numeric", function(from) as.numeric(from))
  )
)

#' Fast read of NONMEM output table
#'
#' @description
#'
#' `r lifecycle::badge("stable")`
#'
#' Reads in $TABLE outputs rapidly.  [output_table()] is a higher level function
#' for reading output files and combining with input datasets.
#'
#' @param file File argument from `utils::read.table()`.
#' @param ... Other arguments to be passed to `utils::read.table()`.
#'
#' @return A `data.frame` from a relevant $TABLE output file.
#' @seealso [output_table()]
#' @export

nm_read_table <- function(file, ...) {
  if (!file.exists(file)) {
    usethis::ui_stop("The file {usethis::ui_path(file)} could not be found")
  }
  tmp <- suppressWarnings(utils::read.table(file, fill = T, colClasses = "dummy.numeric", ...))
  return(tmp[stats::complete.cases(tmp[, sapply(tmp, function(i) !all(is.na(i)))]), ])
}

Try the NMproject package in your browser

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

NMproject documentation built on Sept. 30, 2022, 1:06 a.m.