2

I am using sp::merge to merge SpatialPologynDataFrame with data.frame:

z <- merge(x, y, by.x = "field1", by.y = "field2") 

merge() annoys me with Warning message: In .local(x, y, ...) : 12 records in y cannot be matched to x, which I am very well aware of. How to make him quiet? I did try to put all.y = FALSE. It would feel kinda stupid to have to pre-filter y to only those who match to x. This is what merge is supposed to do, just without kidding :-)

PS: I didn't ask for global warning suppression, just how to disable in this function.

PS 2: I still don't understand why sp::merge() warns about this, when base::merge() doesn't!:

z <- merge(x@data, y, by.x = "field1", by.y = "field2") 
# spatial info dropped, base::merge() called, no warning now
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • You can wrap the call to `merge` in `suppressWarnings` to get rid of the warnings for just the call to `merge`. – Paul Hiemstra Jul 18 '16 at 13:38
  • I understand your frustration, and voted to reopen the question. But using so many exclamation marks makes it look like you are screaming in our faces :). – Paul Hiemstra Jul 18 '16 at 13:40
  • thanks @PaulHiemstra, I was screaming actually, and I am glad and honestly very nicely surprised it got reopened again. I suggest to cleanup this conversation now as the original reason disappeared. – Tomas Jul 18 '16 at 15:48

1 Answers1

4

Just run this line on top of your script options(warn=-1). To turn back on set warn = 0 . I read this here on SO but couldn't actually find the link so posting the answer. But note this will switch off the warnings globally .

For single line you can use suppressWarnings(yourcode). Hope this helps .

Pankaj Kaundal
  • 1,012
  • 3
  • 13
  • 25
  • My original question is how to disable this particular warning only. Thanks a lot though, this might come in handy as the last resort... – Tomas Jul 18 '16 at 13:10
  • +1, I would reverse the solutions, and put the `supressWarnings` first. This solves the problem of the OP. – Paul Hiemstra Jul 18 '16 at 13:39
  • @PaulHiemstra, well, I'd say it is a very nice hack rather than a proper solution, which would be to persuade merge to not warn about *this* - since merge might issue different, possibly useful warnings as well, which you miss using this hack. I know I am perfectionist though. sp::merge() shouldn't warn or it should possibly be lower priority message than warning if that exists in R. I still don't understand why sp::merge() warns about this, when merge() doesn't! – Tomas Jul 18 '16 at 15:51
  • Merge is a generic function with a very different set of code for spatial objects than for say data.frames. This explains why the merge on data.frames does not show a particular warning. – Paul Hiemstra Jul 18 '16 at 16:44
  • @PaulHiemstra well it's quite clear why base::merge doesn't show that warning.. and the argument is that sp::merge shoudln't have it for the exactly same reason – Tomas Jul 19 '16 at 08:37