fn_Mean=function(x, ...){tryCatch( expr ={fn_n=function(x, na.rm=FALSE)ifelse(na.rm, length(na.omit(x)), length(x))n=fn_n(x, ...)AM=mean(x, ...)GM=exp(mean(log(x), ...))HM=1/mean(1/x, ...)Mean=list(n =n, AM =AM, GM =GM, HM =HM)return(Mean)}, error =function(e){cat('\n An error has occurred! The error message is below. \n')print(e)}, warning =function(w){cat('\n A warning has occurred! The warning message is below. \n')print(w)}, finally ={cat('\n Completed the fn_Mean run! \n')})}
A warning has occurred! The warning message is below.
<simpleWarning in mean.default(x, ...): argument is not numeric or logical: returning NA>
Completed the fn_Mean run!
25.9 Call 8: Error
Code
fn_Mean(J, na.rm =TRUE)
An error has occurred! The error message is below.
<simpleError in na.omit(x): object 'J' not found>
Completed the fn_Mean run!