Add check for NULL when building R matrix output.