# Predicate functions [program]

(Builds on: Function basics)

Predicate functions are functions that return a single `TRUE` or `FALSE`. You use predicate functions to check if your input meets some condition. For example, `is.character()` is a predicate function that returns `TRUE` if its input is of type character and `FALSE` otherwise.

``````is.character("a")
``````
``````##  TRUE
``````
``````is.character(4.5)
``````
``````##  FALSE
``````

R does not have scalars. `"a"` is actually a character vector of length 1. `is.character()` and similar functions return a single value for all vectors, whether they have 1 element or many.

``````x <- c("a", "b")
is.character(x)
``````
``````##  TRUE
``````

In atomic vectors like `x`, all the elements must be the same type. The type of the individual elements will always be the same as the type of the atomic vector. You can use the function `typeof()` to find the type of a vector (or any other object in R).

``````typeof(x)
``````
``````##  "character"
``````

`is.character()` simply checks whether `x` is of type character.

If the vector is not a character vector, `is.character()` will return `FALSE`.

``````y <- c(1, 3)
typeof(y)
``````
``````##  "double"
``````
``````is.character(y)
``````
``````##  FALSE
``````

Lists can have elements of any type. Even if all the elements of a list are of type character, the list is not a character vector, and `is.character()` will return `FALSE`.

``````z <- list("a", "b")
typeof(z)
``````
``````##  "list"
``````
``````is.character(z)
``````
``````##  FALSE
``````