Skip to content

[R-pkg-devel] Confusing error

7 messages · Josiah Parry, Duncan Murdoch, Cohen, Aaron

#
Hello,

I am trying to submit an R package to CRAN. There are no notes, comments or errors when checking on my local machine, but I keep getting an error message when submitting. I am attaching the log file, but basically the error occurs when running the examples. In particular, it says

Error in loadNamespace(x) : there is no package called 'survey'

However, my package does not use the ?survey? package, and when I include this package to the Imports field in the DESCRIPTION file, it gives the following NOTE:

checking dependencies in R code ... NOTE
  Namespace in Imports field not imported from: ?survey?
    All declared Imports should be used.


How do I resolve this issue?

Best,
Aaron

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: _00details.log_.log
URL: <https://stat.ethz.ch/pipermail/r-package-devel/attachments/20241202/6bb856bb/attachment.log>
#
On 2024-12-02 11:38 a.m., Cohen, Aaron wrote:
I'd remove the survey package on your system, and try running the 
example that fails.  If you get the same error, you can track it down.

Duncan Murdoch
#
Hello, thank you for getting back to me. I have a github with the code:

https://github.com/237triangle/surveynnet

The main code is in R/surveynnet.R.

Re: your suggestion, do you mean I should de-install the survey package? I will try that, but would appreciate any additional help in the meantime so I?m linking my github above.

Best,
Aaron

From: Duncan Murdoch <murdoch.duncan at gmail.com>
Date: Monday, December 2, 2024 at 3:09?PM
To: Cohen, Aaron <cohenaa at iu.edu>, r-package-devel at r-project.org <r-package-devel at r-project.org>
Subject: [External] Re: [R-pkg-devel] Confusing error
[You don't often get email from murdoch.duncan at gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

This message was sent from a non-IU address. Please exercise caution when clicking links or opening attachments from external sources.
On 2024-12-02 11:38 a.m., Cohen, Aaron wrote:
I'd remove the survey package on your system, and try running the
example that fails.  If you get the same error, you can track it down.

Duncan Murdoch
#
My guess is that one of your packages uses survey as a Suggested package.
And your calling a function from that package that uses survey via
Suggests.

Is your package on GitHub? Or could you share your Imports?

On Mon, Dec 2, 2024 at 12:09 Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

  
  
#
The PracTools::deffCR function calls survey::svydesign.  It only 
suggests the survey package, so it is not necessarily available.

What you could do is also suggest survey, then add a test for its 
presence before calling PracTools::deffCR.  Or if that call is 
essential, then you should import survey, and add some innocuous direct 
reference to it to quiet the NOTE.

Duncan Murdoch
On 2024-12-02 3:38 p.m., Cohen, Aaron wrote:
#
Thank you [and Josiah Parry] for your help; I had already seen that PracTools uses `survey` but only suggests it, and I was unsure what to do on my end since I was getting in trouble whether I imported it or not. I will try doing what you suggest.

Since the call to PracTools::deffCR is essential to this package, I will do the second suggestion.

Best,
Aaron

From: Duncan Murdoch <murdoch.duncan at gmail.com>
Date: Monday, December 2, 2024 at 3:48?PM
To: Cohen, Aaron <cohenaa at iu.edu>, r-package-devel at r-project.org <r-package-devel at r-project.org>
Subject: Re: [External] Re: [R-pkg-devel] Confusing error
The PracTools::deffCR function calls survey::svydesign.  It only
suggests the survey package, so it is not necessarily available.

What you could do is also suggest survey, then add a test for its
presence before calling PracTools::deffCR.  Or if that call is
essential, then you should import survey, and add some innocuous direct
reference to it to quiet the NOTE.

Duncan Murdoch
On 2024-12-02 3:38 p.m., Cohen, Aaron wrote:

  
  
#
Since you have dplyr as a dependency (though I?d reconsider that one since
it can be quite hefty / change it?s API) I would suggest using
rlang::check_installer(?survey?) in the function that indirectly calls
survey.

This will throw an informative error when survey is not found.

In your examples you can wrap your example like:

if (rlang::is_installed(?survey?)) {
   Example code here
}
On Mon, Dec 2, 2024 at 13:17 Cohen, Aaron <cohenaa at iu.edu> wrote: