Skip to content
Back to formatted view

Raw Message

Message-ID: <1114645753.650.70.camel@horizons.localdomain>
Date: 2005-04-27T23:49:13Z
From: Marc Schwartz
Subject: Getting the name of an object as character
In-Reply-To: <BAY17-F281703DCA9942A7F4980B1D1220@phx.gbl>

On Wed, 2005-04-27 at 23:03 +0000, Ali - wrote:
> This could be really trivial, but I cannot find the right function to get 
> the name of an object as a character.
> 
> Assume we have a function like:
> 
> getName <- function(obj)
> 
> Now if we call the function like:
> 
> getName(blabla)
> 
> and 'blabla' is not a defined object, I want getName to return "blabla". In 
> other word, if
> 
> paste("blabla")
> 
> returns
> 
> "blabla"
> 
> I want to define a paste function which returns the same character by:
> 
> paste(blabla)

Do you mean:

> exists("plot.default")
[1] TRUE
> deparse(substitute(plot.default))
[1] "plot.default"

> exists("MyPlot.Default")
[1] FALSE
> deparse(substitute(MyPlot.Default))
[1] "MyPlot.Default"

> x <- 1:10
> x
 [1]  1  2  3  4  5  6  7  8  9 10
> deparse(substitute(x))
[1] "x"

Does that get what you want?

If so, see ?deparse and ?substitute

HTH,

Marc Schwartz