Spatial interpolation in R gstat without the message

891 views Asked by At

When I'm doing interpolation in R using gstat package, the message like this '[inverse distance weighted interpolation]' or this '[ordinary or weighted least squares prediction] ' occurs. Eg:

library('sp')
library('gstat')
data(meuse)
coordinates(meuse) = ~x + y 
data(meuse.grid)
coordinates(meuse.grid) = ~x + y 
gridded(meuse.grid) <- TRUE
zn.tr1 <- krige(log(zinc) ~  x + y , meuse, meuse.grid)

[ordinary or weighted least squares prediction]

How to disable that message?

2

There are 2 answers

0
Spacedman On BEST ANSWER

Various ways exist of stopping output - the nicest being if the function has an option to suppress it. But krige doesn't seem to have that.

capture.output works here:

> rm(zn.tr1)
> zn.tr1 # there is no zn.tr1
Error: object 'zn.tr1' not found
> z = capture.output(zn.tr1 <- krige(log(zinc) ~  x + y , meuse, meuse.grid))
> str(zn.tr1) # there is now
Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots
  ..@ data       :'data.frame': 3103 obs. of  2 variables:
  .. ..$ var1.pred: num [1:3103] 6.16 6.18 6.14 6.1 6.19 ...

The output message itself is returned and stored in z

> z
[1] "[ordinary or weighted least squares prediction]"

But if you don't print it you won't see it.

0
Edzer Pebesma On

Or set the debug level just one below default:

zn.tr1 <- krige(log(zinc) ~  x + y , meuse, meuse.grid, debug.level = 0)