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
View Answer

Answer: a
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.

advertisement
advertisement

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

Answer: a
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

Answer: b
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
View Answer

Answer: a
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.
advertisement

5. What will be the output of the following R code?

advertisement
> 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

Answer: a
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

Answer: a
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

Answer: a
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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.