diff --git a/NEWS.md b/NEWS.md index ff54f9020..f5de789fa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # roxygen2 (development version) +* `evalNamespace()` works again (#1022). + * roxygen2 now keeps using Windows (CR LF) line endings for files that already have CR LF line endings, and uses LF for new files (#989). diff --git a/R/namespace.R b/R/namespace.R index 2209144ce..29c690dbb 100644 --- a/R/namespace.R +++ b/R/namespace.R @@ -32,8 +32,7 @@ namespace_roclet <- function() { #' @export roclet_preprocess.roclet_namespace <- function(x, blocks, base_path) { - - lines <- blocks_to_ns(blocks, env, import_only = TRUE) + lines <- blocks_to_ns(blocks, emptyenv(), import_only = TRUE) NAMESPACE <- file.path(base_path, "NAMESPACE") if (length(lines) == 0 && !made_by_roxygen(NAMESPACE)) { @@ -101,6 +100,10 @@ roxy_tag_parse.roxy_tag_evalNamespace <- function(x) { } #' @export roxy_tag_ns.roxy_tag_evalNamespace <- function(x, block, env, import_only = FALSE) { + if (import_only) { + return() + } + roxy_tag_eval(x, env) } diff --git a/man/figures/test-figure-1.png b/man/figures/test-figure-1.png index a39deb0e8..037937329 100644 Binary files a/man/figures/test-figure-1.png and b/man/figures/test-figure-1.png differ diff --git a/tests/testthat/test-namespace.R b/tests/testthat/test-namespace.R index feffc3036..d224a7f0a 100644 --- a/tests/testthat/test-namespace.R +++ b/tests/testthat/test-namespace.R @@ -1,3 +1,10 @@ +test_that("end-to-end NAMESPACE generation works", { + expect_output(roxygenise(test_path("testNamespace"), "namespace", clean = TRUE)) + + ns <- read_lines(test_path("testNamespace/NAMESPACE")) + expect_length(ns, 4) +}) + # @export ----------------------------------------------------------------- test_that("export quote object name appropriate", { diff --git a/tests/testthat/testNamespace/DESCRIPTION b/tests/testthat/testNamespace/DESCRIPTION new file mode 100644 index 000000000..4552c154f --- /dev/null +++ b/tests/testthat/testNamespace/DESCRIPTION @@ -0,0 +1,9 @@ +Package: testNamespace +Title: Check that utf8 escapes are round tripped ok +License: GPL-2 +Description: +Author: Hadley +Maintainer: Hadley +Encoding: UTF-8 +Version: 0.1 +RoxygenNote: 7.0.2.9000 diff --git a/tests/testthat/testNamespace/NAMESPACE b/tests/testthat/testNamespace/NAMESPACE new file mode 100644 index 000000000..c986411e4 --- /dev/null +++ b/tests/testthat/testNamespace/NAMESPACE @@ -0,0 +1,4 @@ +# Generated by roxygen2: do not edit by hand + +export(f) +export(g) diff --git a/tests/testthat/testNamespace/R/a.r b/tests/testthat/testNamespace/R/a.r new file mode 100644 index 000000000..cd57423bf --- /dev/null +++ b/tests/testthat/testNamespace/R/a.r @@ -0,0 +1,6 @@ +#' @export +f <- function(x) x + + +#' @evalNamespace "export(g)" +g <- function() 1 diff --git a/vignettes/namespace.Rmd b/vignettes/namespace.Rmd index ea9efa5d9..16f75215e 100644 --- a/vignettes/namespace.Rmd +++ b/vignettes/namespace.Rmd @@ -79,7 +79,7 @@ Generally, roxygen2 can generate the correct namespace directive when `@export`i * `@exportMethod foo` generates `exportMethods(foo)` * `@exportPattern foo` generates `exportPattern(foo)` -For even more specialised cases you can use `@rawNamespace code` which inserts `code` literally into the `NAMESPACE`. If you need to automate this, `@evalNamespace foo()` will evaluate the `foo()` in the package environment and insert the results into `NAMESPACE`. +For even more specialised cases you can use `@rawNamespace code` which inserts `code` literally into the `NAMESPACE`. If you need to automate this, `@evalNamespace foo()` will evaluate the `foo()` in the package environment and insert the results into `NAMESPACE`. Because `evalNamespace()` is run in the package environment, it can only generate exports, not imports. ## Imports