Skip to content

Commit 2ecfbbc

Browse files
do not use native pipe or \(...) lambdas, so we do not have to depend on >= R-4.1.
1 parent 5e67f70 commit 2ecfbbc

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

R/autoplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ plot_data <- function(x) {
6060
by(
6161
x,
6262
x$run,
63-
\(y) data.frame(
63+
function(y) data.frame(
6464
run = unique(y$run),
6565
order = 1 + max(y$order),
6666
site = 0

R/clarke_wright.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ clarke_wright_stepwise <- function(demand, distances, vehicles,
152152
`_heumilkr_cpp_clarke_wright_stepwise`, as.numeric(demand), distances,
153153
vehicles$n, vehicles$caps, restrictions$site, restrictions$vehicle
154154
),
155-
\(x) heumilkr_solution(
155+
function(x) heumilkr_solution(
156156
x,
157157
distances = distances
158158
)

R/cvrplib.R

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,16 @@ cvrplib_url <- "http://vrp.atd-lab.inf.puc-rio.br/media/com_vrp/instances/"
131131
cvrplib_ls <- function() {
132132
# reading directories first
133133
rel_dirs <-
134-
xml2::read_html(paste0(readLines(url(cvrplib_url)), collapse = "\n")) |>
135-
xml2::xml_find_all("//a[substring(@href, string-length(@href) - string-length('/') +1) = '/']") |>
136-
xml2::xml_attr("href") |>
137-
setdiff(c("/media/com_vrp/", "test/", "CMT/"))
134+
setdiff(
135+
xml2::xml_attr(
136+
xml2::xml_find_all(
137+
xml2::read_html(paste0(readLines(url(cvrplib_url)), collapse = "\n")),
138+
"//a[substring(@href, string-length(@href) - string-length('/') +1) = '/']"
139+
),
140+
"href"
141+
),
142+
c("/media/com_vrp/", "test/", "CMT/")
143+
)
138144
# CMT has buggy .sol files
139145

140146
# iterate over all directories and collect file names
@@ -144,17 +150,21 @@ cvrplib_ls <- function() {
144150
unlist(
145151
lapply(
146152
rel_dirs,
147-
\(rel_dir) {
153+
function(rel_dir) {
148154
paste0(
149155
rel_dir,
150-
xml2::read_html(
151-
paste0(
152-
readLines(url(paste0(cvrplib_url, rel_dir))),
153-
collapse = "\n"
154-
)
155-
) |>
156-
xml2::xml_find_all("//a[substring(@href, string-length(@href) - string-length('.vrp') +1) = '.vrp']") |>
157-
xml2::xml_attr("href")
156+
xml2::xml_attr(
157+
xml2::xml_find_all(
158+
xml2::read_html(
159+
paste0(
160+
readLines(url(paste0(cvrplib_url, rel_dir))),
161+
collapse = "\n"
162+
)
163+
),
164+
"//a[substring(@href, string-length(@href) - string-length('.vrp') +1) = '.vrp']"
165+
),
166+
"href"
167+
)
158168
)
159169
}
160170
)
@@ -231,7 +241,7 @@ cvrplib_download <- function(qualifier) {
231241
demand_section <- grep("DEMAND_SECTION", content, fixed = TRUE)
232242
edge_content <- content[edge_weight_section:(demand_section - 1)]
233243

234-
lower_triang <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), \(x) x[x != ""])))
244+
lower_triang <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), function(x) x[x != ""])))
235245
dmat <- matrix(0, nrow = dimension, ncol = dimension)
236246
dmat[upper.tri(dmat, diag = TRUE)] <- lower_triang
237247
pos <- as.data.frame(cmdscale(dist(dmat + t(dmat))))
@@ -241,7 +251,7 @@ cvrplib_download <- function(qualifier) {
241251
demand_section <- grep("DEMAND_SECTION", content, fixed = TRUE)
242252
edge_content <- content[edge_weight_section:(demand_section - 1)]
243253

244-
lower_triang <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), \(x) x[x != ""])))
254+
lower_triang <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), function(x) x[x != ""])))
245255
dmat <- matrix(0, nrow = dimension, ncol = dimension)
246256
dmat[upper.tri(dmat)] <- lower_triang
247257
pos <- as.data.frame(cmdscale(dist(dmat + t(dmat))))
@@ -250,7 +260,7 @@ cvrplib_download <- function(qualifier) {
250260
} else if (edge_weight_format == "FULL_MATRIX") {
251261
edge_content <- content[edge_weight_section:(edge_weight_section + dimension - 1)]
252262

253-
dmat <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), \(x) x[x != ""])))
263+
dmat <- as.numeric(unlist(lapply(strsplit(edge_content, "\\s+"), function(x) x[x != ""])))
254264
dim(dmat) <- c(dimension, dimension)
255265

256266
pos <- as.data.frame(cmdscale(dist(dmat)))

R/heumilkr_solution.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ milkr_saving <- function(solution, relative = FALSE) {
100100
sum(
101101
vapply(
102102
1:(dim(d)[[2]] - 1),
103-
\(idx) 2 * d[1, idx + 1],
103+
function(idx) 2 * d[1, idx + 1],
104104
FUN.VALUE = 1.
105105
)
106106
)

tests/testthat/helper-hedgehog.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gen.demand_net <- function(max_sites = 10L) {
77
demand = gen.demand(n_sites),
88
distances = hedgehog::gen.with(
99
gen.pos(n_sites),
10-
\(pos) dist(pos, method = "euclidean")
10+
function(pos) dist(pos, method = "euclidean")
1111
)
1212
)
1313
}
@@ -62,6 +62,6 @@ gen.coords <- function(n_sites) {
6262
),
6363
half_plane = hedgehog::gen.element(c(1, -1))
6464
),
65-
\(g) c(0, g$half_plane * g$positives)
65+
function(g) c(0, g$half_plane * g$positives)
6666
)
6767
}

0 commit comments

Comments
 (0)