-
Notifications
You must be signed in to change notification settings - Fork 236
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
For ropensci/spelling#3 it would be useful to have the start line per tag in the roxy_block()
objects which are the result of parse_file()
. This can be done with a trivial change
diff --git a/R/block.R b/R/block.R
index 350fd1e..ce2b5cd 100644
--- a/R/block.R
+++ b/R/block.R
@@ -163,6 +163,10 @@ parse_tags <- function(tokens, registry = list(), global_options = list()) {
# it's what roxygen already uses
vals <- lapply(tags, `[[`, "val")
names <- vapply(tags, `[[`, "tag", FUN.VALUE = character(1))
+ for (i in seq_along(tags)) {
+ attr(vals[[i]], "line") <- tags[[i]]$line
+ }
+
setNames(vals, names)
}
However doing so reveals that the line numbers do not seem quite correct. Running parse_file()
on a simple file reveals a couple of issues.
cat(
"#' Foo
#'
#' A simple
#' multiline description.
#'
#' @param x xyz
#' @export
NULL", "test.R")
res <- roxygen2::parse_file("test.R")
str(res)
#> List of 1
#> $ :List of 4
#> ..$ title : atomic [1:1] Foo
#> .. ..- attr(*, "line")= int 1
#> ..$ description: atomic [1:1] A simple
#> multiline description.
#> .. ..- attr(*, "line")= int 1
#> ..$ param :List of 2
#> .. ..$ name : chr "x"
#> .. ..$ description: chr "xyz"
#> .. ..- attr(*, "line")= int 7
#> ..$ export : atomic [1:1]
#> .. ..- attr(*, "line")= int 8
#> ..- attr(*, "filename")= chr "test.R"
#> ..- attr(*, "location")= int [1:8] 8 1 8 4 1 4 8 8
#> ..- attr(*, "class")= chr "roxy_block"
- The start line of the description should be at least 2 (ideally 3), it is 1.
- The start lines of the param and export tags are 1 higher than they should be. They are 7 and 8 when they occur on lines 6 and 7 of the file.
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement