Someone who has experience with R in Qgis can help me with this problem. I have a script that works perfectly in R making downloads SRTM DEM and cuts to the desired polygon. But I can't implement it in qgis.
library(sf)
library(raster)
library(elevatr)
library(viridis)
library(tidyverse)
library(sp)
library(rgdal)
setwd("D:/teste_MDT/1")
pol_mask <- readOGR(dsn = "D:/teste_MDT/1", layer = "2")
#crs(pol_mask) <- "+proj=longlat +datum=WGS84"
plot(pol_mask)
dem <- get_elev_raster(pol_mask, z = 11, override_size_check = TRUE)
plot(dem)
writeRaster(dem, filename= "dem.tif")
crop_dem <- mask(x= crop(dem, pol_mask), pol_mask, filename = "crop.tif")
plot(crop_dem)