-
Notifications
You must be signed in to change notification settings - Fork 0
/
score-package.R
74 lines (60 loc) · 1.73 KB
/
score-package.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
74
score_package <- function(
risk_breaks = c(0.3, 0.7),
open_dirs = TRUE,
overwrite = TRUE
){
# Setup Directories
score_dir <- tempfile(pattern = "score_dir")
fs::dir_create(score_dir)
message(glue::glue("Scoring Directory: {score_dir}"))
# Open results directory
if(isTRUE(open_dirs)) rstudioapi::filesPaneNavigate(score_dir)
pkg_dir <- file.path(score_dir, "pkg_dir")
out_dir <- file.path(score_dir, "out_dir")
fs::dir_create(pkg_dir)
fs::dir_create(out_dir)
# Build package
tar_file <- devtools::build(pkg = ".", path = pkg_dir, quiet = TRUE)
# Score package
message("Scoring package...")
results_dir <- mpn.scorecard::score_pkg(
pkg = tar_file, out_dir = out_dir,
overwrite = overwrite
)
# Traceability Matrix
message("Making traceability matrix...")
library(tidyr)
trac_matrix <- mpn.scorecard::make_traceability_matrix(
tar_file, results_dir = results_dir
)
# Scorecard
message("Rendering PDF...")
pdf_path <- mpn.scorecard::render_scorecard(
results_dir,
risk_breaks = risk_breaks,
overwrite = overwrite,
add_traceability = "auto"
)
# Browse PDF
if(isTRUE(open_dirs)) browseURL(pdf_path)
return(
list(
score_dir = score_dir,
pdf_path = pdf_path,
trac_matrix = trac_matrix
)
)
}
overwrite_scorecard <- function(pdf_path){
devtools::load_all()
scorecard_dir <- system.file("scorecard", package = "pythonR", mustWork = TRUE)
fs::file_copy(pdf_path, scorecard_dir, overwrite = TRUE)
}
# Create scorecard
score_card <- score_package()
# rstudioapi::filesPaneNavigate(score_card$score_dir)
# Overwrite scorecard
# overwrite_scorecard(score_card$pdf_path)
# Deploy pkgdown site
# devtools::install()
# pkgdown::deploy_to_branch()