Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MichaelChirico opened this issue Jan 14, 2024 · 1 comment · Fixed by #1573
Closed
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@MichaelChirico
Copy link
Contributor

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 {
@hadley
Copy link
Member

hadley commented Jan 22, 2024

And now on CRAN 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants