简体   繁体   English

在另一个程序包或函数中装载一个程序包时,是否有可能得到通知?

[英]Is it possible to get notified when a package is loaded within another package or function?

I am writing a function for my package, and its goal is to get notified when a certain package is loaded so that it could do something to respond to the package loading. 我正在为我的程序包编写一个函数,其目的是在加载某个程序包时得到通知,以便它可以对程序包的加载做出响应。 It's similar to .onLoad() except that it's the response for other packages. 它与.onLoad()相似,只是它是对其他软件包的响应。

Is it possible to do this in R? 在R中可以这样做吗?

OK, I figured it out by using setHook() . 好的,我通过使用setHook()弄清楚了。

setHook(packageEvent("pkg", "attach"),
    function(...) {
      message('hooked')
    } )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否有可能从另一个包中的函数@inheritParams? - Is it possible to @inheritParams from a function within another package? get(search()[2])中的R错误:尝试从已加载的包中调用函数时找不到对象 - R error in get(search()[2]): object not found when trying to call a function from a loaded package 如何通过命名空间查看哪个R包或函数已经加载了另一个R包 - How to see which R package or function has loaded another R package via namespace 从另一个包中调用时,无法从 mgcv 访问“ldTweedie”函数 - No access to "ldTweedie" function from mgcv when called from within another package 以编程方式获取加载包的函数X标题 - Get loaded package's function X title programmatically 覆盖另一个包继承的包函数 - Overriding a package function inherited by another package 未声明函数(函数作为另一个函数的参数)-创建包时的XPtr - function was not declared (function as argument to another)- XPtr when creating package 包中的R编辑功能 - Edit R function within a package 在函数内使用sfApply时的作用域问题(程序包降雪-R) - Scoping problem when sfApply is used within function (package snowfall - R) 如果包已经加载,那么在函数内部需要包的影响是什么? - Whats the impact of requiring a package inside a function if the package is already loaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM