Dear R-help, Yes, I do know about the auto-loading feature. My question is more complicated than that: Suppose I loaded a package (e.g., e1071) and created an object of certain class (e.g., svm), for which there is a print method in the package to hide things that the user may not need to see (e.g., large vectors or matrices needed by methods such as predict). If the next time I started R, I type the object name without loading the package first, the whole shebang (sp?) gets dumped on the screen, which is quite annoying. Is there any way to make R automagically search for availability of methods for a particular class when objects of that class is accessed? One possibility is to auto-load the package if the appropriate method is found. Another possibility is to notify the user that a package contains the appropriate method and ask if it should be loaded. Can such a thing be done? Regards, Andy Andy I. Liaw, PhD Biometrics Research Phone: (732) 594-0820 Merck & Co., Inc. Fax: (732) 594-1565 P.O. Box 2000, RY84-16 Rahway, NJ 07065 mailto:andy_liaw at merck.com ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ============================================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There is nothing that associates classes with packages. So one would have to have print() look at all packages (loaded or not) for a print.foo method and load the appropriate one. Now suppose it found three print.foo functions in separate packages? Which one should it use? There is also the potential for an enormous slowdown whilst packages are searched. However, I do have a vision which would allow users to load many packages at negligible cost and so one could have all one's working set of packages in .Rprofile (or some such file). This depends on two things 1) Packages declaring their list of public objects (which will come soon with namespaces), and these would be automatically auto-loaded and 2) Small-scale autoloading, so a package is divided into a set of code sections which are loaded as needed. Then one could have many packages `loaded' via library(), but only code that has actually been used in memory. Don't expect to see an implementation any time soon, though. (One issue is interactions with namespaces.) On Tue, 2 Jul 2002, Liaw, Andy wrote:> Dear R-help, > > Yes, I do know about the auto-loading feature. My question is more > complicated than that: > > Suppose I loaded a package (e.g., e1071) and created an object of certain > class (e.g., svm), for which there is a print method in the package to hide > things that the user may not need to see (e.g., large vectors or matrices > needed by methods such as predict). If the next time I started R, I type > the object name without loading the package first, the whole shebang (sp?) > gets dumped on the screen, which is quite annoying. > > Is there any way to make R automagically search for availability of methods > for a particular class when objects of that class is accessed? One > possibility is to auto-load the package if the appropriate method is found. > Another possibility is to notify the user that a package contains the > appropriate method and ask if it should be loaded. Can such a thing be > done? > > Regards, > Andy > > Andy I. Liaw, PhD > Biometrics Research Phone: (732) 594-0820 > Merck & Co., Inc. Fax: (732) 594-1565 > P.O. Box 2000, RY84-16 Rahway, NJ 07065 > mailto:andy_liaw at merck.com > > > > ------------------------------------------------------------------------------ > Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. > > =============================================================================> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There is a plan afoot to keep better track of the packages that are needed for dealing with particular objects (especially if they are saved and loaded using save and load). I'm hoping to get this in to 1.6.0. For now there is no simple way to do this -- you could write your own simple wrappers around save and load that did this in a brute force way. On Tue, Jul 02, 2002 at 08:29:24AM -0400, Liaw, Andy wrote:> Dear R-help, > > Yes, I do know about the auto-loading feature. My question is more > complicated than that: > > Suppose I loaded a package (e.g., e1071) and created an object of certain > class (e.g., svm), for which there is a print method in the package to hide > things that the user may not need to see (e.g., large vectors or matrices > needed by methods such as predict). If the next time I started R, I type > the object name without loading the package first, the whole shebang (sp?) > gets dumped on the screen, which is quite annoying. > > Is there any way to make R automagically search for availability of methods > for a particular class when objects of that class is accessed? One > possibility is to auto-load the package if the appropriate method is found. > Another possibility is to notify the user that a package contains the > appropriate method and ask if it should be loaded. Can such a thing be > done? > > Regards, > Andy > > Andy I. Liaw, PhD > Biometrics Research Phone: (732) 594-0820 > Merck & Co., Inc. Fax: (732) 594-1565 > P.O. Box 2000, RY84-16 Rahway, NJ 07065 > mailto:andy_liaw at merck.com > > > > ------------------------------------------------------------------------------ > Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. > > =============================================================================> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- +---------------------------------------------------------------------------+ | Robert Gentleman phone : (617) 632-5250 | | Associate Professor fax: (617) 632-2444 | | Department of Biostatistics office: M1B28 | Harvard School of Public Health email: rgentlem at jimmy.dfci.harvard.edu | +---------------------------------------------------------------------------+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 2 Jul 2002, Liaw, Andy wrote:> Dear R-help, > > Yes, I do know about the auto-loading feature. My question is more > complicated than that: >You can use the autoloading feature for this (at least for packages using old classes) if all you need is print methods. It's fairly straightforward to get a list of all the print.foo functions in all the installed packages. For example, load the package, use ls() to get the object names, and grep for names beginning "print.". Use this to create a file of autoload() statements like autoload("print.Surv","survival") autoload("print.coxph","survival") autoload("print.nlme","nlme") and so on, and read this from your .Rprofile. As long as the names are unique this will do what you are asking (and if they're not unique then it's pretty much impossible). It does need to be updated when you install new packages. Doing this in general is much harder, as has been pointed out. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently I only had faint impression of what autoload does. What Thomas described will do what I want, even though it's not as automatic as one would hope. In my case I know most of the methods and the packages they're in, so doing it this way is not a problem at all. Thanks to all who responded!! Cheers, Andy> -----Original Message----- > From: Thomas Lumley [mailto:tlumley at u.washington.edu] > Sent: Tuesday, July 02, 2002 11:05 AM > To: Liaw, Andy > Cc: 'r-help at stat.math.ethz.ch' > Subject: Re: [R] auto-loading package possible? > > > On Tue, 2 Jul 2002, Liaw, Andy wrote: > > > Dear R-help, > > > > Yes, I do know about the auto-loading feature. My question is more > > complicated than that: > > > > You can use the autoloading feature for this (at least for > packages using > old classes) if all you need is print methods. > > It's fairly straightforward to get a list of all the > print.foo functions > in all the installed packages. For example, load the package, > use ls() to > get the object names, and grep for names beginning "print.". > Use this to > create a file of autoload() statements like > autoload("print.Surv","survival") > autoload("print.coxph","survival") > autoload("print.nlme","nlme") > and so on, and read this from your .Rprofile. > > As long as the names are unique this will do what you are > asking (and if > they're not unique then it's pretty much impossible). It does > need to be > updated when you install new packages. > > Doing this in general is much harder, as has been pointed out. > > -thomas > > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ============================================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._