Skip to content

Commit

Permalink
Merge pull request #203 from phuse-org/release_0.4.0
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
thebioengineer authored Nov 4, 2021
2 parents c11ad03 + a28a050 commit 5d9a003
Show file tree
Hide file tree
Showing 40 changed files with 1,392 additions and 161 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ CONTRIBUTING.md
^validation\.yml$

vignettes/validation/validation.yml
^man/figures/cheatsheets/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
valtools.Rproj
.Rproj.user
.Rhistory
inst/doc
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: valtools
Title: Automate Validated Package Creation
Version: 0.3.0
Version: 0.4.0
Authors@R:
c(
person(given = "Ellis",
family = "Hughes",
role = c("aut","cre"),
email = "ehhughes@scharp.org",
email = "ellishughes@live.com",
comment = c(ORCID = "0000-0003-0637-4436")),
person(given = "Eli",
family = "Miller",
Expand All @@ -23,6 +23,11 @@ Authors@R:
role = "aut",
email = "peymaan.es@gmail.com",
comment = c(ORCID = "0000-0003-1613-2705")),
person(given = "Maya",
family = "Gans",
role = "ctb",
email = "maya.gans@atorusresearch.com",
comment = c(ORCID = "0000-0002-5452-6089")),
person(given = "PHUSE",
role = "cph")
)
Expand All @@ -35,7 +40,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Suggests:
covr,
XML,
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ S3method(roxy_tag_rd,roxy_tag_riskAssessment)
export(vt_add_file_to_config)
export(vt_add_user_to_config)
export(vt_create_package)
export(vt_create_packet)
export(vt_drop_file_from_config)
export(vt_drop_user_from_config)
export(vt_dynamic_referencer)
Expand Down Expand Up @@ -87,6 +88,7 @@ importFrom(kableExtra,kable_styling)
importFrom(knitr,asis_output)
importFrom(knitr,current_input)
importFrom(knitr,kable)
importFrom(knitr,knit)
importFrom(knitr,knit_child)
importFrom(knitr,opts_knit)
importFrom(lubridate,parse_date_time)
Expand Down Expand Up @@ -128,9 +130,12 @@ importFrom(tools,file_ext)
importFrom(tools,file_path_sans_ext)
importFrom(usethis,create_package)
importFrom(usethis,edit_file)
importFrom(usethis,local_project)
importFrom(usethis,proj_activate)
importFrom(usethis,ui_stop)
importFrom(usethis,ui_value)
importFrom(usethis,use_git_ignore)
importFrom(usethis,use_rstudio)
importFrom(usethis,write_union)
importFrom(utils,capture.output)
importFrom(utils,getFromNamespace)
Expand Down
15 changes: 9 additions & 6 deletions R/case.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
vt_use_test_case <- function(name, username = vt_username(), title = NULL, open = interactive(),
add_before = NULL, add_after = NULL) {

name <- vt_set_ext(name, ext = "md")
name <- vt_set_ext(name, ext = c("md","rmd"))

is_valid_name(name)

Expand All @@ -60,14 +60,17 @@ vt_use_test_case <- function(name, username = vt_username(), title = NULL, open
username = username,
editDate = as.character(Sys.Date())
))


# Add file to validation configuration
vt_add_file_to_config(
filename = name,
after = {{add_after}},
before = {{add_before}}
)
}

# Add file to validation configuration
vt_add_file_to_config(filename = name, after = {{add_after}}, before = {{add_before}})

if(open){
edit_file(case_name)
edit_file(case_name) # nocov
}

invisible(case_name)
Expand Down
13 changes: 9 additions & 4 deletions R/code.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ vt_use_test_code <- function(name, username = vt_username(), open = interactive(
username = username,
editDate = as.character(Sys.Date())
))

# Add file to validation configuration
vt_add_file_to_config(
filename = name,
after = {{add_after}},
before = {{add_before}}
)
}

# Add file to validation configuration
vt_add_file_to_config(filename = name, after = {{add_after}},
before = {{add_before}})


if(open){
edit_file(code_name)
edit_file(code_name) # nocov
}

invisible(code_name)
Expand Down
27 changes: 19 additions & 8 deletions R/coverage-matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ vt_scrape_coverage_matrix <- function(type = c("long", "wide"),
do.call("rbind", apply(vals, 1, FUN = function(x){

this_row <- strsplit(x[["coverage"]], split = ":")[[1]]
if(length(this_row) == 1){
this_row <- rep(this_row, 2)

} else if(length(this_row) != 2){
rlang::abort(paste("Coverage details must follow format Test_Case:Requirement.",
"See", x[["tc_title"]]),
if(length(this_row) != 2){
rlang::abort(paste0("Coverage details must follow format Test_Case:Requirement.",
" See ", x[["tc_title"]], ", Coverage Entry: ",trimws(x[["coverage"]])),
class = "vt.coverage_format")
}
names(this_row) <- c("tc_id", "req_id")
Expand All @@ -31,19 +29,31 @@ vt_scrape_coverage_matrix <- function(type = c("long", "wide"),
}

split_req <- function(vals){
do.call("rbind", apply(vals, 1, FUN = function(x){
out <- do.call("rbind", apply(vals, 1, FUN = function(x){


req_one_row <- data.frame(tc_title = x[["tc_title"]],
tc_id = x[["tc_id"]],
req_id = strsplit(trimws(x[["req_id"]]), split = ", ")[[1]],
req_id = trimws(strsplit(trimws(x[["req_id"]]), split = ", ")[[1]]),
deprecate = x[["deprecate"]],
stringsAsFactors = FALSE)



req_one_row$req_title <- paste0("Requirement ", gsub(req_one_row$req_id,
pattern = "^(\\d+)\\.*.*",
replacement = "\\1"))

req_one_row
}))

# req_title uses only first numeric position
out$req_title <- factor(out$req_title,
levels = paste0("Requirement ",
sort(as.numeric(unique(unlist(lapply(strsplit(out$req_title, split = " "),
function(x){x[2]})))))))
out[order(out$req_title),]

}

# avoids dependency on tidyr::pivot_wider
Expand All @@ -64,6 +74,7 @@ vt_scrape_coverage_matrix <- function(type = c("long", "wide"),
x
})
out <- do.call("rbind", list_all_x)

row.names(out) <- 1:nrow(out)
out[, c("req_title", "req_id", sort(names(out)[-1:-2]))]
}
Expand Down Expand Up @@ -91,7 +102,7 @@ vt_scrape_coverage_matrix <- function(type = c("long", "wide"),
vals_all <- split_req(numbered_cov_vals)

if(type[1] == "long"){
out_data <- vals_all[order(vals_all$req_id),]
out_data <- vals_all[order(vals_all$req_title),]
row.names(out_data) <- 1:nrow(out_data)
out_data <- out_data[, c("req_title", "req_id", "tc_title", "tc_id", "deprecate")]
attr(out_data, "table_type") <- "long"
Expand Down
5 changes: 4 additions & 1 deletion R/dynamic_referencing.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ vt_dynamic_referencer <- R6::R6Class("vt_dynamic_referencer",
#' ref$list_references()

scrape_references = function(text){

## Drop roxygen comment headers from text for scraping references.
text <- unname(unlist(text[!grepl("^#'", text)]))

## drop NA text from scraping
text <- text[!is.na(text)]

reference_locations <-
gregexpr(
Expand Down
14 changes: 12 additions & 2 deletions R/file_and_path_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ vt_path <- function(...){
#'
#' @export
vt_find_config <- function(){

root <- find_root(has_file(".here") | is_rstudio_project | is_r_package | is_vcs_root)

tryCatch({
root <- find_root(has_file(".here") | is_rstudio_project | is_r_package | is_vcs_root)
}, error = function(e){
abort(
paste0(
"Could not find root directory. ",
"Is your working directory inside a package, validation packet, or project?\n"
),
class = "vt.validation_root_missing"
)
})

tryCatch({

Expand Down
67 changes: 66 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vt_use_validation <- function( pkg = ".", working_dir, ...) {
#' @inheritParams usethis::create_package
#'
#' @importFrom usethis create_package
#' @importFrom rlang inform abort
#' @importFrom rlang inform abort is_interactive
#'
#' @rdname val_init
#'
Expand Down Expand Up @@ -89,6 +89,62 @@ vt_create_package <- function(pkg = ".", ..., fields = list(), rstudio = rstudio

}

#' @description Create the validation packet infrastructure. Intended to create
#' validation infrastructure external to an R package.
#'
#' @param target target of validation. Character name of package or scope validation packet is being performed for.
#' @param ... Additional argument passed to `vt_use_config()`
#' @inheritParams usethis::create_project
#'
#' @importFrom usethis use_rstudio local_project proj_activate
#' @importFrom rlang inform abort is_interactive
#'
#' @rdname val_init
#'
#' @export
vt_create_packet <- function(path = ".", target, ..., rstudio = rstudioapi::isAvailable(), open = rlang::is_interactive()) {

if(is_package(path)){
abort(paste0(
"`vt_create_packet()` is not intended to add validation infrastructure",
" to an existing package. Use `vt_use_validation()` instead."
))
}

tryCatch({

if(!dir.exists(path)){
dir.create(path = path, recursive = TRUE, showWarnings = FALSE)
usethis::with_project(path = path,force = TRUE,{
if(rstudio){
usethis::use_rstudio()
}else{
file.create(".here")
}
})
}

## set up validation structure in package & create basic config for validation
vt_use_validation(pkg = path, working_dir = ".", package = target, ...)

inform("Created validation packet",
class = "vt.initPacket")

}, error = function(e) {
abort(paste0("Failed to create validation packet.\n", #nocov
e, sep = "\n"), #nocov
class = "vt.initPacketFail") #nocov

})

if(open){
usethis::proj_activate(path = path)
}

invisible()

}

#' Internal wrapper function to call vt_create_package().
#' To be used by RStudio project wizard, preventing opening the project twice.
#'
Expand All @@ -99,5 +155,14 @@ vt_create_package_wizard <- function(path, ...){
vt_create_package(pkg= path, open= FALSE, ...) # nocov
}

#' Internal wrapper function to call vt_create_packet().
#' To be used by RStudio project wizard, preventing opening the project twice.
#'
#' @param path Project directory, collected through project wizard
#'
#' @noRd
vt_create_packet_wizard <- function(path, ...){
vt_create_packet(path = path, open= FALSE, ...) # nocov
}


11 changes: 8 additions & 3 deletions R/req.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vt_use_req <- function(name, username = vt_username(), title = NULL, open = inte
add_before = NULL, add_after = NULL){

# ensure file extensions are of the acceptable type
name <- vt_set_ext(name, ext = "md")
name <- vt_set_ext(name, ext = c("md", "rmd"))

is_valid_name(name)

Expand All @@ -29,12 +29,17 @@ vt_use_req <- function(name, username = vt_username(), title = NULL, open = inte
title = title,
editDate = as.character(Sys.Date())
))

vt_add_file_to_config(
filename = name,
after = {{add_after}},
before = {{add_before}}
)
}

vt_add_file_to_config(filename = name, after = {{add_after}}, before = {{add_before}})

if(open){
edit_file(req_name)
edit_file(req_name) # nocov
}

invisible(req_name)
Expand Down
3 changes: 3 additions & 0 deletions R/roxygen_extension.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ roxy_tag_parse.roxy_tag_deprecate <- function(x) {
tag_markdown(x)
}

# nocov start

#' @export
#' @importFrom roxygen2 rd_section roxy_tag_rd
roxy_tag_rd.roxy_tag_editor <- function(x, base_path, env) {
Expand Down Expand Up @@ -97,6 +99,7 @@ format.rd_section_deprecate <- function(x, ...) {
)
}

# nocov end

format_coverage_text <- function(x){

Expand Down
Loading

0 comments on commit 5d9a003

Please sign in to comment.