which.first / which.last moved to checkmate
replaced with temporary version in plain R