inspect <- function(stuff){
q <- as.character(match.call()[2])
if (length(stuff)==1 && !is.data.frame(stuff)) ##not a proper vector / matrix / complex object
jCat(q, " = ", stuff)
else
jCat(q, " = "); print(stuff)
}
> inspect(nv) ## calls jCat to print everything in one line
nv = 14
> inspect(ranking)
ranking =
[1] "A1~C4" "C5~C6" "B1~C2" "A1~A3" "A2~A3" "B1~B4" "C3~C6" "C2~C5" "A1~C2"
[10] "B3~C6" "B1~C6"
> inspect(nv+5)
nv + 5 = 19
The obvious drawback is the need to write quotes around the expression, so I'm wondering if we can define macros in R in the style of Common Lisp's defmacro, i.e. something that will stop evaluation. Thanks
serapio!
deparse + quote
Date: 2010-05-26 08:04 am (UTC)(no subject)
Date: 2010-05-26 08:11 am (UTC)(no subject)
Date: 2010-05-26 08:59 am (UTC)expr = as.character(match.call())[2]
(no subject)
Date: 2010-05-26 09:34 am (UTC)(no subject)
Date: 2010-05-26 09:48 am (UTC)'expr' should refer to 'q', if anything.
(no subject)
Date: 2010-05-26 09:51 am (UTC)