Check if an Object of the Specified Name is Defined or not in R Programming - exists() Function Last Updated : 17 Apr, 2025 Comments Improve Suggest changes Like Article Like Report exists() function in R Programming Language is used to check if an object with the names specified in the argument of the function is defined or not. It returns TRUE if the object is found.Syntax: exists(name)Parameters: name: Name of the Object to be searchedExample 1: Apply exists() Function to variableIn this example, we will use the exists() function to check if various objects are defined R # Calling exists() function exists("cos") exists("diff") exists("Hello") Output[1] TRUE [1] TRUE [1] FALSE In the output, the exists() function returns TRUE for predefined functions like cos and diff, while it returns FALSE for Hello, as it hasn't been defined yet.Example 2: Checking for User-defined Objects (Vectors)We will declare a vector and see if it exists or not using the exists() function. R # Creating a vector Hello <- c(1, 2, 3, 4, 5) # Calling exists() function exists("Hello") Output[1] TRUE Here, when defining the vector Hello, the exists() function gives TRUE, which verifies that the object has been defined.Example 3: Checking if a Variable Exists in a Data FrameYou can also verify whether a variable exists in a data frame or any other R object using exists(). R # creating a data frame friend.data <- data.frame( friend_id = c(1:5), friend_name = c("Sachin", "Sourav", "Dravid", "Sehwag", "Dhoni"), stringsAsFactors = FALSE ) print(friend.data) attach(friend.data) exists('friend_id') Output friend_id friend_name 1 1 Sachin 2 2 Sourav 3 3 Dravid 4 4 Sehwag 5 5 Dhoni [1] TRUE In this example, exists('friend_id') returns TRUE because the variable friend_id is part of the friend.data data frame.Example 4: Conditional Check for Object ExistenceThe exists() function in R can be used to check if an object with a specified name exists in the current environment or not. The example of how to use the exists() function. R x <- 6 # Check if an object 'x' exists if (exists("x")) { print("Object 'x' exists!") } else { print("Object 'x' does not exist!") } # Check if an object 'y' exists if (exists("y")) { print("Object 'y' exists!") } else { print("Object 'y' does not exist!") } Output[1] "Object 'x' exists!" [1] "Object 'y' does not exist!" Related Article:R Programming Language – Introduction Comment More infoAdvertise with us Next Article Check if an Object of the Specified Name is Defined or not in R Programming - exists() Function N nidhi_biet Follow Improve Article Tags : R Language R Vector-Function R Object-Function R Matrix-Function R List-Function +1 More Similar Reads Check if an Object is sorted or not in R Programming - is.unsorted() Function is.unsorted() function in R Language is used to check if an object is sorted or not. It returns False if the object is sorted otherwise True. Syntax: is.unsorted(x) Parameters: x: Object Example 1: Python3 1== # R Program to check if # an object is sorted # Creating a vector x <- c(1:9) # Creatin 1 min read Check if an Object is of Type Numeric in R Programming - is.numeric() Function is.numeric() function in R Language is used to check if the object passed to it as argument is of numeric type. Syntax: is.numeric(x) Parameters: x: Object to be checked Example 1: Python3 # R program to check if # object is of numeric type # Calling is.numeric() function is.numeric(1) is.numeric(1. 1 min read Get or Set names of Elements of an Object in R Programming - names() Function names() function in R Language is used to get or set the name of an Object. This function takes object i.e. vector, matrix or data frame as argument along with the value that is to be assigned as name to the object. The length of the value vector passed must be exactly equal to the length of the obj 2 min read Check if an Object is of Complex Data Type in R Programming - is.complex() Function is.complex() function in R Language is used to check if the object passed to it as argument is of complex data type. Syntax: is.complex(x) Parameters: x: Object to be checked Example 1: Python3 # R program to check if # object is of complex type # Calling is.complex() function is.complex(1 + 0i) is. 1 min read Check if the Object is a Data Frame in R Programming - is.data.frame() Function is.data.frame() function in R Language is used to return TRUE if the specified data type is a data frame else return FALSE. R data.frame is a powerful data type, especially when processing table (.csv). It can store the data as row and columns according to the table. Syntax: is.data.frame(x) Paramet 1 min read Check if the Object is a List in R Programming - is.list() Function is.list() function in R Language is used to return TRUE if the specified data is in the form of list, else returns FALSE. Syntax: is.list(X) Parameters: x: different types of data storage Example 1: Python3 # R program to illustrate # is.list function # Initializing some list a <- list(1, 2, 3) b 1 min read Check if an Object is an Expression in R Programming - is.expression() Function is.expression() function in R Language is used to check if the object passed to it as argument is of the expression class. Syntax: is.expression(object) Parameters: object: Object to be checked Example 1: Python3 1== # R program to check if # an object is an expression # Creating an object x <- 1 min read Return an Object with the specified name in R Programming - get0() and mget() Function In R programming, get0() and mget() function works similar to get() function. It is used to search and return the object with the specified name passed to it as argument. get0() Function get0() function has the same syntax as get() function but there is an addition of a new parameter which returns a 2 min read Check if an Object is of Type Integer in R Programming - is.integer() Function is.integer() function in R Language is used to check if the object passed to it as argument is of integer type. Syntax: is.integer(x) Parameters: x: Object to be checked Example 1: Python3 1== # R program to check if # object is an integer # Creating a vector x1 <- 4L x2 <- c(1:6) x3 <- c( 1 min read Check if the Object is a Matrix in R Programming - is.matrix() Function is.matrix() function in R Language is used to return TRUE if the specified data is in the form of matrix else return FALSE. Syntax: is.matrix(x) Parameters: x: specified matrix Example 1: Python3 # R program to illustrate # is.matrix function # Specifying some different types of arrays A <- matri 1 min read Like