I am building a package which contains a function from which I wish to call the fortune() function from the fortunes package --- if that package is available. I have place the line Suggests: fortunes in the DESCRIPTION file. In my code for the function that I am writing (let's call it "foo") I put> fortOK <- requireNamespace(fortunes,quietly=TRUE) > if(fortOK) { > fortunes::fortune() > }thinking that I was following all of the prescriptions in "Writing R Extensions". Yet when I do R CMD check on the package I get> * checking R code for possible problems ... NOTE > foo: no visible binding for global variable ?fortunes? > Undefined global functions or variables: > fortunesWhat am I doing wrong? Thanks for any insight. cheers, Rolf Turner P. S. I tried putting an "imports(fortunes)" in the NAMESPACE file, but this just made matters worse:> * checking package dependencies ... ERROR > Namespace dependency not required: ?fortunes?Huh? What on earth is this actually saying? I cannot parse this error message. R. T. -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Rolf Turner
2018-Nov-17 22:30 UTC
[R] The Suggests field in a DESCRIPTION file --- never mind!!!
I figured it out. The package name in the call to requireNamespace() has to be a *text string*. I should've had: fortOK <- requireNamespace("fortunes",quietly=TRUE) So require() takes a package name, but requireNamespace() takes a *string* specifying the package name. Trap for young players. Psigh. cheers, Rolf Turner On 11/18/18 11:16 AM, Rolf Turner wrote:> > I am building a package which contains a function from which I wish to > call the fortune() function from the fortunes package --- if that > package is available. > > I have place the line > > ?? Suggests: fortunes > > in the DESCRIPTION file. > > In my code for the function that I am writing (let's call it "foo") > I put > >> fortOK <- requireNamespace(fortunes,quietly=TRUE) >> ??????? if(fortOK) { >> ??????????? fortunes::fortune() >> ??????? } > > thinking that I was following all of the prescriptions in "Writing R > Extensions".? Yet when I do R CMD check on the package I get > >> * checking R code for possible problems ... NOTE >> foo: no visible binding for global variable ?fortunes? >> Undefined global functions or variables: >> ? fortunes > > What am I doing wrong? > > Thanks for any insight. > > cheers, > > Rolf Turner > > P. S.? I tried putting an "imports(fortunes)" in the NAMESPACE file, but > this just made matters worse: > >> * checking package dependencies ... ERROR >> Namespace dependency not required: ?fortunes? > > Huh?? What on earth is this actually saying?? I cannot parse this error > message. > > R. T. >-- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276