What is the as.name() function in R?

Overview

The as.name() function in R converts a given R object into a name class object.

The name class object has the class "name". class(name_object) returns the name of the class from which the R object is inherited.

Syntax

as.name(value)

Parameter value

The as.name() function takes the parameter value, value, which represents the R object.

Return value

The as.name() function returns a name class object.

Code example

# creating an R object
number <- 123
# printing the value stored in number
number
# calling the as.name() function
name_object = as.name(number)
# printing the name class object
name_object
# checking if its a name class object
is.name(name_object)
# checking the class
class(name_object)

Code explanation

  • Line 2: We create a variable number.
  • Line 5: We print the value stored in variable number.
  • Line 8: We implement the as.name() function on the number variable. The result is assigned to a variable name_object.
  • Line 11: We print the variable name_object.
  • Line 14: We use the is.name() function and check if the variable, name_object is a name class object.
  • Line 17: We use the class() function we returned the class of the object name_object.