Skip to content

Commit

Permalink
Don't run evalNamespace in roclet_preprocess
Browse files Browse the repository at this point in the history
Fixes #1022
  • Loading branch information
hadley committed Mar 10, 2020
1 parent 235de49 commit ee93506
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
7 changes: 5 additions & 2 deletions R/namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
}

Expand Down
Binary file modified man/figures/test-figure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/testthat/test-namespace.R
Original file line number Diff line number Diff line change
@@ -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", {
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/testNamespace/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: testNamespace
Title: Check that utf8 escapes are round tripped ok
License: GPL-2
Description:
Author: Hadley <hadley@rstudio.com>
Maintainer: Hadley <hadley@rstudio.com>
Encoding: UTF-8
Version: 0.1
RoxygenNote: 7.0.2.9000
4 changes: 4 additions & 0 deletions tests/testthat/testNamespace/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(f)
export(g)
6 changes: 6 additions & 0 deletions tests/testthat/testNamespace/R/a.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#' @export
f <- function(x) x


#' @evalNamespace "export(g)"
g <- function() 1
2 changes: 1 addition & 1 deletion vignettes/namespace.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ee93506

Please sign in to comment.