R/yaml.load_file.R

Defines functions `yaml.load_file`

`yaml.load_file` <-
function(input, error.label, readLines.warn=TRUE, ...) {
  if (missing(error.label)) {
    if (inherits(input, "connection")) {
      # try to guess filename
      s <- try(summary(input), silent = TRUE)
      if (!inherits(s, "try-error") && is.list(s) && "description" %in% names(s)) {
        error.label <- s$description
      }
    }
    else if (is.character(input) && nzchar(input[1])) {
      error.label <- input[1]
    }
    else {
      error.label <- NULL
    }
  }

  if (is.character(input)) {
    con <- file(input, encoding = 'UTF-8')
    on.exit(close(con), add = TRUE)
  } else {
    con <- input
  }
  yaml.load(readLines(con, warn=readLines.warn),
            error.label = error.label, ...)
}

Try the yaml package in your browser

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

yaml documentation built on Jan. 24, 2023, 1:09 a.m.