year <- sub("-.*", "", meta$Date)

if (!length(year)) {
  i <- regexpr("(?<=\\s{1})\\d{4}(?=-{1})", meta$Built, perl = TRUE)
  year <- substring(meta$Built, i, i + 3)
}

if (!length(year))
  year <- substr(Sys.Date(),1,4)

pkg <- meta$Package
vers <- meta$Version
title <- meta$Title

if (is.null(vers))
  vers <- packageVersion(pkg)

vers <- paste("R package version", vers)

author <- meta$`Authors@R`
if (length(author)) {
  aar <- .read_authors_at_R_field(author)
  author <- Filter(function(e) {
    !(is.null(e$given) && is.null(e$family)) && !is.na(match("aut", e$role))
  }, aar)
  if (!length(author))
    author <- Filter(function(e) {
      !(is.null(e$given) && is.null(e$family)) && !is.na(match("cre", e$role))
    }, aar)
}

author <- format(author, include = c("given", "family"))
if (length(author) > 1L)
  author <- paste(paste(head(author, -1L), collapse = ", "),
                  tail(author, 1L), sep = " and ")

bibentry(
  bibtype = "Manual",
  title   = paste0("{", pkg, "}: ", title),
  author  = author,
  year    = year,
  note    = vers,
  url     = "https://CRAN.R-project.org/package=qualpalr",
  header  = "To cite use of the qualpalr R package in publications, please use:"
)
