handle different return types in R