On 02/25/2013 01:28 PM, Hadley Wickham wrote:
To summarize, it appears that the only way to call functions from a
suggested package is by using either 'require' (which will dynamically
attach it) or the double colon method. Is this something that should be
mentioned in R-exts?

Except the double colon method doesn't work (i.e. does not pass R CMD
check) unless you also import the package, which means it's no longer
just a suggestion - it must always be installed.

A simple test case (attached DESCRIPTION and R/test.r) yields this
warning on R CMD check:

* checking for unstated dependencies in R code ... WARNING
'::' or ':::' import not declared from: 'MASS'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.

haven't been following fully, but loadNamespace rather than require, with Suggests: MASS in DESCRIPTION ?

f = function() {
    ok <- tryCatch({
        loadNamespace("MASS")
        TRUE
    }, error=function(...) FALSE)

    if (ok) {
        MASS::huber(1:10)
        cat("OK\n")
    }
}

loadNamespaces loads but does not attach the package. Suggests: is enough to quieten the warning with

~/tmp$ R --version
R Under development (unstable) (2013-02-21 r62017) -- "Unsuffered Consequences"

This is consistent with RShowDoc("R-exts") section 1.1.1

Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here, or in ‘Suggests’ or ‘Enhances’ (see below).

Martin


Hadley



______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to