Hi all,
I am back yet again hoping to learn from this great group of folks here. I am working to translate and adapt some R functions I wrote to nimble. My R functions are built with multiple conditional ifelse statements where there are threshold values needed for reproduction or survival, for example. the ifelse() function doesnt work with nimble, so I've been trying to code it appropriately, but I'm having trouble. I've looked through the existing conversations here in the google group and did my best to adapt accordingly, but I'm still running in to issues.
The section of R code I am trying to replicate is here in red, with the corresponding section of the nimbleFunction in red below. Errors from printErrors() are included as well.
Thanks a lot
Ben
# if Zs is below min threshold she doesnt breed, or if available Zr:Z is less than threshold she does not breed
u<-ifelse (zs.values <= zs.threshold.k, 0, ifelse (Zr_o/z.tot<=breeding.zr.threshold, 0, 1))
R.nimb <- nimbleFunction(run = function(zr.v=double(1),zs.v=double(1),zs.k=double(0),c.slope=double(0),v.eng=double(0),steep=double(0),fat.thresh=double(0),sburn=double(0),sbs=double(0),sbw=double(0),m.ana=double(0),
m.cat=double(0),
zr.br=double(0),neomort=double(0),v.biom=double(0),warb=double(1),ost=double(1),aF=double(0),season=double(0)){
returnType(double(1))
ztot<-zr.v+zs.v
maxC <- C.nimb(zr.v,zs.v,c.slope,steep,fat.thresh,v.biom,ost,aF,season)
burned <- burn.nimb(z,sburn,sbs,sbw,season)
if(season==2) eOut<-burned + (((63.24*(warb*0.85))/0.98 + (((0.05*70*4.187*0.85^0.75)/0.85)*warb)*200) * 0.001)
if(season==1) eOut<-burned
dE <- v.eng*(maxC*6)-eOut
zr.o <- zr.v+(1/m.ana)*dE
#create placeholder u to be filled with 0 and 1
u <- zr.o
for(i in 1:length(zr.o)){
u[i]<- 0
if(zs.v[i] <= zs.k) u[i] <- 0
if((zr.o[i]/ztot[i]) <= zr.br) u[i] <- 0
if((zr.o[i]/ztot[i]) >= zr.br) u[i] <- 1
} u <- (1-neomort)*u
u <- u/2
return(u)
})
compileNimble(R.nimb)
> printErrors()
P_17_rcFun_R_GlobalEnv21.cpp:73:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
}
^
P_17_rcFun_R_GlobalEnv21.cpp:210:29: error: use of undeclared identifier 'z'
burned = rcFun_R_GlobalEnv9(z, ARG8_sburn_, ARG9_sbs_, ARG10_sbw_, ARG19_season_);
^
1 warning and 1 error generated.
make: *** [P_17_rcFun_R_GlobalEnv21.o] Error 1