Is there a way to distinguish between 1
and c(1)
? Apparently in R
c(1) == 1 # TRUE
as.matrix(c(1)) == 1 # TRUE
as.array(c(1)) == 1 # TRUE
which is a problem, for example, if I'm converting a vector to JSON:
library(rjson)
toJSON(c(1,2)) # "[1,2]"
toJSON(c(1)) # "1" instead of "[1]"
Any ideas?