Hi all, I've been trying to include a nice example in the Rd file for a function and cannot work out how to get it through R check. If I use: if(require(maps,quietly=TRUE)) { ... Warning message: 'Sys.putenv' is deprecated. Use 'Sys.setenv' instead. See help("Deprecated") The warning message causes R check to get the tremors and assume there is something wrong with the example. This also means that I can't put a little message telling the user that they needed "maps" to run the example, as the warning message leads to the "else" being detached from the "if" (and another tremor and error message). I can't really use the following, even though it doesn't cause the warning (but would be messy if the user didn't have the package). if(library(maps)) { ... If I try: if(library(maps,logical.return=TRUE)) { ... I get the same warning as with "require". Does this qualify as a bug in require/library or should I just not bother to test the result of "library" and let the user suffer? Jim
On 6/4/2008 8:09 AM, Jim Lemon wrote:> Hi all, > I've been trying to include a nice example in the Rd file for a function > and cannot work out how to get it through R check. If I use: > > if(require(maps,quietly=TRUE)) { > ... > > Warning message: > 'Sys.putenv' is deprecated. > Use 'Sys.setenv' instead. > See help("Deprecated")require() doesn't use Sys.putenv, so I'd guess some package that you're loading does. However, the current version of maps doesn't, so I think you must be loading something that's obsolete. sessionInfo() would have helped a lot. Duncan Murdoch> > The warning message causes R check to get the tremors and assume there > is something wrong with the example. This also means that I can't put a > little message telling the user that they needed "maps" to run the > example, as the warning message leads to the "else" being detached from > the "if" (and another tremor and error message). > > I can't really use the following, even though it doesn't cause the > warning (but would be messy if the user didn't have the package). > > if(library(maps)) { > ... > > If I try: > > if(library(maps,logical.return=TRUE)) { > ... > > I get the same warning as with "require". Does this qualify as a bug in > require/library or should I just not bother to test the result of > "library" and let the user suffer? > > Jim > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Thanks to Dirk and Duncan Dirk's suggestion of the suppressMessages function unfortunately doesn't quite do the job. The warning message isn't printed, but it is picked up by the check function and leads to a whinge. Duncan is right - I had an older version of "maps" and installing the new version fixed the problem that was causing the warning in the first place. (My apologies for not including sessionInfo). So, the outcome is: 1) If you try to use require or library in help page examples, everything has to work. 2) If you use require or library, wrap it in suppressPackageStartupMessages so that the "Loading package" message doesn't mess up your elegant code. 3) Remember that 2) won't stop any errors or warnings from being recorded during package checking, therefore 1). Is my logic sufficiently circular? Jim