S4 oop を使用して R で土壌水収支モデルを実行しています。クラス waterBalance のオブジェクトを作成しましたが、メソッド内からスロットを更新できません。ここには、私が見ていない単純なものがあるに違いありません。私の更新コードは次のとおりです。
setGeneric(name="updateASW",def=function(object,...){standardGeneric("updateASW")})
setMethod(f = "updateASW",
signature(object = "WaterBalance"),
function(object, radiationI, rainfallI, maxTI, minTI, laiTI, laiWI, monthI, yearI) {
object@maxT<-maxTI
object@minT<-minTI
object@laiT<-laiTI
object@laiW<-laiWI
object@month<-monthI
object@year<-yearI
object@radiation<-radiationI
object@precipitation<-rainfallI
object@availableSoilWater<-object@availableSoilWater+rainfallI-getInterception(object)-penmanMonteith(object)
if (object@availableSoilWater>object@ASWMax) {
object@availableSoilWater<-object@ASWMax
}
if (object@availableSoilWater<object@ASWMin) {
object@availableSoilWater<-object@ASWMin
}
})
このクラスの他のすべてのメソッドをテストしたところ、エラーなしで正しい値が返されました。このメソッドは、スロット値を更新しようとする唯一のメソッドです。
クラス waterBalance のオブジェクトを作成し、この更新コードを実行しようとすると、次のようになります。
> testWB<-makeWB(100,200,50,"loam",0.02,0.02,58,300,25,-2,15)
> testWB
ASW = 100
ASW Max = 200
ASW Min = 50
LAI of trees = 3
LAI of weeds = 0
Soil type = loam
Radiation =
Rainfall =
Max T =
Min T =
Latitude = 58
Altitude = 300
Gs Max for trees = 0.02
Gs Max for weeds = 0.02
Maximum temp for Ps = 25
Minimum temp for Ps = -2
OPtimum temp for Ps = 15
> updateASW(testWB, 25, 0, 25, 10, 6, 0, 7, 2004)
> testWB
ASW = 100
ASW Max = 200
ASW Min = 50
LAI of trees = 3
LAI of weeds = 0
Soil type = loam
Radiation =
Rainfall =
Max T =
Min T =
Latitude = 58
Altitude = 300
Gs Max for trees = 0.02
Gs Max for weeds = 0.02
Maximum temp for Ps = 25
Minimum temp for Ps = -2
OPtimum temp for Ps = 15
>
したがって、オブジェクト インスタンスのスロット値は変更されません。どこが間違っているのか教えてください。
ありがとう、
ユアン