# R Programming Questions and Answers – Debugging

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

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

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

Explanation: Warning is produced due to negative values.

Note: Join free Sanfoundry classes at Telegram or Youtube

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

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

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

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

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.

To practice all areas of R Programming Language, Here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]