is there any way to display a message when a user loads library(myCustomLibrary)
?
Upon loading, I want to display a message that tells the user how to run all the test functions.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes. You can use the .onLoad
, .onAttach
, or .First.lib
functions to do whatever you want when the package is loaded. I suggest looking at the help for those functions. You would use .onLoad
with a namespace, and .First.lib
without.
One convention is that people will frequently put these commands in a separate zzz.R
file, which is just used for package related code.
回答2:
Quick points:
if your package has a NAMESPACE, then
.onLoad()
is where you do thisif your package does not have NAMESPACE, then
.First.lib()
is where you do thiseither way, use
packageStartupMessage()
instead ofcat()
so that users have a choice of suppressing this.