1package_files <- function(path) {
2  all <- normalizePath(r_files(path))
3
4  collate <- desc::desc_get_collate(file = file.path(path, "DESCRIPTION"))
5
6  collate <- normalizePath(file.path(path, "R", collate))
7
8  rfiles <- c(collate, setdiff(all, collate))
9  ignore_files(rfiles, path)
10}
11
12r_files <- function(path) {
13  sort_c(dir(file.path(path, "R"), "\\.[Rr]$", full.names = TRUE))
14}
15
16ignore_files <- function(rfiles, path) {
17  rbuildignore <- file.path(path, ".Rbuildignore")
18  if (!file.exists(rbuildignore))
19    return(rfiles)
20
21  # Strip leading directory and slashes
22  rfiles_relative <- sub(normalizePath(path, winslash = "/"), "", normalizePath(rfiles, winslash = "/"), fixed = TRUE)
23  rfiles_relative <- sub("^[/]*", "", rfiles_relative)
24
25  # Remove any files that match any perl-compatible regexp
26  patterns <- read_lines(rbuildignore)
27  patterns <- patterns[patterns != ""]
28  if (length(patterns) == 0L) {
29    return(rfiles)
30  }
31  matches <- lapply(patterns, grepl, rfiles_relative, perl = TRUE)
32  matches <- Reduce("|", matches)
33  rfiles[!matches]
34}
35