How can I remove the element called ntl.tif, from a list in the below code?
wd = "C:/Users/nikos/OneDrive/Desktop/tehran/"
ntl = rast(paste0(wd, "ntl.tif"))
v <- vect(paste0(wd, "lc.shp"))
doStuff <- function(file){
pic = rast(file)
for (i in seq(from = 0.3, to = 3, by = 0.1)) {
print(i)
gf <- focalMat(pic, i * res(ntl), "Gauss")
r_gf <- focal(pic, w = gf, na.rm = TRUE)
r_gf = exact_resample(r_gf, ntl, fun = 'mean', coverage_area = FALSE)
r_gf <- mask(r_gf, v)
# ext(r_gf) <- ext(ntl)
(stringedi = gsub("\\.", "", toString(format(i, nsmall = 2))))
writeRaster(r_gf,
paste0(wd,
basename(fs::path_ext_remove(file)),
stringedi, ".tif"),
overwrite=TRUE)
}
}
list.files(wd, pattern = "tif$", full.names = TRUE) |>
purrr::walk(doStuff)
I tried something like
list.files(wd, pattern = "tif$", full.names = TRUE != "ntl.tif") |>
purrr::walk(doStuff)
or with an if
statement
doStuff <- function(file){
if (file != file.path(wd, "ntl.tif")) {
pic = rast(file)
for (i in seq(from = 0.3, to = 3, by = 0.1)) {
print(i)
gf <- focalMat(pic, i * res(ntl), "Gauss")
r_gf <- focal(pic, w = gf, na.rm = TRUE)
r_gf = exact_resample(r_gf, ntl, fun = 'mean', coverage_area = FALSE)
r_gf <- mask(r_gf, v)
ext(r_gf) <- ext(ntl)
(stringedi = gsub("\\.", "", toString(format(i, nsmall = 2))))
writeRaster(r_gf,
paste0("path/",
basename(fs::path_ext_remove(file)),
stringedi, ".tif"),
overwrite=TRUE)
}
}
}
but I couldn't fix the issue.