I am trying to load a set of shapefiles into R using a loop. I am trying to find a way to name the loaded shapefile using the name as it stored in the vector used for the loop.
When I run the following code the loaded shapefile is named "s" instead of "spain", "france", or "portugal".
I have tried something like paste(print(s))
but it is not successful.
Make list of all names
shapefiles<-c("spain","france","portugal")
Load files
for (s in shapefiles) {
combine<-paste(s,"borders.shp",sep = "")
s<-st_read(paste("./repository/",print(combine), sep=""))
}
SOLUTION:
Make list of all names
shapefiles<-c("spain","france","portugal")
Load files
for (s in 1:length(shapefiles)) {
combine<-paste(shapefiles[s],"borders.shp",sep = "")
assign(shapefiles[s],st_read(paste("./repository/",print(combine), sep=""))) }