我有很多R源文件.例如,在两个A.R和C.R文件中,B.R通过加载source().现在,我想使用的功能均A.R和C.R,我怎么能避免采购B.R反复?在C/C++中是否有类似的保护机制?
如果BR已经在其中设置了具有相当唯一名称的功能或数据,则可以将其用作保护.否则,只需定义一个:
BR
B_is_loaded <- TRUE
# The normal B stuff
Run Code Online (Sandbox Code Playgroud)
AR:
if(!exists("B_is_loaded")) source("B.R")
# Now you can call the stuff in B
Run Code Online (Sandbox Code Playgroud)