1
.parseRVignetteMetadata <- function(text, ...) {
2
  # Parse "\Vignette" directives into RSP metadata
3 1
  bfr <- unlist(strsplit(text, split="\n", fixed=TRUE), use.names=FALSE)
4

5 1
  pattern <- "[[:space:]]*%*[[:space:]]*\\\\Vignette(.*)\\{([^}]*)\\}"
6 1
  keep <- (regexpr(pattern, bfr) != -1L)
7 1
  bfr <- bfr[keep]
8

9
  # Nothing todo?
10 0
  if (length(bfr) == 0L) return(list())
11

12
  # Mapping from R vignette metadata to RSP metadata
13 1
  map <- c(
14
    # Official R vignette markup
15 1
    "IndexEntry"="title",
16 1
    "Keyword"="keyword",
17 1
    "Keywords"="keywords", ## Deprecated in R
18 1
    "Engine"="engine",
19
    # Custom
20 1
    "Subject"="subject",
21 1
    "Author"="author",
22 1
    "Date"="date",
23 1
    "Tangle"="tangle",
24 1
    "Compression"="compression"
25
  )
26

27 1
  metadata <- grep(pattern, bfr, value=TRUE)
28 1
  names <- gsub(pattern, "\\1", metadata)
29 1
  metadata <- gsub(pattern, "\\2", metadata)
30 1
  metadata <- trim(metadata)
31

32
  # Keep only known markup
33 1
  keep <- is.element(names, names(map))
34 1
  metadata <- metadata[keep]
35 1
  names <- names[keep]
36

37
  # Nothing todo?
38 0
  if (length(names) == 0L) return(list())
39

40
  # Rename
41 1
  names <- map[names]
42 1
  names(metadata) <- names
43 1
  metadata <- as.list(metadata)
44

45
  # Special: Merge all keyword meta data into one comma-separated entry
46 1
  idxs <- which(is.element(names(metadata), c("keyword", "keywords")))
47 1
  keywords <- unlist(metadata[idxs], use.names=FALSE)
48 1
  keywords <- paste(keywords, collapse=", ")
49 1
  metadata <- metadata[-idxs]
50 1
  metadata$keywords <- keywords
51

52 1
  metadata
53
} # .parseRVignetteMetadata()

Read our documentation on viewing source code .

Loading