Antoine Fabri
2023-Feb-06 14:42 UTC
[Rd] Unnecessary note when import only used in arg definition
Dear r-devel, When a package is only used in an argument definition, e.g : f <- function(test = testthat::is_testing()) { if (test) 1 else 2 } R CMD CHECK gives us a note: "Namespace in Imports field not imported from: 'testthat'" This incites me to remove the package from the Imports field but that'll make my package brittle. I noted I'm not the first one having the issue ( https://github.com/r-lib/devtools/issues/2456 ) and I've seen some workarounds too, in particular Hadley Wickham suggests in 'R packages' to use the following construct : ignore_unused_imports <- *function*() { aaapkg::aaa_fun } That's far from obvious though, and not very satisfying. Are there any downside to removing this note in this scenario? it makes little sense to me and incites wrong behaviour AFAIU. Thanks, Antoine [[alternative HTML version deleted]]
Kevin Ushey
2023-Feb-06 18:03 UTC
[Rd] Unnecessary note when import only used in arg definition
Hi Antoine, Maybe I'm misunderstanding, but I think the warning is saying that you've declared the package dependency in the DESCRIPTION file, but you haven't actually imported the package (or any functions) in your package NAMESPACE file? I put together an example package that I think satisfies the point you're describing, and I don't see any R CMD check warnings (using R 4.2.2). https://github.com/kevinushey/imports.example As I understand it, if you declare a package dependency in the DESCRIPTION file, you need to clarify how you're using the package in the NAMESPACE file -- e.g. what symbols you want to import, and so on. Best, Kevin On Mon, Feb 6, 2023 at 6:43 AM Antoine Fabri <antoine.fabri at gmail.com> wrote:> > Dear r-devel, > > When a package is only used in an argument definition, e.g : > > > f <- function(test = testthat::is_testing()) { > > if (test) 1 else 2 > > } > > > R CMD CHECK gives us a note: "Namespace in Imports field not imported from: > 'testthat'" > > > This incites me to remove the package from the Imports field but that'll > make my package brittle. > > > I noted I'm not the first one having the issue ( > https://github.com/r-lib/devtools/issues/2456 ) and I've seen some > workarounds too, in particular Hadley Wickham suggests in 'R packages' to > use the following construct : > > > ignore_unused_imports <- *function*() { > > aaapkg::aaa_fun > > } > > > That's far from obvious though, and not very satisfying. > > Are there any downside to removing this note in this scenario? it makes > little sense to me and incites wrong behaviour AFAIU. > > > Thanks, > > > Antoine > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Duncan Murdoch
2023-Feb-07 15:22 UTC
[Rd] Unnecessary note when import only used in arg definition
I've submitted a bug report (https://bugs.r-project.org/show_bug.cgi?id=18465) about this, along with a patch to fix it. Duncan Murdoch On 06/02/2023 9:42 a.m., Antoine Fabri wrote:> Dear r-devel, > > When a package is only used in an argument definition, e.g : > > > f <- function(test = testthat::is_testing()) { > > if (test) 1 else 2 > > } > > > R CMD CHECK gives us a note: "Namespace in Imports field not imported from: > 'testthat'" > > > This incites me to remove the package from the Imports field but that'll > make my package brittle. > > > I noted I'm not the first one having the issue ( > https://github.com/r-lib/devtools/issues/2456 ) and I've seen some > workarounds too, in particular Hadley Wickham suggests in 'R packages' to > use the following construct : > > > ignore_unused_imports <- *function*() { > > aaapkg::aaa_fun > > } > > > That's far from obvious though, and not very satisfying. > > Are there any downside to removing this note in this scenario? it makes > little sense to me and incites wrong behaviour AFAIU. > > > Thanks, > > > Antoine > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel