Skip to content

Commit 80540fb

Browse files
committed
minor comments, lintr, styler
1 parent ad486b1 commit 80540fb

22 files changed

+48
-40
lines changed

R/geopressure_map_preprocess.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ geopressure_map_preprocess <- function(tag, compute_known = FALSE) {
188188

189189
assertthat::assert_that(all(!is.na(pgi_reg$value)))
190190

191-
return(pgi_reg)
191+
pgi_reg
192192
})
193193

194194
# Combine into a single data.frame

R/geopressuretemplate_graph.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ geopressuretemplate_graph <- function(
8585
"i" = "Error while defining the movement model.{.var graph} is return.",
8686
">" = "Debug line by line by opening {.code edit(geopressuretemplate_graph)}"
8787
))
88-
return(graph)
88+
graph
8989
}
9090
)
9191

@@ -137,7 +137,7 @@ geopressuretemplate_graph <- function(
137137
"x" = "Error while computing the outputs. {.var graph} is returned.",
138138
">" = "Debug line by line by opening {.code edit(geopressuretemplate_graph)}"
139139
))
140-
return(graph)
140+
graph
141141
}
142142
)
143143

R/graph_assert.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ graph_status <- function(graph) {
5151
if (length(graph$s) > 0) {
5252
status <- append(status, "full")
5353
}
54-
return(status)
54+
status
5555
}

R/graph_create.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ graph_create <- function(tag,
175175
thr_prob <- ls[id_prob_percentile + 1]
176176

177177
# return matrix if the values are above the threshold
178-
return(l >= thr_prob)
178+
l >= thr_prob
179179
})
180180

181181
# Check that there are still values
@@ -371,6 +371,9 @@ graph_create <- function(tag,
371371
likelihood = likelihood
372372
)
373373

374+
# Check graph validity
375+
# all(graph$s[!(graph$s %in% graph$equipment)] %in% graph$t)
376+
374377
return(graph)
375378
}
376379

R/graph_most_likely.R

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,22 @@ graph_most_likely <- function(graph, quiet = FALSE) {
5858
# number of nodes in the 3d grid
5959
n <- prod(graph$sz)
6060

61-
# Compute the matrix TO
61+
# Compute the matrix TO (transition * observation)
6262
if (!quiet) {
6363
cli::cli_progress_step("Compute movement model")
6464
}
6565
trans_obs <- graph_transition(graph) * graph$obs[graph$t]
6666

67-
# Initiate the matrix providing for each node of the graph, the source id (index of the node)
68-
# with the most likely path to get there.
67+
# Initiate the sparse 1D matrix providing for each node of the graph, the source id (index of the
68+
# node in the 3D grid) with the cumulative max probability to get there.
69+
# Start with prob=1 at the equipment site (log = 0)
6970
path_s <- Matrix::sparseMatrix(
7071
rep(1, length(graph$equipment)),
7172
graph$equipment,
7273
x = 0, dims = c(1, n)
7374
)
74-
# Initiate the same matrix providing the total probability of the current path so far
75+
# Initiate the same matrix providing the cumulative total probability of the current path so far
76+
# Not sure why x is differently specify, should be the same value for both path_s and path_max
7577
path_max <- Matrix::sparseMatrix(
7678
rep(1, length(graph$equipment)),
7779
graph$equipment,
@@ -89,9 +91,10 @@ graph_most_likely <- function(graph, quiet = FALSE) {
8991
stap = arrayInd(graph$s, graph$sz)[, 3]
9092
)
9193

92-
# Split this data.fram by stationary period (of the source)
94+
# Split this data.frame by stationary period (of the source)
9395
node_stap <- split(node, node$stap)
9496

97+
# Compute number of nodes per stap
9598
n_edge <- sapply(node_stap, nrow)
9699

97100
if (!quiet) {
@@ -109,12 +112,14 @@ graph_most_likely <- function(graph, quiet = FALSE) {
109112
}
110113

111114
for (i_s in seq_len(length(node_stap))) {
115+
# Select all nodes of the current stap
112116
node_i_s <- node_stap[[i_s]]
113117

114-
# compute the probability of all possible transition
118+
# Compute the (cum) log probability of all possible transitions
115119
node_i_s$p <- path_max[node_i_s$s] + node_i_s$to
116120

117-
# Find the value of the maximum possible transition for each target node
121+
# Find the value of the maximum possible transition for each target node and store it into
122+
# path_max
118123
max_v <- sapply(split(node_i_s$p, node_i_s$t), max)
119124
max_t <- as.numeric(names(max_v))
120125
path_max[max_t] <- max_v

R/graph_transition.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ graph_transition <- function(graph) {
4343
))
4444
}
4545

46-
return(transition)
46+
transition
4747
}

R/light2mat.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ light2mat <- function(light, twl_offset = 0) {
5858

5959
if (length(candidates) > 0) {
6060
closest_idx <- candidates[which.min(abs(light_date_num[candidates] - t))]
61-
return(light_value[closest_idx])
61+
light_value[closest_idx]
6262
} else {
63-
return(NA)
63+
NA
6464
}
6565
}
6666

R/map_create.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ dim.map <- function(x) {
139139
# Compute value
140140
z$data <- mapply(\(p, l) {
141141
if (is.null(p) && is.null(l)) {
142-
return(NULL)
142+
NULL
143143
} else if (is.null(p)) {
144-
return(l)
144+
l
145145
} else if (is.null(l)) {
146-
return(p)
146+
p
147147
} else {
148-
return(p * l)
148+
p * l
149149
}
150150
}, x$data, y$data, SIMPLIFY = FALSE)
151151

@@ -157,5 +157,5 @@ dim.map <- function(x) {
157157

158158
z$type <- glue::glue("{x$type} x {y$type}")
159159

160-
return(z)
160+
z
161161
}

R/map_expand.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ map_expand <- function(extent, scale) {
7777
lon = lon,
7878
dim = dim
7979
)
80-
return(grid)
80+
grid
8181
}

R/path2edge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,5 @@ path2edge <- function(path, tag_graph) {
129129

130130
attr(edge, "type") <- attr(path, "type")
131131

132-
return(edge)
132+
edge
133133
}

0 commit comments

Comments
 (0)