[R] as.character(quote(x$y) ) = "$" "x" "y" not "x$y"?

Bert Gunter gunter.berton at gene.com
Fri May 9 05:05:41 CEST 2014


[1] "x$y"

Spencer:

Does

deparse(substitute(x$y))
[1] "x$y"

do what you want?

Cheers,
Bert






-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Thu, May 8, 2014 at 5:56 PM, Spencer Graves
<spencer.graves at structuremonitoring.com> wrote:
>           "as.character.call" seems not to work as an alias for deparse.
> Consider the following:
>
>
> xDy <- quote(x$y)
> class(xDy)
> "call"
> as.character.call <- function(x, ...)deparse(x, ...)
> as.character(xDy)
> [1] "$" "x" "y"
> # fails
>
> str(xDy)
> #  language x$y
> as.character.language <- function(x, ...)"language"
>
> as.character(xDy)
> [1] "$" "x" "y"
>
>
>           Is it feasible to construct a method for "as.character" that works
> for objects of class "call"?
>
>
>           Thanks,
>           Spencer
>
>
> #################
>
>
> Thanks for the quick replies from Richard Heiberger, Greg Show & Bert
> Gunter.
>
>
>       Might it make sense to create as.character.call as an alias for
> deparse?
>
>
>       A few years ago, I wrote several functions like "predict.fd" as
> aliases for functions with less memorable names like "eval.fd".  Doing that
> made the "fda" package easier to use, at least for me ;-)
>
>
>       Thanks again,
>       Spencer
>
>
> On 5/7/2014 2:39 PM, Bert Gunter wrote:
>>
>> ... and
>>
>>> str(quote(x$y))
>>
>>   language x$y
>>
>>> as.list(quote(x$y))
>>
>> [[1]]
>> `$`
>>
>> [[2]]
>> x
>>
>> [[3]]
>> y
>>
>> ## may be instructive.
>>
>> Cheers,
>> Bert
>>
>>
>>
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>> (650) 467-7374
>>
>> "Data is not information. Information is not knowledge. And knowledge
>> is certainly not wisdom."
>> H. Gilbert Welch
>>
>>
>>
>>
>> On Wed, May 7, 2014 at 2:30 PM, Greg Snow <538280 at gmail.com> wrote:
>>>>
>>>> deparse(quote(x$y))
>>>
>>> [1] "x$y"
>>>
>>> It looks like deparse does what you want here.
>>>
>>> On Wed, May 7, 2014 at 3:23 PM, Spencer Graves
>>> <spencer.graves at structuremonitoring.com> wrote:
>>>>
>>>> Hello, All:
>>>>
>>>>
>>>>        Is there a simple utility someplace to convert "quote(x$y)" to
>>>> "x$y"?
>>>>
>>>>
>>>>        I ask, because as.character(quote(x$y)) is a character vector of
>>>> length 3 =  "$" "x" "y".  I want to convert this to "x$y" for a
>>>> diagnostic
>>>> message.
>>>>
>>>>
>>>>        class(quote(x$y)) = "call", which suggests I could write
>>>> "as.character.call" to perform this function.  However, before I do, I
>>>> felt
>>>> a need to ask for other thoughts on this.
>>>>
>>>>
>>>>        Thanks,
>>>>        Spencer
>>>>
>>>>
>>>>
>>>> --
>>>> Gregory (Greg) L. Snow Ph.D.
>>>> 538280 at gmail.com
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list