[R-pkg-devel] Problem passing noSuggests test

Lluís Revilla ||u|@@rev|||@ @end|ng |rom gm@||@com
Fri Aug 1 16:18:51 CEST 2025


To check the existence of a suggested package it is recommended to use
requireNamespace("suggested", quiet = TRUE). See the solution for
examples on the CRAN cookbook [1].

On tests, it depends on the approach you use.
It seems that you don't use any testing package for it (tinytest,
testthat, ...).
I think you could rely on the actual objects and not compare with a
saved output of tests.
Instead of:

> obj
[1] "test1"

Use something like in a plain R file:
stopifnot(identical(obj, "test1"))

This is how it is done on base R itself that checks if MASS is
installed and performs some checks conditionally.
See example on a mirror: [2].
Hope this helps,

Lluís

[1]: https://contributor.r-project.org/cran-cookbook/general_issues.html
[2]: https://github.com/r-devel/r-svn/blob/fb206acc9f17c30d91c528efca9a368c69d5015b/src/library/stats/tests/ig_glm.R


On Fri, 1 Aug 2025 at 15:23, Jon Olav Skoien <jon.skoien using gmail.com> wrote:
>
> One of my packages failed the noSuggests test, and needs to be
> updated. Fair enough, a suggested package was used unconditionally
> both in an example and in a test. From what I understood, a solution
> is to wrap this part of the code inside
> if (require("suggestedPackage")) {useSuggestedPackage}
> However, it still fails the noSuggests test, this time because the
> output does not match the test.Rout.save-file. This is also clear, as
> some of the code is not executed, and some output is missing.
>
> How do I get around this?
> I could use ## IGNORE_RDIFF_BEGIN and ## IGNORE_RDIFF_END before and
> after the if (require())  clause, but then this part would not be
> tested when the suggested package is available either. I don't like
> this solution, as it means the interaction between the two packages
> will not be checked.
>
> Am I missing something? Is there a different way of conditionally
> using the suggested package? Or do I have to use the IGNORE_RDIFF
> method?
>
> Thanks,
> Jon
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list