Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert variable (object) name into String [duplicate]

Tags:

string

object

r

People also ask

How do I turn a variable into a string?

Converting Numbers to Strings We can convert numbers to strings through using the str() method. We'll pass either a number or a variable into the parentheses of the method and then that numeric value will be converted into a string value.

How do I convert a variable to a string in R?

To convert elements of a Vector to Strings in R, use the toString() function. The toString() is an inbuilt R function used to produce a single character string describing an R object.

Can you convert a variable name to a string in Python?

This is not possible. In Python, there really isn't any such thing as a "variable".

How do I extract a variable name in R?

There are two ways to extract information from objects in R, using subsetting and using the "$" operator. Below, we summarize the Age vector and store the results in sum. vec. We print out the sum.


You can use deparse and substitute to get the name of a function argument:

myfunc <- function(v1) {
  deparse(substitute(v1))
}

myfunc(foo)
[1] "foo"