I am trying to shortern my code by using functions and for
loops.
For the example below, I would like to create 5 different objects and then apply raster
to each object that is created. How can I do this with loops and functions?
#Defining variables of interest
url = "https://files.isric.org/soilgrids/latest/data/" # Path to the webDAV data.
voi1 = "sand"
voi2 = "clay"
voi3 = "silt"
voi4 = "phh2o"
voi5 = "soc"
depth = "5-15cm"
quantile = "mean" # prediction uncertainty quantified by probability distribution. Using mean of distribution
voi_layer1 = paste(paste(paste(url, voi1, "/", voi1, sep=""), depth, quantile, sep="_"), '.vrt', sep="")
voi_layer2 = paste(paste(paste(url, voi2, "/", voi2, sep=""), depth, quantile, sep="_"), '.vrt', sep="")
voi_layer3 = paste(paste(paste(url, voi3, "/", voi3, sep=""), depth, quantile, sep="_"), '.vrt', sep="")
voi_layer4 = paste(paste(paste(url, voi4, "/", voi4, sep=""), depth, quantile, sep="_"), '.vrt', sep="")
voi_layer5 = paste(paste(paste(url, voi5, "/", voi5, sep=""), depth, quantile, sep="_"), '.vrt', sep="")
#Apply 'raster' so can derive descriptions of each layer
sand = raster(voi_layer1)
clay = raster(voi_layer2)
silt = raster(voi_layer3)
ph = raster(voi_layer4)
org_carb = raster(voi_layer5)