The SRTM digital elevation model (DEM) for Germany was retrieved from OPENDEM on June 25, 2017. Please note that the zipped file is about 86.4 MB in size.

## build a temporary folder on disk
temp <- tempfile()
download.url <- ""
zipfile <- ""
## download the file
download.file(paste0(download.url,zipfile),temp, mode = "wb")
## unzip the file

To load the raster data set we apply the raster() function.

## read in the data 
srtm.germany <- raster('srtm_germany_dtm.tif')

When working with large data sets it is recommendable to check the size of the file in advance. The processing time increases with the size of the data set.

fs <- file.size('srtm_germany_dtm.tif')
print(paste("The file size is", as.numeric(fs)/1e6, "MB"))
## [1] "The file size is 285.254776 MB"

Owing to the large file size we downscale the raster data set using he aggregate() function. The aggregate() function performs aggregation by grouping adjacent pixels into new ones, given an input raster and the aggregation factor fact. In addition the aggregate() function accepts the fun argument, which specifies the function that will be used to calculate the new values based on existing ones (the default is mean). Here we set fact = 20. Depending on your computing resources this step may take some time.

srtm.germany <- aggregate(srtm.germany,
                          fact = 20, 
                          fun = mean)