Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @field for documenting RC fields.
- Loading branch information
Showing
9 changed files
with
118 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
process_inherit_params <- function(topics) { | ||
|
||
# Currently no topological sort, so @inheritParams will only traverse | ||
# one-level - you can't inherit params that have been inherited from | ||
# another function (and you can't currently use multiple inherit tags) | ||
inherit_index <- get_values(topics, "inheritParams") | ||
name_index <- get_values(topics, "name") | ||
|
||
for(topic_name in names(inherit_index)) { | ||
topic <- topics[[topic_name]] | ||
|
||
documented <- names(get_tag(topic, "arguments")$values) | ||
documented <- names(get_tag(topic, "param")$values) | ||
if (length(documented) > 0) | ||
documented <- unlist(strsplit(documented, ",")) | ||
|
||
needed <- get_tag(topic, "formals")$values | ||
missing <- setdiff(needed, documented) | ||
if (length(missing) == 0) next | ||
|
||
for(inheritor in inherit_index[[topic_name]]) { | ||
inherited <- find_params(inheritor, topics, name_index) | ||
|
||
to_add <- intersect(missing, names(inherited)) | ||
if (length(to_add) == 0) next | ||
missing <- setdiff(missing, names(inherited)) | ||
add_tag(topic, new_tag("arguments", inherited[to_add])) | ||
|
||
add_tag(topic, new_tag("param", inherited[to_add])) | ||
} | ||
} | ||
topics | ||
|
||
topics | ||
} | ||
|
||
find_params <- function(inheritor, topics, name_lookup) { | ||
has_colons <- grepl("::", inheritor, fixed = TRUE) | ||
|
||
if (has_colons) { | ||
# Reference to another package | ||
pieces <- strsplit(inheritor, "::", fixed = TRUE)[[1]] | ||
params <- rd_arguments(get_rd(pieces[2], pieces[1])) | ||
|
||
} else { | ||
# Reference within this package | ||
rd_name <- names(Filter(function(x) inheritor %in% x, name_lookup)) | ||
|
||
if (length(rd_name) != 1) { | ||
warning("@inheritParams: can't find topic ", inheritor, | ||
call. = FALSE, immediate. = TRUE) | ||
return() | ||
} | ||
params <- get_tag(topics[[rd_name]], "arguments")$values | ||
params <- get_tag(topics[[rd_name]], "param")$values | ||
} | ||
params <- unlist(params) | ||
|
||
param_names <- str_trim(names(params)) | ||
param_names[param_names == "\\dots"] <- "..." | ||
|
||
# Split up compound names on , duplicating their contents | ||
individual_names <- strsplit(param_names, ",") | ||
reps <- vapply(individual_names, length, integer(1)) | ||
|
||
setNames(rep.int(params, reps), unlist(individual_names)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
context("Field") | ||
|
||
test_that("@fields creates a new section and lists fields", { | ||
out <- roc_proc_text(rd_roclet(), " | ||
#' Important class. | ||
#' | ||
#' @field a field a | ||
#' @field b field b | ||
setRefClass('test') | ||
")[[1]] | ||
expect_equal(get_tag(out, "field")$values, c(a = "field a", b = "field b")) | ||
}) |
Oops, something went wrong.