简体   繁体   中英

Do I have to export functions conditionally imported via :: in R?

I am extracting information from objects whose classes are defined in various R packages. For example, I extract coefficients from various statistical models (for which coef methods are not always implemented). I usually don't have to import those packages because I defined a generic function for which methods can be added by users. There is one method for each kind of statistical model, and it would be stupid to import all those model definitions if the user is only interested in one specific model type.

In some cases, however, I need to use a function which is defined in a package. For instance, the confint.merMod method in the lme4 package. Up to now, I used package::function to call these functions and wrapped this command in an exists(function) if-condition to make sure that the package really offers this function (because the function may be available only in some versions of the package).

However, I just discovered on http://developer.r-project.org/blosxom.cgi/R-devel/NEWS (see Sep 5, 2013) that in R version 3.0.2, "'R CMD check' does more thorough checking of declared packages and namespaces. It reports [...] objects imported by '::' which are not exported."

Does this mean that I really have to add export("function") to the NAMESPACE file? Wouldn't the CMD check complain because the function is only imported conditionally?

To clarify/summarize for future visitors...

The R-devel News quoted in the question related to the now 3-0-branch NEWS file where the specific entry lists the particular cases which R CMD check will generate a report for issues found with imports, usage and declarations of packages and functions.

If you have questions regarding a particular warning the list is worth a look.

For further (and more in-depth) information see the wiki page for links to the Writing R Extensions R development guide and other helpful information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM