How does one \"throw\" an error in R? I have a function that takes a data frame and some column names and does stuff with them. If the columns don\'t exist, I want the fun
You can check if the column exists and do whatever your want. Suppose a data.frame named df1 and checking if column col1 exists:
data.frame
df1
col1
if(! any(grepl('^col1$',colnames(df1)))) stop("nonexistent column")
or
if(! any(grepl('^col1$',colnames(df1)))) return(-1)
For instance