Skip to content

Commit

Permalink
v0.0.1 Release Final Touches (#77)
Browse files Browse the repository at this point in the history
* chore: add @returns, cran-comments.md, remove remotes suggested dependency

* fix: initial CRAN notes

* fix: add new cran-comments to buildignore

* skip reexport.srcrefs package tests on cran

* more updates for CRAN submission
  • Loading branch information
dgkf authored Jul 10, 2024
1 parent a341800 commit b8cc02b
Show file tree
Hide file tree
Showing 59 changed files with 425 additions and 244 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^\.github$
^doc$
^Meta$
^cran-comments\.md$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ inst/doc
README.html
/doc/
/Meta/
*\.tar\.gz
45 changes: 28 additions & 17 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
Package: covtracer
Title: Tools for contextualizing tests
Version: 0.0.0.9016
Authors@R: c(
Title: Contextualizing Tests
Version: 0.0.1
Authors@R:
c(
person(
given = "Doug",
family = "Kelkhoff",
role = c("aut", "cre"),
email = "kelkhofd@gene.com"),
"Doug", "Kelkhoff", ,
"doug.kelkhoff@gmail.com",
role = c("cre", "aut"),
comment = c(ORCID = "0009-0003-7845-4061")
),
person(
given = "Szymon",
family = "Maksymiuk",
role = c("aut"),
email = "sz.maksymiuk@gmail.com",
comment = c(ORCID = "0000-0002-3120-1601")
),
person(
given = "Andrew",
family = "McNeil",
role = c("aut"),
email = "andrew.richard.mcneil@gmail.com")
email = "andrew.richard.mcneil@gmail.com"
),
person(
"F. Hoffmann-La Roche AG",
role = c("cph", "fnd")
)
)
Description:
Provides tools for dissecting a package namespace or "covr" coverage object
in order to cross reference tested code with the lines that are evaluated, as
well as linking those evaluated lines to the documentation that they are
described within. Connecting these three pieces of information provides a
mechanism of linking tests to documented behaviors.
Dissects a package environment or 'covr' coverage object in order to cross
reference tested code with the lines that are evaluated, as well as linking
those evaluated lines to the documentation that they are described within.
Connecting these three pieces of information provides a mechanism of
linking tests to documented behaviors.
URL: https://github.com/genentech/covtracer
BugReports: https://github.com/genentech/covtracer/issues
Depends:
Expand All @@ -29,7 +43,6 @@ Imports:
methods
Suggests:
testthat,
remotes,
covr (>= 3.5.2),
withr,
R6,
Expand All @@ -38,11 +51,9 @@ Suggests:
igraph,
knitr,
rmarkdown
Remotes:
github::r-lib/covr
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2022
COPYRIGHT HOLDER: Genentech
YEAR: 2024
COPYRIGHT HOLDER: F. Hoffmann-La Roche AG
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased (tentative 0.0.1)
# covtracer 0.0.1

* initial CRAN release

# covtracer 0.0.0.9000

* Fix handling for packages with no objects (#73, @dgkf)

Expand Down
2 changes: 1 addition & 1 deletion R/Rd_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Rd_df <- function(x) {
if (length(doctype)) doctype else NA_character_
}, character(1L))

aliases <- aliases[sort(names(aliases))] # avoid OS-specific file sorting
aliases <- aliases[sort(names(aliases))] # avoid OS-specific file sorting
naliases <- vapply(aliases, length, integer(1L))
files <- rep(names(db), times = naliases)
doctype <- rep(doctype, times = naliases)
Expand Down
4 changes: 3 additions & 1 deletion R/getSrcFilepath.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ getSrcFilepath.default <- function(x) {
path <- getSrcFilename(x, full.names = TRUE)
wd <- attr(getSrcref(x), "srcfile")$wd
if (!is.null(wd)) path <- file.path(wd, path)
if (!length(path)) return(NA_character_)
if (!length(path)) {
return(NA_character_)
}
normalizePath(path, winslash = "/", mustWork = FALSE)
}

Expand Down
15 changes: 11 additions & 4 deletions R/list_of_srcref.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Create an S3 list of srcref objects
#'
#' @param x A list or single srcref to coerce to a list_of_srcref
#' @param x A list or single srcref to coerce to a `list_of_srcref`
#' @return A `list_of_srcref` class object
#'
#' @rdname as_list_of_srcref
as_list_of_srcref <- function(x) {
Expand Down Expand Up @@ -41,15 +42,20 @@ as_list_of_srcref.list <- function(x) {
#' paths when formatting `srcref`s.
#' @param full.num A \code{logical} value indicating whether to use all numeric
#' `srcref` components when formatting `srcref`s.
#' @return A `character` vector of formatted strings
#'
#' @export
format.list_of_srcref <- function(x, ..., full.names = FALSE, full.num = FALSE) {
out <- rep_len(NA_character_, length(x))
if (!length(x)) return(out)
if (!length(x)) {
return(out)
}
xnull <- vapply(x, is.null, logical(1L))
srcnull <- vapply(x, function(i) is.null(getSrcref(i)), logical(1L))
isnull <- xnull | srcnull
if (all(isnull)) return(out)
if (all(isnull)) {
return(out)
}
fps <- if (full.names) getSrcFilepath(x[!isnull]) else vapply(x[!isnull], getSrcFilename, character(1L))
srcref_num_rep_len <- length(as.numeric(x[!isnull][[1]]))
nums <- t(vapply(x[!isnull], as.numeric, numeric(srcref_num_rep_len)))
Expand All @@ -71,7 +77,8 @@ print.list_of_srcref <- function(x, ...) {
sprintf("$%s", ifelse(
grepl("^[a-zA-Z0-9_.]*$", names(x)),
names(x),
sprintf("`%s`", names(x))))
sprintf("`%s`", names(x))
))
)
xfmt <- sprintf(
"%s\n%s\n\n",
Expand Down
9 changes: 7 additions & 2 deletions R/obj_namespace_name.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
env_ns_name <- function(e) {
if (is.null(e) || !isNamespace(e)) return(NA_character_)
if (is.null(e) || !isNamespace(e)) {
return(NA_character_)
}
unname(getNamespaceName(e))
}

Expand All @@ -24,6 +26,7 @@ env_name <- function(e) {
#'
#' @param x A value to find within namespace `ns`
#' @param ns A package namespace
#' @return A `character` string representing a namespace or similar
#'
obj_namespace_name <- function(x, ns) {
UseMethod("obj_namespace_name")
Expand All @@ -37,7 +40,9 @@ obj_namespace_name.default <- function(x, ns) {
#' @exportS3Method
obj_namespace_name.character <- function(x, ns) {
is_exported <- x %in% getNamespaceExports(ns)
if (!is_exported) return(NA_character_)
if (!is_exported) {
return(NA_character_)
}
env_ns_name(environment(getExportedValue(ns, x)))
}

Expand Down
4 changes: 3 additions & 1 deletion R/pseudo_srcref.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#' @param call Any code object, most often a `call` object
#' @param file A filepath to bind as a `srcfile` object
#' @param lloc A `srcef`-like `lloc` numeric vector
#' @return A `with_pseudo_srcref` object, mimicking the structure of `srcref`
#'
with_pseudo_srcref <- function(call, file, lloc) {
if (!is.null(srcfile) && !is.null(lloc))
if (!is.null(srcfile) && !is.null(lloc)) {
attr(call, "srcref") <- structure(lloc, srcfile = srcfile(file), class = "pseudo_srcref")
}
structure(call, class = c("with_pseudo_srcref", class(call)))
}

Expand Down
42 changes: 27 additions & 15 deletions R/srcref_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,40 @@
#'
#' @examples
#' pkg <- system.file("examplepkg", package = "covtracer")
#' remotes::install_local(
#' install.packages(
#' pkg,
#' force = TRUE,
#' type = "source",
#' repos = NULL,
#' quiet = TRUE,
#' INSTALL_opts = "--with-keep.source"
#' )
#' as.data.frame(pkg_srcrefs("examplepkg"))
#' @export
as.data.frame.list_of_srcref <- function(x, ..., use.names = TRUE,
as.data.frame.list_of_srcref <- function(
x, ..., use.names = TRUE,
expand.srcref = FALSE, row.names = NULL) {

if (expand.srcref) {
df <- data.frame(
srcfile = getSrcFilepath(x),
matrix(
t(vapply(lapply(x, as.numeric), `[`, numeric(8L), 1:8)),
ncol = 8L,
dimnames = list(c(), c("line1", "byte1", "line2",
"byte2", "col1", "col2", "parsed1", "parsed2"))),
dimnames = list(c(), c(
"line1", "byte1", "line2",
"byte2", "col1", "col2", "parsed1", "parsed2"
))
),
stringsAsFactors = FALSE,
row.names = row.names,
...)
...
)
} else {
df <- data.frame(
srcref = I(x),
stringsAsFactors = FALSE,
row.names = row.names,
...)
...
)
class(df$srcref) <- setdiff(class(df$srcref), "AsIs")
}

Expand All @@ -74,9 +80,10 @@ as.data.frame.list_of_srcref <- function(x, ..., use.names = TRUE,
#'
#' @examples
#' pkg <- system.file("examplepkg", package = "covtracer")
#' remotes::install_local(
#' install.packages(
#' pkg,
#' force = TRUE,
#' type = "source",
#' repos = NULL,
#' quiet = TRUE,
#' INSTALL_opts = "--with-keep.source"
#' )
Expand Down Expand Up @@ -246,8 +253,9 @@ test_trace_mapping <- function(x) {
logical(1L)
)

if (!any(has_tests))
if (!any(has_tests)) {
return(new_empty_test_trace_tally())
}

mat <- do.call(
rbind,
Expand All @@ -259,7 +267,7 @@ test_trace_mapping <- function(x) {
)
)

mat <- mat[order(mat[, "test"], mat[, "i"]),, drop = FALSE]
mat <- mat[order(mat[, "test"], mat[, "i"]), , drop = FALSE]
mat
}

Expand All @@ -273,6 +281,8 @@ test_trace_mapping <- function(x) {
#'
#' @param l A `list_of_srcref` object
#' @param r A `list_of_srcref` object
#' @return A `integer` vector of the first index in `r` that fully encapsulate
#' the respective element in `l`
#'
match_containing_srcrefs <- function(l, r) {
# NOTE:
Expand Down Expand Up @@ -311,11 +321,11 @@ match_containing_srcrefs <- function(l, r) {

l_start_gte_r_start <- (ldf[[li, "line1"]] > rdf[[ri, "line1"]]) ||
(ldf[[li, "line1"]] == rdf[[ri, "line1"]] &&
ldf[[li, "col1"]] >= rdf[[ri, "col1"]])
ldf[[li, "col1"]] >= rdf[[ri, "col1"]])

l_end_lte_r_end <- (ldf[[li, "line2"]] < rdf[[ri, "line2"]]) ||
(ldf[[li, "line2"]] == rdf[[ri, "line2"]] &&
ldf[[li, "col2"]] <= rdf[[ri, "col2"]])
ldf[[li, "col2"]] <= rdf[[ri, "col2"]])

if (!is.na(l_start_gte_r_start) && l_start_gte_r_start) {
if (!is.na(l_end_lte_r_end) && l_end_lte_r_end) {
Expand Down Expand Up @@ -358,12 +368,14 @@ match_containing_srcrefs <- function(l, r) {
#' The name should be the name of the column from the left `data.frame`
#' containing a `list_of_srcref` column, and the value should be the name of a
#' column from the right `data.frame` containing a `list_of_srcref` column.
#' @return A `data.frame` of `x` joined on `y` by spanning `srcref`
#'
#' @export
join_on_containing_srcrefs <- function(x, y, by = c("srcref" = "srcref")) {
by <- by[1L]
if (!names(by) %in% names(x) || !by %in% names(y))
if (!names(by) %in% names(x) || !by %in% names(y)) {
stop("joining columns defined in `by` not found in provided data.frames")
}

idx <- match_containing_srcrefs(x[[names(by)[[1L]]]], y[[by[[1L]]]])
if (any(names(y) %in% names(x))) {
Expand Down
Loading

0 comments on commit b8cc02b

Please sign in to comment.