```r
## Write out the raster in saga format first.
writeRaster(dtm,"rasters/arne/saga_dtm.sgrd",format="SAGA", overwrite=TRUE)

## Run the commands (WILL ONLY WORK IF THE LIBRARIES ARE INSTALLED) 

system ("saga_cmd ta_lighting 2 -GRD_DEM 
        rasters/arne/saga_dtm.sgrd  -DAY '13/10/19' -GRD_DIRECT    rasters/arne/saga_sol")
system ("saga_cmd ta_hydrology 15 -DEM 
        rasters/arne/saga_dtm.sgrd  -TWI   rasters/arne/saga_TWI")

## Read the results back to R

sol<-raster("rasters/arne/saga_sol.sdat")
twi<-raster("rasters/arne/saga_TWI.sdat")

## Re set the coordinate reference systems (which get lost in the process of translation to SAGA and back)
sol@crs<-dtm@crs
twi@crs<-dtm@crs

## Write out the results 
writeRaster(sol,"rasters/arne/insol_oct.tif",format="GTiff", overwrite=TRUE)
writeRaster(twi,"rasters/arne/twi.tif",format="GTiff", overwrite=TRUE)

## Remove the intermediate SAGA files
system("rm rasters/arne/saga*")
```