I am basic in R and this code should be working although I get an error on this part of the code. Although I tried adding a "simple" method it seems not to solve the issue
library(terra)
# create SpatRast for all SM files
imgSM <- rast(sub("NDVI_cropped.tif","SM_cropped.tif",files))
xy <- cbind(x,y)
valNDVI <- extract(img, xy)0.0001 # extract and convert DN to NDVI
#Error: unexpected numeric constant in "valNDVI <- extract(img, xy)0.0001"
valSM <- extract(imgSM, xy) # extract SM
#Error in UseMethod("extract") :
# no applicable method for 'extract' applied to an object of class "SpatRaster"