Skip to content

Commit 0bbbb7b

Browse files
committed
refactor: Update names of covars in rast object to match file naming
1 parent c2b7b51 commit 0bbbb7b

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

02_Covariates_Extraction.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ raster_list
9090
#Stack all unique covariates
9191
raster_2024_covariates <- rast(paste0(covs_path_2024, c(raster_list)))
9292

93-
# Find duplicate layer names
94-
dup_names <- names(raster_2024_covariates)[duplicated(names(raster_2024_covariates))]
93+
names(raster_2024_covariates) <- sources(raster_2024_covariates) %>%
94+
lapply(str_split_i, "/", -1) %>%
95+
lapply(str_split_i, ".tif", 1)
9596

96-
# Remove layers with duplicate names (keep only the first occurrence)
97-
unique_layers <- !duplicated(names(raster_2024_covariates))
98-
raster_2024_covariates <- raster_2024_covariates[[unique_layers]]
9997

10098
#Extract rasters using their mean values
10199
tic()

0 commit comments

Comments
 (0)