R/renderobject.R

Defines functions renderobject

renderobject <- function(object, Routput, fnargs, cache=TRUE){

	#block 'save' for GET
	if(Routput == "save"){
		stop("Output type /save cannot be used with method GET.")
	}

	#we evaluate the meta parameters.
	if(length(fnargs) > 0){
		
		#check for illegal code injection
		if(any(substr(names(fnargs),1,1) == "#")){
			stop("arguments are not allowed to start with a #");
		}
		
		#parse HTTP arguments and evaluate
		fnargs <- lapply(fnargs, tryParse, disable.eval=TRUE);		

		#check for a seed
		if(!is.null(fnargs[["!seed"]])){
			set.seed(fnargs[["!seed"]]);
			fnargs[["!seed"]] <- NULL;
		}
	}
	
	#add the function as an argument		
	fnargs[["#dofn"]] <- "identity";
	
	#load the object from the store
	fnargs[["x"]] <- object;	
	
	#perform the actual request
	returndata <- callfunction(fnargs, Routput);
	
	#add default cache value
	if(isTRUE(cache)){
		returndata$cache <- config("cache.store");
	} else {
		returndata$cache <- FALSE
	}
	
	#return the list with content and type and status
	return(returndata);
}
jeroenooms/opencpu-legacy documentation built on May 19, 2019, 6:15 a.m.