-
Notifications
You must be signed in to change notification settings - Fork 21
/
guess_other_metadata.R
74 lines (60 loc) · 2.09 KB
/
guess_other_metadata.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# guess_releaseNotes -----------------------------------------------------------
guess_releaseNotes <- function(root = ".", cm) {
## First look for a local NEWS.md or NEWS
news_files <- c("NEWS.md", "NEWS")
## Do the news files exist?
file_exists <- file.exists(file.path(root, news_files))
## Give up if there is no news file or if Git is not used
if (! any(file_exists) || ! uses_git(root)) {
return(NULL)
}
## Point to the first file that was found: NEWS.md or NEWS on the GitHub page
github_path(root, news_files[file_exists][1], cm)
## Consider pointing to CRAN NEWS, BIOC NEWS?
}
# guess_fileSize ---------------------------------------------------------------
#' @title Estimate the File Size of the Software
#'
#' @description The function makes a rough estimation of the size of the
#' R package using the base R function [file.size]. Files in `.Rbuildignore` are
#' exclude. Please note that this estimation does not necessarily reflect the installed size
#' of the package.
#'
#' @param root the root file path
#'
#' @param .ignore optional vector of regular expresssions that will be ignore when the file
#' size is guessed
#'
#' @seealso [base::file.size]
#'
#' @examples
#'
#' guess_fileSize()
#'
#' @md
#' @noRd
guess_fileSize <- function(root = ".", .ignore = NULL) {
## no root, no file size
if (is.null(root))
return(NULL)
## check for .Rbuildignore, everything listed should be excluded since
## it will not become part of the final package
rbuildignore_path <- file.path(root,".Rbuildignore")
if (file.exists(rbuildignore_path) && is.null(.ignore)){
.ignore <- readLines(normalizePath(rbuildignore_path), warn = FALSE)
}else{
.ignore <- " "
}
## grep all files of interest (exclude hidden files)
files <- normalizePath(list.files(
path = normalizePath(root),
recursive = TRUE,
full.names = TRUE,
all.files = FALSE
))
## kick-out all files that do not belong to the R package
files <-
files[!grepl(paste(.ignore, collapse = "|"), files, perl = TRUE)]
## estimate total size
paste0(sum(file.size(files)) / 1e3, "KB")
}