You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When exporting a new S3 method for a generic imported from another package, ‘roxygen2’ 7.3.1 generates an incorrect NAMESPACE directive; namely, it generates export() rather than S3method(). However, this only happens when both of the following conditions are fulfilled:
if the imported package is not attached, and
when there is no NAMESPACE file, i.e. only the first time round: when rerunning roxygen2::roxygenize(), it “corrects” the NAMESPACE file (intermittently I’ve also managed to produce this with an existing NAMESPACE file, but the exact circumstances are unclear to me, and I no longer manage the right circumstances to reproduce this).
Here’s a minimal example: a package without NAMESPACE file with a single implementation file R/foo.r (complete MWE at the end in the details):
ℹ Loading pkg
Writing 'NAMESPACE'
# Generated by roxygen2: do not edit by hand
export(foo)
export(head.foo)
importFrom(utils,head)
ℹ Loading pkg
Writing 'NAMESPACE'
# Generated by roxygen2: do not edit by hand
S3method(head,foo)
export(foo)
importFrom(utils,head)
Complete MWE
dir.create('pkg/R', recursive=TRUE)
desc=matrix(
c(
'pkg', 'Package', 'What the Package Does (Title Case)', '0.1.0',
'person(\'First\', \'Last\', email = \'last@example.com\', role = c(\'aut\', \'cre\'))',
'More about what it does.', 'GPL', 'utils', 'UTF-8'
),
ncol=9L,
dimnames=list(
NULL, c('Package', 'Type', 'Title', 'Version', 'Authors@R', 'Description', 'License', 'Imports', 'Encoding')
)
)
write.dcf(desc, 'pkg/DESCRIPTION')
code=r"[#' @importFrom utils head#' @exporthead.foo = function (x, ...) { x$head}#' @exportfoo = function () { structure(list(head = 'caput'), class = 'foo')}]"
writeLines(code, 'pkg/R/foo.r')
###
setwd('pkg')
detach('package:utils')
roxygen2::roxygenize()
writeLines(readLines('NAMESPACE'))
roxygen2::roxygenize()
writeLines(readLines('NAMESPACE'))
The text was updated successfully, but these errors were encountered:
klmr
changed the title
@export generates a wrong NAMESPACE directive for S3 methods for generics imported from a different package
@export generates a wrong NAMESPACE directive for S3 methods of generics imported from a different package
Apr 22, 2024
When exporting a new S3 method for a generic imported from another package, ‘roxygen2’ 7.3.1 generates an incorrect
NAMESPACE
directive; namely, it generatesexport()
rather thanS3method()
. However, this only happens when both of the following conditions are fulfilled:NAMESPACE
file, i.e. only the first time round: when rerunningroxygen2::roxygenize()
, it “corrects” theNAMESPACE
file (intermittently I’ve also managed to produce this with an existingNAMESPACE
file, but the exact circumstances are unclear to me, and I no longer manage the right circumstances to reproduce this).Here’s a minimal example: a package without
NAMESPACE
file with a single implementation fileR/foo.r
(complete MWE at the end in the details):Now run the following code to generate the
NAMESPACE
file:Complete MWE
The text was updated successfully, but these errors were encountered: