I have two dem files downloaded via the getData function in the raster package. Here you can see the code:

I tried to make the example reproducible so there you have it.


While attempting to perform the merge, the following error appears:

Error in compareRaster(x, extent = FALSE, rowcol = FALSE, orig = TRUE,  : 
  different origin

2 Answers 2


This works as expected for me:

> demALL
class       : RasterLayer 
dimensions  : 6000, 12000, 7.2e+07  (nrow, ncol, ncell)
resolution  : 0.0008333333, 0.0008333333  (x, y)
extent      : 25, 35, 40, 45  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : c:\Temp\R_raster_rhijmans\r_tmp_2015-10-22_102651_340_06019.grd 
names       : layer 
values      : -37, 2573  (min, max)

However, there is a small difference in the origin due to floating-point imprecision

 #[1] 0 0
 #[1] -3.552714e-15  0.000000e+00

but that should not matter

So I wonder if you are using the current versions of R and raster? If you are, you could probably get around this by setting

 rasterOptions(tolerance = 0.1)

(That is actually the default value) or perhaps

.Machine$double.eps <- 0.000000001

or something like that

  • There is no problem during the merge for you?
    – gsa
    Oct 22, 2015 at 17:49
  • It works fine for me. That is why I wonder about the package version you are using Oct 22, 2015 at 18:59
  • It was the outdated R version after all.Nice.
    – gsa
    Oct 22, 2015 at 19:03

I faced a similar issue with other raster files even when using the most recent version of R and the raster package. The above did not work for me. Instead, by trying

mergedraster <- raster::merge(raster1, raster2, tolerance = 0.1)

worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.