r - How to make reshape2::acast throw an error upon variable aggregation? -


> df = data.frame(expand.grid(letters[1:3], letters[4:5])[-3,], value=1:5) > dfa = rbind(df, c("a","d",6)) > df   var1 var2 value 1       d     1 2    b    d     2 4       e     3 5    b    e     4 6    c    e     5 > dfa    var1 var2 value 1        d     1 2     b    d     2 4        e     3 5     b    e     4 6     c    e     5 61       d     6 

the following works expected:

> reshape2::acast(df, var1~var2, value.var="value")    d e  1 3 b  2 4 c na 5 

for case aggregation performed, prefer function call throw error instead of writing message:

> reshape2::acast(dfa, var1~var2, value.var="value") aggregation function missing: defaulting length   d e 2 1 b 1 1 c 0 1 

how wrap 2nd call throw error instead of displaying message?

i've tried combinations of capture.output() , sink(), i'd have result of call in result variable.

messages part of condition system in r, , can handled using appropriate functions. consequence, works:

withcallinghandlers(reshape2::acast(df, var1~var2, value.var="value"),                     message = stop) 

incidentally, reason prefer using warning , message on cat such things.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -