8
我想懶惰地讀取不同文本文件中的數據,類似於延遲加載數據集(例如,將iris
鍵入R,從datasets
包中延遲加載數據集)。這裏的區別是,我想要一個R expression
只要某個變量(這裏我使用x
)被輸入到R控制檯或被其他代碼使用,就會運行R expression
。從零開始編寫一個R promise對象(懶惰評估)
# The expression that I want run if the variable x is called by some other code
expn = quote({x = read.table(text = "a b \n 1 2", header=TRUE)})
# When I type this, I want the language object 'expn' to be evaluated
# (e.g. eval(expn)) so that the variable x now exists
x
有沒有辦法用R promise對象做到這一點?我必須創建一個R包來獲得這種行爲嗎?