I have to separate files, one to start a simulation (the main file) and a file with the required functions.
In the main file CalcPriceSystem is called:
priceSystemInit <- CalcPriceSystem(df.firmDistribution, shopMatrixInit, utilityMatrix,
prices, initialPrice, repetitions,
quantity, profit)
In the function file I define the function CalcPriceSystem:
CalcPriceSystem <- function(df.firmDistribution, shopMatrix, utilityMatrix, prices, initialPrice, repetitions , quantity , profit, ...){
response.df <- data.frame(matrix(, nrow=repetitions, ncol=0))
for(i in 1:length(unique(df.firmDistribution[,1]))){
competitors <- which(unique(df.firmDistribution[,1])[i]==df.firmDistribution[,1])
response.df <- cbind(response.df, BestResponsePar(utilityMatrix[,competitors], shopMatrix[,unique(df.firmDistribution[,1])[i]],
prices, initialPrice[competitors], repetitions, quantity , profit ,
#shopMatrix[,df.firmDistribution[1,1]] value where firm i resides
marketNumber = unique(df.firmDistribution[,1])[i]))
}
#Order the response alphabetically
response.df <- response.df[,order(names(response.df))]
#Rearrange PriceLevelMarket variables to the last columns
response.df <- response.df[,c(names(response.df)[-grep("Price",names(response.df))],
names(response.df)[grep("PriceLevel",names(response.df))])]
return(response.df)
}
If I source the main file before I source the function file there is no error reported and computation works fine. It works also fine if I write the functions into the main file, but I'd like to place them into a separate one.
And now to the strange behavior: If I source the function file BEFORE the main file, R throws an unused argument error. Even if the R Environment (data, functions) is exactly the same as above.
Error in CalcPriceSystem(df.firmDistribution, shopMatrixInit, utilityMatrix, :
unused arguments (initialPrice, repetitions, quantity, profit)
Why is that?
Thanks