Exercise 17: Try Catch
Let's test your understanding of using try catch in R code.
We'll cover the following
Problem Statement
Implement a function calculateLog()
that takes a testVariable
and prints its log
. If the logarithmic value of the testVariable
is not possible, print “This operation is not allowed!”
Use the
cat()
function for printing!
Input
A testVariable
containing the data whose logarithmic value needs to be found.
Output
The correct output based on the testVariable
.
Sample Input
"a"
Sample Output
This operation is not allowed!
Test Yourself
Write your code in the given area. If you get stuck, you can look at the solution.
calculateLog <- function(testVariable){# Write your code herecat(" ")}
In the next lesson, we have a solution review of this exercise.