我必须分开文件,一个用于启动模拟(主文件)和一个具有所需功能的文件。
在主文件中调用CalcPriceSystem:
priceSystemInit <- CalcPriceSystem(df.firmDistribution, shopMatrixInit, utilityMatrix,
prices, initialPrice, repetitions,
quantity, profit)
在函数文件中,我定义了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)
}
如果我在获取函数文件之前获取主文件,则不会报告错误并且计算正常。如果我将函数写入主文件,它也可以正常工作,但我想将它们放在一个单独的文件中。
现在到了奇怪的行为:如果我在主文件之前输入函数文件,R会抛出一个未使用的参数错误。即使R环境(数据,功能)与上述完全相同。
Error in CalcPriceSystem(df.firmDistribution, shopMatrixInit, utilityMatrix, :
unused arguments (initialPrice, repetitions, quantity, profit)
为什么?
由于