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 {
As noted here:
r-lib/lintr#2510
I've constructed a more minimal example with package:
roxygenize()works fine, with contents:Attempt to
roxygenize()with existing NAMESPACE fails:Contents of
NAMESPACEnow: