如何防止 source() R 代码被多次包含?
我有很多 R 源文件。例如,在 AR
和 CR
文件中,BR
都是通过 source()
加载的。现在我想同时使用AR
和CR
中的功能,如何避免重复采购BR
? C/C++ 中是否有类似的包含保护机制?
I have lots of R source files. For example, in both A.R
and C.R
files, B.R
is loaded via source()
. Now I'd like to use the functions in both A.R
and C.R
, how can I avoid sourcing B.R
repeatedly? Is there any include guard mechanisms similar in C/C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 BR 中已经有一个具有相当唯一名称的函数或数据集,您可以将其用作防护。否则,只需定义一个:
BR
AR:
If B.R already has a function or data set in it with a rather unique name, you could use it as a guard. Otherwise, just define one:
B.R
A.R: