[R] convert expressions to characters

David Winsemius dwinsemius at comcast.net
Wed Jan 5 23:07:48 CET 2011


On Jan 5, 2011, at 4:47 PM, Yihui Xie wrote:

> Hi,
>
> Suppose I have
>
> x = parse(text = "
> {y=50+50+50#'asfasf'
> }
> ")
>
> now x is an expression with some src attributes.
>
>> x
> expression({y=50+50+50#'asfasf'
> })
> attr(,"srcfile")
> <text>
> attr(,"wholeSrcref")
>
> {y=50+50+50#'asfasf'
> }
>
> My question is, how can I get my string back (the string passed to
> parse() as the text argument)?

 > attr(x, "wholeSrcref")

{y=50+50+50#'asfasf'
}

-- 
David.

>
>> as.character(x)
> [1] "{"
>
> as.character() only returns "{".
>
>> as.character(expression({1}))
> [1] "{"
>> as.character(expression("1","2+3"))
> [1] "1"   "2+3"
>
>
> Thanks a lot!
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list