From ggrothendieck at gmail.com  Fri Jul 13 04:02:15 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 12 Jul 2007 22:02:15 -0400
Subject: [Rd] parse(text=...) and the srcfile attribute
In-Reply-To: <eb555e660707121852x13817360t5def7f645632e86@mail.gmail.com>
References: <eb555e660707121852x13817360t5def7f645632e86@mail.gmail.com>
Message-ID: <971536df0707121902t44b214e5r212da62fba7688a@mail.gmail.com>

You can do this:

> foo at srcfile$lines
[1] "\na <- 1; b <- 2**2\na + b\n"

> # or this
> as.character(foo)
[1] "a <- 1"   "b <- 2^2" "a + b"

On 7/12/07, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
> Hi,
>
> I'm trying to understand whether the new source file references can
> help me with something I want to do. Let's say I have
>
> foo <- parse(text = "
> a <- 1; b <- 2**2
> a + b
> ")
>
> I now wish to recover the sources for the parsed expressions. I can
> get them one at a time:
>
> > foo[[2]]
> b <- 2^2
> > as.character(attr(foo, "srcref")[[2]])
> [1] "b <- 2**2"
>
> Is there a better way? Perhaps like the print method
>
> > as.character(foo, useSource = TRUE)
>
> could give all the sources at once?
>
> -Deepayan
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] parse(text=...) and the srcfile attribute
Gabor Grothendieck