Suppose I have a Null vector and Null List -
ot_vec = c()
msg_lst = list()
Further, suppose I have many user-defined functions. Now I want to use a tryCatch to append the outputs of the user-defined functions in the Null list and the messages from tryCatch in the Null vector one by one without printing the outputs and messages from tryCatch.
For e.g., if I define two user-defined functions for Square_Calculator and SquareRoot_Calculator using tryCatch, after running the following lines of code No outputs or error messages should be given directly here -
The outputs and error or warning messages should be appended in the Null List and Null Vector i.e., that list and vector should now take the following form -

I was trying something like that -
Though it is appending the output and error message to the ot_list and msg_vec within the function, it is not appending to the original Null List and Null Vector we have created a the very beginning.


I believe the following will work. It may be possible to vectorize, but I will use a loop for the
tryCatch. Also, it's set up to allow alistas input, as a list can have different data types within it. The example will be for square root, which returns an error on non-numeric and a warning on negative numbers. It will append to passed lists/vectors.Now to test: