From ee93506dbb81b5105f6f12385549cffac025a6a3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 10 Mar 2020 10:32:30 -0500 Subject: [PATCH] Don't run evalNamespace in roclet_preprocess Fixes #1022 --- NEWS.md | 2 ++ R/namespace.R | 7 +++++-- man/figures/test-figure-1.png | Bin 13613 -> 13681 bytes tests/testthat/test-namespace.R | 7 +++++++ tests/testthat/testNamespace/DESCRIPTION | 9 +++++++++ tests/testthat/testNamespace/NAMESPACE | 4 ++++ tests/testthat/testNamespace/R/a.r | 6 ++++++ vignettes/namespace.Rmd | 2 +- 8 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/testNamespace/DESCRIPTION create mode 100644 tests/testthat/testNamespace/NAMESPACE create mode 100644 tests/testthat/testNamespace/R/a.r 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 a39deb0e84b926261e3ccbbbd0b8af88af4859f2..037937329c314155a7f5e880baa8b0870e032415 100644 GIT binary patch delta 79 zcmZ3R^)YLM2a6MfMQVg+ny)W|76StV2Loe!CIbtQ#R$YwK+M3vw15dF!uVqWGlC70 OWbw; +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