General functions for R