Skip to content

Commit ea42ed2

Browse files
committed
Fixed if temp var already in IPS
1 parent 7185485 commit ea42ed2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

R/fitISDM.R

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ fitISDM <- function(data, options = list()) {
7979

8080
if (!is.null(data$.__enclos_env__$private$temporalName)) {
8181

82+
if (!data$.__enclos_env__$private$temporalName %in% names(data$.__enclos_env__$private$IPS)) {
83+
8284
numTime <- length(unique(unlist(data$.__enclos_env__$private$temporalVars)))
8385

8486
newIPS <- rep(list(data$.__enclos_env__$private$IPS), numTime)
@@ -91,6 +93,7 @@ fitISDM <- function(data, options = list()) {
9193

9294
data$.__enclos_env__$private$IPS <- newIPS
9395

96+
}
9497
}
9598

9699
comp_terms <- gsub('\\(.*$', '', data$.__enclos_env__$private$Components)

R/specifyISDM.R

+25-8
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,15 @@ specifyISDM$set('public', 'initialize', function(data, projection, Inlamesh, in
11691169

11701170
if (!missing(offset)) private$Offset <- offset
11711171

1172+
private$Spatial <- spatial
1173+
private$Intercepts <- intercepts
1174+
1175+
private$covariateFormula <- formulas$covariateFormula
1176+
private$biasFormula <- formulas$biasFormula
1177+
1178+
private$Projection <- projection
1179+
private$INLAmesh <- Inlamesh
1180+
11721181
private$pointCovariates <- pointcovariates
11731182

11741183
if (!is.null(spatialcovariates)) private$spatialCovariates(spatialcovariates)
@@ -1188,14 +1197,6 @@ specifyISDM$set('public', 'initialize', function(data, projection, Inlamesh, in
11881197
}
11891198
private$IPS <- ips
11901199

1191-
private$Spatial <- spatial
1192-
private$Intercepts <- intercepts
1193-
1194-
private$covariateFormula <- formulas$covariateFormula
1195-
private$biasFormula <- formulas$biasFormula
1196-
1197-
private$Projection <- projection
1198-
private$INLAmesh <- Inlamesh
11991200

12001201
private$addData(dataList = data, responseCounts = responsecounts,
12011202
responsePA = responsepa, trialsPA = trialspa,
@@ -1317,6 +1318,18 @@ specifyISDM$set('private', 'addData', function(dataList, responseCounts, respons
13171318

13181319
private$temporalVars <- pointData$timeIndex
13191320

1321+
numTime <- length(unique(unlist(private$temporalVars)))
1322+
1323+
newIPS <- rep(list(private$IPS), numTime)
1324+
1325+
newIPS <- do.call(rbind, newIPS)
1326+
1327+
newIPS[, private$temporalName] <- rep(1:numTime, each = nrow(private$IPS))
1328+
1329+
newIPS <- st_transform(newIPS, private$Projection)
1330+
1331+
private$IPS <- newIPS
1332+
13201333
}
13211334

13221335
##How does this work?
@@ -1385,6 +1398,8 @@ specifyISDM$set('private', 'addData', function(dataList, responseCounts, respons
13851398
envir = private$spatcovsEnv)[cov],
13861399
layer = cov)
13871400

1401+
if (is.character(pointData$Data[[data]][[species]][[covIndex]])) pointData$Data[[data]][[species]][[covIndex]] <- as.factor(pointData$Data[[data]][[species]][[covIndex]])
1402+
13881403
if (any(is.na(pointData$Data[[data]][[species]][[covIndex]]))) {
13891404

13901405
pointData$Data[[data]][[species]][[covIndex]] <- inlabru::bru_fill_missing(where = pointData$Data[[data]][[species]],
@@ -1416,6 +1431,8 @@ specifyISDM$set('private', 'addData', function(dataList, responseCounts, respons
14161431
layer = covIPS
14171432
)
14181433

1434+
if (is.character(private$IPS[[covADD]])) private$IPS[[covADD]] <- as.factor(private$IPS[[covADD]])
1435+
14191436
if (any(is.na(private$IPS[[covADD]]))) {
14201437

14211438
private$IPS[[covADD]] <- inlabru::bru_fill_missing(where = private$IPS,

0 commit comments

Comments
 (0)