From 83bf24fee9e9bb4062855af9abfbb83ccc9f95bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Oct 2015 22:53:54 +0200 Subject: [PATCH 1/3] allow roxygen comments in object to be documented useful e.g. to document implementation details inline --- R/parse.R | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/R/parse.R b/R/parse.R index 7fb9fd5af..4b265b6ee 100644 --- a/R/parse.R +++ b/R/parse.R @@ -46,8 +46,8 @@ comments <- function(refs) { # first_line, first_byte, last_line, last_byte com <- vector("list", length(refs)) for(i in seq_along(refs)) { - # Comments begin after last line of last block, and continue to - # first line of this block + # Comments begin after last line of last block, and this block is included + # so that it can be parsed for additional comments if (i == 1) { first_byte <- 1 first_line <- 1 @@ -56,17 +56,8 @@ comments <- function(refs) { first_line <- refs[[i - 1]][3] } - last_line <- refs[[i]][1] - last_byte <- refs[[i]][2] - 1 - if (last_byte == 0) { - if (last_line == 1) { - last_byte <- 1 - last_line <- 1 - } else { - last_line <- last_line - 1 - last_byte <- 1e3 - } - } + last_line <- refs[[i]][3] + last_byte <- refs[[i]][4] lloc <- c(first_line, first_byte, last_line, last_byte) com[[i]] <- srcref(srcfile, lloc) From 6f043e61b6ac8c72bb58db7b897679f5d4823ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 20 Oct 2015 23:26:30 +0200 Subject: [PATCH 2/3] add test --- tests/testthat/test-inline.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/testthat/test-inline.R diff --git a/tests/testthat/test-inline.R b/tests/testthat/test-inline.R new file mode 100644 index 000000000..d25160ee5 --- /dev/null +++ b/tests/testthat/test-inline.R @@ -0,0 +1,34 @@ +context("Inline") +roc <- rd_roclet() + +test_that("Inline comments are supported", { + out <- roc_proc_text(roc, " + #' Description + a <- function(x) { + #' @param x an integer + stopifnot(is.integer(x)) + }")[[1]] + expect_equal(get_tag(out, "param")$values, c(x="an integer")) +}) + +test_that("Inline comments just before the closing brace are allowed", { + out <- roc_proc_text(roc, " + #' Description + a <- function(x) { + #' @param x an integer + stopifnot(is.integer(x)) + + #' @seealso somewhere + }")[[1]] + expect_equal(get_tag(out, "seealso")$value, "somewhere") +}) + +test_that("Inline comments do not extend past the closing brace", { + out <- roc_proc_text(roc, " + #' Description + a <- function(x) { + #' @param x an integer + stopifnot(is.integer(x)) + }; #' @seealso somewhere")[[1]] + expect_null(get_tag(out, "seealso")) +}) From 80b7062f6eb7cae169eb8bf1581f64babad49ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 20 Oct 2015 23:31:22 +0200 Subject: [PATCH 3/3] add NEWS --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index ce88ac27b..2d3874409 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,11 @@ output. `@rawNamespace` allows you to insert literal text in your namespace: this can be useful for conditional imports (#385). +* The contents of documented functions are now also parsed for tags. This allows, + e.g., documenting a parameter's type close to where this type is checked, + or documenting implementation details close to the source, and simplifies + future extensions such as the documentation of R6 classes (#397, @krlmlr). + * `register.preref.parser()` and `register.preref.parsers()` have been deprecated - please use `register_tags()` instead.