Section 9 Common Error Messages

9.1 Error messages

  • Error: could not find function

  • Error in if function: missing value where TRUE/FALSE is needed

  • Error: Error in eval; object not found

  • Error: cannot open the connection

  • Error: incorrect number of dimensions

  • Error: subscript out of bounds

  • Error: undefined columns selected

  • Error: non-numeric argument to a binary operator

  • Error: no applicable method - caused by using an object-oriented function on a data type it does not support


9.2 Error messages from R

  • Check if the following R codes run without any warning or error messages

  • Understand the warning and error messages that R displays

9.3 Example 1

rm(list = ls())

f <- function(x){
    if(as.numeric(x) > 0) print("Positive") else print("Negative")
}


f(5)


f('A')

sum(a)

f()

f.(5)

9.4 Example 2

rm(list = ls())

x <- c(1:5)
x[2,]

9.5 Example 3

rm(list = ls())


DF <- data.frame(A=1:5, B=letters[1:5])
sum(DF[,3])

9.6 Example 4

rm(list = ls())

x <- c(1:5)
y <- c(2,3)

x; y

x > y

x + y

if(x > y) 1 else 0

9.7 Example 5

rm(list = ls())

mean(letters[1:5])

3 + a

5 + 'one'