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