[R] delayedAssign list members

Shan Huang openhuangs at gmail.com
Tue Mar 4 09:23:18 CET 2014


I am fascinated by lazy evaluation mechanism provided by delayedAssign. Like

 

delayedAssign("foo", { 

  Sys.sleep(1)  # or any other time consuming operations

  1

}

 

Time consuming operations will be evaluated only if object "foo" is used.

But when I try: 

 

foo <- list()

foo$bar <- 1

delayedAssign("foo$bar", 2)

foo$bar  # 1

`foo$bar`  # 2

 

Shows that delayedAssign can't be applied to list members, instead symbol
with "$" will be assigned.

What I actually want is a lazy evaluation wrapper for large complex
hierarchical datasets. Like:

 

MyDatasets <- list(

  Dataset1 = complexData1

  Dataset2 = complexData2

)

 

There is no need for loading whole datasets when I only use Dataset1. And I
want to implement some 

incremental updating mechanism fetching data from remote host.

Can any one give me some tips to implement this?



More information about the R-help mailing list