Skip to content
Prev 157070 / 398506 Next

Calling object outside function

I don't understand why you need to use a function at all, especially 
when all your function arguments are overwritten inside the loop.

Here is a simplified example of what you are doing:

f <- function(x){
  x <- 5
  print(x)
}

Therefore f(1), f(2), ..., f(1000) etc all gives you the same answer.

However, you can set a default value for x, which will allow you to vary 
it at a later stage if you wish to.

f <- function(x=5){
  print(x)
}

So now f() gives 5, f(10) gives 10, ...


Similarly, assuming that you want to vary the file, Loc_Mod_TAZ, 
Dev_Size later, you might be interested in perhaps:

loadTestData <- function(file="TAZ_VAC_ACRES.csv",
                          Loc_Mod_TAZ=120, Dev_Size=58){

    #Loads TAZ and corresponding vacant acres data
    TAZ_VAC_ACRES <- read.csv(file=file,header=TRUE);

    #Determines vacant acres by TAZ
    TAZDetermine=TAZ_VAC_ACRES[TAZ_VAC_ACRES$TAZ==Loc_Mod_TAZ,2]
    return(TAZDetermine)
}

out <- LoadTestData()

Regards, Adai
PDXRugger wrote: