Skye Bender-deMoll
2015-Feb-24 18:29 UTC
[Rd] alternatives to do.call() when namespace is attached but not loaded?
Dear R-devel I have a function in a package that essentially provides a wrapper for a group of functions in another Suggested package (it sets appropriate defaults for the context, transforms output, etc). I've implemented this by verifying that the package was loaded with require(sna) and then do.call(snaFunName, args = args) The rDevel check is requesting that I use requireNamespace(sna) instead of directly loading the SNA package. This seems reasonable, except that I have yet to figure out a way to use do.call to call the function when the namespace is attached but package is not loaded. do.call("sna::funName",..) doesn't seem to work. 1) Can do.call() call functions that are only namespace attached? Is there better way to accomplish this without do.call()? For example, should I use getAnywhere('funName') ('tho this doesn't seem to permit restricting search to a specific namespace..) 2) Is this an appropriate of require() instead of requireNamespace() to ensure that the Suggested package is loaded and attached? Can I ignore the check warning? best, -skye
Winston Chang
2015-Feb-24 18:52 UTC
[Rd] alternatives to do.call() when namespace is attached but not loaded?
First, a clarification of terminology: a package can be loaded and attached, or loaded and not attached. It can't be attached and not loaded. To get the function from a package by name, you could do something like: getExportedValue("sna", snaFunName) where snaFunName is a string containing the name of the function. -Winston On Tue, Feb 24, 2015 at 12:29 PM, Skye Bender-deMoll <skyebend at skyeome.net> wrote:> Dear R-devel > > I have a function in a package that essentially provides a wrapper for a > group of functions in another Suggested package (it sets appropriate > defaults for the context, transforms output, etc). I've implemented this > by verifying that the package was loaded with > > require(sna) > > and then > > do.call(snaFunName, args = args) > > > The rDevel check is requesting that I use requireNamespace(sna) instead > of directly loading the SNA package. This seems reasonable, except that I > have yet to figure out a way to use do.call to call the function when the > namespace is attached but package is not loaded. do.call("sna::funName",..) > doesn't seem to work. > > 1) Can do.call() call functions that are only namespace attached? Is there > better way to accomplish this without do.call()? For example, should I use > getAnywhere('funName') ('tho this doesn't seem to permit restricting search > to a specific namespace..) > > 2) Is this an appropriate of require() instead of requireNamespace() to > ensure that the Suggested package is loaded and attached? Can I ignore the > check warning? > > best, > -skye > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
Hadley Wickham
2015-Feb-24 18:53 UTC
[Rd] alternatives to do.call() when namespace is attached but not loaded?
do.call(sna::snaFunName, args = args) ? Hadley On Tue, Feb 24, 2015 at 1:29 PM, Skye Bender-deMoll <skyebend at skyeome.net> wrote:> Dear R-devel > > I have a function in a package that essentially provides a wrapper for a > group of functions in another Suggested package (it sets appropriate > defaults for the context, transforms output, etc). I've implemented this by > verifying that the package was loaded with > > require(sna) > > and then > > do.call(snaFunName, args = args) > > > The rDevel check is requesting that I use requireNamespace(sna) instead of > directly loading the SNA package. This seems reasonable, except that I have > yet to figure out a way to use do.call to call the function when the > namespace is attached but package is not loaded. do.call("sna::funName",..) > doesn't seem to work. > > 1) Can do.call() call functions that are only namespace attached? Is there > better way to accomplish this without do.call()? For example, should I use > getAnywhere('funName') ('tho this doesn't seem to permit restricting search > to a specific namespace..) > > 2) Is this an appropriate of require() instead of requireNamespace() to > ensure that the Suggested package is loaded and attached? Can I ignore the > check warning? > > best, > -skye > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- http://had.co.nz/
peter dalgaard
2015-Feb-24 21:38 UTC
[Rd] alternatives to do.call() when namespace is attached but not loaded?
> On 24 Feb 2015, at 19:53 , Hadley Wickham <h.wickham at gmail.com> wrote: > > do.call(sna::snaFunName, args = args) > > ? >I was about to suggest something similar. The key is that the first arg to do.call is not necessarily a text string; it can be the actual function object. So something along the lines of name <- as.name("snaFunName") f <- eval(bquote(sna::.(name))) do.call(f, args) should work too.> Hadley > > On Tue, Feb 24, 2015 at 1:29 PM, Skye Bender-deMoll > <skyebend at skyeome.net> wrote: >> Dear R-devel >> >> I have a function in a package that essentially provides a wrapper for a >> group of functions in another Suggested package (it sets appropriate >> defaults for the context, transforms output, etc). I've implemented this by >> verifying that the package was loaded with >> >> require(sna) >> >> and then >> >> do.call(snaFunName, args = args) >> >> >> The rDevel check is requesting that I use requireNamespace(sna) instead of >> directly loading the SNA package. This seems reasonable, except that I have >> yet to figure out a way to use do.call to call the function when the >> namespace is attached but package is not loaded. do.call("sna::funName",..) >> doesn't seem to work. >> >> 1) Can do.call() call functions that are only namespace attached? Is there >> better way to accomplish this without do.call()? For example, should I use >> getAnywhere('funName') ('tho this doesn't seem to permit restricting search >> to a specific namespace..) >> >> 2) Is this an appropriate of require() instead of requireNamespace() to >> ensure that the Suggested package is loaded and attached? Can I ignore the >> check warning? >> >> best, >> -skye >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > > > > -- > http://had.co.nz/ > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Apparently Analagous Threads
- alternatives to do.call() when namespace is attached but not loaded?
- issues with dev.new avoiding RStudio plot device on unix?
- issues with dev.new avoiding RStudio plot device on unix?
- what is the correct way to force a copy of an object?
- quieting the "apparent S3 methods" warning