Re: [R] source() behavior I don't understand

From: jim holtman <jholtman_at_gmail.com>
Date: Sun, 09 Mar 2008 21:14:15 -0500

Put 'print' around your variable:

> temp.ttt <- "ttt <- 1\nprint(ttt)"
> conn.ttt <- textConnection(temp.ttt)
> source(conn.ttt, echo=TRUE) ## name of variable is echoed

> ttt <- 1

> print(ttt)

[1] 1
> close(conn.ttt)
> cat(file="c:/temp/temp.R", temp.ttt) ## name of variable not echoed
> source("c:/temp/temp.R", echo=TRUE)

> ttt <- 1

> print(ttt)

[1] 1
>
>
> temp.abc <- "abc <- 1\nprint(abc)"
> conn.abc <- textConnection(temp.abc)
> source(conn.abc, echo=TRUE) ## name of variable is echoed

> abc <- 1

> print(abc)

[1] 1
> close(conn.abc)
> cat(file="c:/temp/temp.R", temp.abc) ## name of variable is echoed
> source("c:/temp/temp.R", echo=TRUE)

> abc <- 1

> print(abc)

[1] 1
>

On Sun, Mar 9, 2008 at 9:01 PM, Richard M. Heiberger <rmh_at_temple.edu> wrote:
> temp.ttt <- "ttt <- 1\nttt"
> conn.ttt <- textConnection(temp.ttt)
> source(conn.ttt, echo=TRUE) ## name of variable is echoed
> close(conn.ttt)
> cat(file="c:/temp/temp.R", temp.ttt) ## name of variable not echoed
> source("c:/temp/temp.R", echo=TRUE)
>
>
> temp.abc <- "abc <- 1\nabc"
> conn.abc <- textConnection(temp.abc)
> source(conn.abc, echo=TRUE) ## name of variable is echoed
> close(conn.abc)
> cat(file="c:/temp/temp.R", temp.abc) ## name of variable is echoed
> source("c:/temp/temp.R", echo=TRUE)
>
>
> The behavior I don't understand is why the variable name "ttt" is not echoed
> when sourced from a file. It is echoed when sourced from a character string.
> The name is echoed in both situations when it begins with a letter other
> than "t". Specifically I have tested "tt" and "ttt".
>
> I am using R-2.6.1 on Windows.
>
> Rich
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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.
Received on Mon 10 Mar 2008 - 02:17:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Mar 2008 - 03:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive