This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Debugging”.
1. What will be the output of the following R expression?
> log(-2.3)
a) Warning in log(-2.3): NaNs produced
b) 1
c) Null
d) 0
View Answer
Explanation: This warning lets you know that taking the log of a negative number results in a NaN value because you can’t take the log of negative numbers.
2. Point out the correct statement?
a) Vectorizing the function can be accomplished easily with the Vectorize() function
b) There are different levels of indication that can be used, ranging from mere notification to fatal error
c) Vectorizing the function can be accomplished easily with the vector() function
d) Warnings are generated by the run() function
View Answer
Explanation: Vectorize() function does not preserve the invisibility of the return value.
3. What will be the value of following R expression?
a) Warning in log(c(-1, 2)): NaNs produced
b) Error in log(c(-1, 2)): NaNs produced
c) Message
d) All of the mentioned
View Answer
Explanation: Warning is produced due to negative values.
4. What will be the output of the following R code?
> printmessage2 <- function(x) { + if(is.na(x)) + print("x is a missing value!") + else if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage2(NA)
a) “x is a missing value!”
b) “x is greater than zero”
c) “x is less than or equal to zero”
d) Error
View Answer
Explanation: We can fix Missing value problem by anticipating the possibility of NA values and checking to see if the input is NA with the is.na() function.
5. What will be the output of the following R code?
> printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(NA)
a) Error
b) Warning
c) Messages
d) x is greater than zero
View Answer
Explanation: You can’t do that test if x is a NA or NaN value.
6. What will be the output of the following R code?
> mean(x) Error in mean(x) : object 'x' not found > traceback()
a) 1: mean(x)
b) Null
c) 0
d) 2
View Answer
Explanation: The traceback() function shows you how many levels deep you were when the error occurred.
7. The recover() function will first print out the function call stack when an _______ occurs.
a) Error
b) Warning
c) Messages
d) delete
View Answer
Explanation: When you choose a frame number, you will be put in the browse and will have the ability to poke around.
Sanfoundry Global Education & Learning Series – R Programming Language.
Here’s the list of Best Books in R Programming Language.
- Check Information Technology Books
- Practice Programming MCQs
- Check R Programming Books
- Apply for Programming Internship