OpasnetUtils/Fetch: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
Line 12: Line 12:
label="Initiate functions"
label="Initiate functions"
graphics="1"
graphics="1"
showcode="1"
>
>
# FETCH ##################### fetch downloads a variable.
# FETCH ##################### fetch downloads a variable.
Line 31: Line 32:
{{comment|# |Fetch should take 'dependencies' as argument and download variables to global memory. Fetch2 does that and I move to suggest that we replace fetch with Fetch2|--[[User:Teemu R|Teemu R]] 11:28, 15 June 2012 (EEST)}}
{{comment|# |Fetch should take 'dependencies' as argument and download variables to global memory. Fetch2 does that and I move to suggest that we replace fetch with Fetch2|--[[User:Teemu R|Teemu R]] 11:28, 15 June 2012 (EEST)}}


<rcode label="Initiate functions">
<rcode  
label="Initiate functions"
showcode="1"
>
# Fetch2 #################### loads all given dependencies to global memory
# Fetch2 #################### loads all given dependencies to global memory



Revision as of 10:33, 15 June 2012


Description

fetch downloads a variable.

Code

- Hide code

# FETCH ##################### fetch downloads a variable.

fetch <- function(x, direction = "wide") { # Could think of a version where dependencies table is given as a parameter, and based on Name, Identifier is downloaded from the Base.
	x <- as.character(x)
	if(exists(x)) {
		out <- get(x)
	} else {
		out <- tidy(op_baseGetData("opasnet_base", x), direction = "wide")
	}
	return(out)
}

Alternative

----#: . Fetch should take 'dependencies' as argument and download variables to global memory. Fetch2 does that and I move to suggest that we replace fetch with Fetch2 --Teemu R 11:28, 15 June 2012 (EEST) (type: truth; paradigms: science: comment)

- Hide code

# Fetch2 #################### loads all given dependencies to global memory

Fetch2 <- function(dependencies, evaluate = FALSE) {
	for (i in 1:nrow(dependencies)) {
		if(!exists(dependencies$Name[i])) {
			objects.get(dependencies$Key[i]) # Key is the R-tools session identifier (shown at the end of the url)
			if (evaluate) get(dependencies$Name[i])@output <- EvalOutput(get(dependencies$Name[i])) 
			# Eval not necessarily needed at this point
		}
	}
}

See also