Now using asLogical(x) instead of LOGICAL(x)[0] everywhere. Same with asInteger(x).