R: as_ids function