R/ravisCacheEnvironment.R

# cache mecanism for internal use of the package

.ravis_cache <- new.env()

# returns a cached variable if it's intializated. If not, 
# initialize it by calling the function provided
# 
.avisCacheReturnOrSetup<-function(varname, setupfun)
{
  if(!.avisCacheHas(varname))
  {
  	if(is.function(setupfun)){
  		setupcall <- as.call(list(setupfun))
    } else {
      setupcall <- call(setupfun)
    }

    setupvalue <- eval(setupcall)
    .avisCacheSet(varname, setupvalue)

    .avisCacheGet(varname)
  }

  return (.avisCacheGet(varname))
}

.avisCacheHas<-function(varname)
{
	exists(varname, envir=.ravis_cache)
}

.avisCacheGet<-function(varname)
{
	return (get(varname, envir=.ravis_cache))
}

.avisCacheSet<-function(varname, value)
{
	assign(varname, value, envir = .ravis_cache)
}

Try the rAvis package in your browser

Any scripts or data that you put into this service are public.

rAvis documentation built on May 2, 2019, 3:28 p.m.