1
2read_dcf <- function(file) {
3  lines <- readLines(file)
4
5  con <- textConnection(lines, local = TRUE)
6  fields <- colnames(read.dcf(con))
7  close(con)
8
9  if (!length(fields)) {
10    return(list(
11      dcf = create_fields(character(), character()),
12      notws = character()
13    ))
14  }
15
16  con <- textConnection(lines, local = TRUE)
17  res <- read.dcf(con, keep.white = fields)
18  close(con)
19
20  if (nrow(res) > 1) {
21    stop("Empty lines found in DESCRIPTION file", call. = FALSE)
22  }
23
24  con <- textConnection(lines, local = TRUE)
25  res2 <- read.dcf(con, keep.white = fields, all = TRUE)
26  close(con)
27
28  if (any(mismatch <- res != res2)) {
29    stop("Duplicate DESCRIPTION fields: ",
30         paste(sQuote(colnames(res)[mismatch]), collapse = ", "))
31  }
32
33  if ("Encoding" %in% colnames(res)) {
34    encoding <- res[, "Encoding"]
35    Encoding(res) <- encoding
36    res[] <- enc2utf8(res)
37    Encoding(lines) <- encoding
38    lines <- enc2utf8(lines)
39  }
40
41  no_tws_fields <- sub(
42    ":$",
43    "",
44    grep("^[^\\s]+:$", lines, perl = TRUE, value = TRUE)
45  )
46
47  notws <- res[1, match(no_tws_fields, fields)]
48
49  list(
50    dcf = create_fields(fields, res[1, ]),
51    notws = notws
52  )
53}
54