[Rd] How to add a welcome message in Package development?
Dear all, it is my first post in R-devel list, and hope that this is the right place to ask question related to package development. I have created my first package in Windows through the usual route. Now I want to add some ***Welcome message*** as soon as user loads my package into their R console, using library() function. However I could not figure out where and how should I add this functionality in entire package development procedure, and the Writing R Exts document also seem to be mum on this issue. Can somebody help me how to add this functionality in the development route of package. I believe this is possible as in many existing packages that functionality is present. Thanks, __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to add a welcome message in Package development?
On Jun 10, 2011, at 2:54 PM, Nipesh Bajaj wrote: Dear all, it is my first post in R-devel list, and hope that this is the right place to ask question related to package development. I have created my first package in Windows through the usual route. Now I want to add some ***Welcome message*** as soon as user loads my package into their R console, using library() function. However I could not figure out where and how should I add this functionality in entire package development procedure, and the Writing R Exts document also seem to be mum on this issue. Personally, I find welcome messages extremely annoying, because if you load a dependency chain of 20 packages and each has something silly to say, you get pages of completely useless output (since you can't read all of them anyway) that tend to interfere with automated scripts. Also anything people tend to say in those is pertinent only once (when the user first sees the message) so the message is pointless most of the time that it's shown. But that's just my opinion. That said, you can simply use cat() in .First.lib (if your packages has no namespace) or .onAttach or .onLoad (if your packages has a namespace). Cheers, Simon Can somebody help me how to add this functionality in the development route of package. I believe this is possible as in many existing packages that functionality is present. Thanks, __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to add a welcome message in Package development?
On 10 June 2011 at 15:10, Simon Urbanek wrote: | | On Jun 10, 2011, at 2:54 PM, Nipesh Bajaj wrote: | | Dear all, it is my first post in R-devel list, and hope that this is | the right place to ask question related to package development. | | I have created my first package in Windows through the usual route. | Now I want to add some ***Welcome message*** as soon as user loads my | package into their R console, using library() function. However I | could not figure out where and how should I add this functionality in | entire package development procedure, and the Writing R Exts | document also seem to be mum on this issue. | | | Personally, I find welcome messages extremely annoying, because if you load a dependency chain of 20 packages and each has something silly to say, you get pages of completely useless output (since you can't read all of them anyway) that tend to interfere with automated scripts. Also anything people tend to say in those is pertinent only once (when the user first sees the message) so the message is pointless most of the time that it's shown. But that's just my opinion. | | That said, you can simply use cat() in .First.lib (if your packages has no namespace) or .onAttach or .onLoad (if your packages has a namespace). No, not cat() --- please use packageStartupMessage() as that can actually be suppressed easily. Dirk, who also finds them annoying -- Gauss once played himself in a zero-sum game and won $50. -- #11 at http://www.gaussfacts.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to add a welcome message in Package development?
I agree with Simon that package startup messages are often annoying and not often helpful. However, I think they should be generated with packageStartupMessage(your message) instead of cat(your message\n) The former may be suppressed by wrapping the call to library() with suppressPackageStartupMessages(), just as messages generated by message(your message) may be suppressed with suppressMessages(). You can suppress cat()'s output with capture.output() but you may throw out things that should be seen. E.g., if a package with a NAMESPACE file contains the following .onXXX functions % more testPkgWithNamespace/R/zzz.R .onAttach - function(...) { cat(message from .onAttach via cat\n) message(message from .onAttach via message) packageStartupMessage(message from .onAttach via packageStartupMessage\n) } .onLoad - function(...) { cat(message from .onLoad via cat\n) message(message from .onLoad via message) packageStartupMessage(message from .onLoad via packageStartupMessage\n) } we get: library(testPkgWithNamespace, lib.loc=Rlib) message from .onLoad via cat message from .onLoad via message message from .onLoad via packageStartupMessage message from .onAttach via cat message from .onAttach via message message from .onAttach via packageStartupMessage detach(package:testPkgWithNamespace, unload=TRUE) suppressMessages(library(testPkgWithNamespace, lib.loc=Rlib)) message from .onLoad via cat message from .onAttach via cat detach(package:testPkgWithNamespace, unload=TRUE) suppressPackageStartupMessages(library(testPkgWithNamespace, lib.loc=Rlib)) message from .onLoad via cat message from .onLoad via message message from .onAttach via cat message from .onAttach via message Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-project.org] On Behalf Of Simon Urbanek Sent: Friday, June 10, 2011 12:10 PM To: Nipesh Bajaj Cc: r-devel@r-project.org Subject: Re: [Rd] How to add a welcome message in Package development? On Jun 10, 2011, at 2:54 PM, Nipesh Bajaj wrote: Dear all, it is my first post in R-devel list, and hope that this is the right place to ask question related to package development. I have created my first package in Windows through the usual route. Now I want to add some ***Welcome message*** as soon as user loads my package into their R console, using library() function. However I could not figure out where and how should I add this functionality in entire package development procedure, and the Writing R Exts document also seem to be mum on this issue. Personally, I find welcome messages extremely annoying, because if you load a dependency chain of 20 packages and each has something silly to say, you get pages of completely useless output (since you can't read all of them anyway) that tend to interfere with automated scripts. Also anything people tend to say in those is pertinent only once (when the user first sees the message) so the message is pointless most of the time that it's shown. But that's just my opinion. That said, you can simply use cat() in .First.lib (if your packages has no namespace) or .onAttach or .onLoad (if your packages has a namespace). Cheers, Simon Can somebody help me how to add this functionality in the development route of package. I believe this is possible as in many existing packages that functionality is present. Thanks, __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to add a welcome message in Package development?
On Jun 10, 2011, at 3:36 PM, Dirk Eddelbuettel wrote: On 10 June 2011 at 15:10, Simon Urbanek wrote: | | On Jun 10, 2011, at 2:54 PM, Nipesh Bajaj wrote: | | Dear all, it is my first post in R-devel list, and hope that this is | the right place to ask question related to package development. | | I have created my first package in Windows through the usual route. | Now I want to add some ***Welcome message*** as soon as user loads my | package into their R console, using library() function. However I | could not figure out where and how should I add this functionality in | entire package development procedure, and the Writing R Exts | document also seem to be mum on this issue. | | | Personally, I find welcome messages extremely annoying, because if you load a dependency chain of 20 packages and each has something silly to say, you get pages of completely useless output (since you can't read all of them anyway) that tend to interfere with automated scripts. Also anything people tend to say in those is pertinent only once (when the user first sees the message) so the message is pointless most of the time that it's shown. But that's just my opinion. | | That said, you can simply use cat() in .First.lib (if your packages has no namespace) or .onAttach or .onLoad (if your packages has a namespace). No, not cat() --- please use packageStartupMessage() as that can actually be suppressed easily. Thanks, very, very good point -- that many package authors did not get (I actually checked a few packages before replying and they all use cat() ... eek). Thanks, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to add a welcome message in Package development?
On 10 June 2011 at 16:04, Simon Urbanek wrote: | On Jun 10, 2011, at 3:36 PM, Dirk Eddelbuettel wrote: | | That said, you can simply use cat() in .First.lib (if your packages has no namespace) or .onAttach or .onLoad (if your packages has a namespace). | | No, not cat() --- please use packageStartupMessage() as that can actually | be suppressed easily. | | | Thanks, very, very good point -- that many package authors did not get (I actually checked a few packages before replying and they all use cat() ... eek). Yup :) I have over the years contacted a few fellow package authors to get this changes. Lots to do still. Maybe R CMD check should look into .onLoad() et al? Dirk -- Gauss once played himself in a zero-sum game and won $50. -- #11 at http://www.gaussfacts.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel