Skip to content

multi-line @rawNamespace + @import directives lead to mangled NAMESPACE on re-run #1572

Description

@MichaelChirico

As noted here:

r-lib/lintr#2510

I've constructed a more minimal example with package:

DESCRIPTION file:
Package: myPkg
Version: 0.0.1
Encoding: UTF-8

R/foo.R:
#' @import stats
#' @rawNamespace
#' if (TRUE) {
#'   import(methods)
#' } else {
#'   import(utils)
#' }
#' @import graphics
NULL

roxygenize() works fine, with contents:

# Generated by roxygen2: do not edit by hand


if (TRUE) {
  import(methods)
} else {
  import(utils)
}
import(graphics)
import(stats)

Attempt to roxygenize() with existing NAMESPACE fails:

roxygen2::roxygenize()
# Setting `RoxygenNote` to "7.3.0.9000"
# Error in parse(path, keep.source = TRUE) : 
#   /tmp/myPkg/NAMESPACE:15:1: unexpected '}'
# 14: }
# 15: }
#     ^

Contents of NAMESPACE now:

# Generated by roxygen2: do not edit by hand


if (TRUE) {
  import(methods)
} else {
  import(utils)
}
  import(methods)
  import(utils)
if (TRUE) {
import(graphics)
import(stats)
}
} else {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions