[R] source(echo=TRUE) bug (was: source() behavior I don't understand)

Duncan Murdoch murdoch at stats.uwo.ca
Mon Mar 10 04:44:48 CET 2008


Richard M. Heiberger wrote:
> Duncan,
>
> I would like an option for all comments and blanks to be echoed.  The
> reason is that I am designing a mechanism for connecting ESS to Rgui
> using source().  It works for me now, but is not smooth enough to post
> until I do a little bit more work on it.  Therefore I want an option
> for the R Console to display all the lines in my source() code.  When
> the seven lines below are sourced, only lines 1,2,4,5,6 are echoed.
> Lines 3 and 7 are not echoed.  This means that well-commented user
> source code will not have complete comments in the output transcript
> in the Console.
>   
source() is pure R code, so if you want a function that behaves 
differently, you can do it fairly easily yourself.
It's basically just a function to parse some source and then evaluate it 
one expression at a time.  No need for all the bells and whistles it has 
if you are in complete control of the input and don't want to offer 
options on the output.  A version that does what you need to do is 
probably just 10 or 20 lines.

Duncan Murdoch
> ## comment 1
> 123
>
> ## comment 4
>
> 456
> ## comment 7
>
>
> What I would also like, but I believe would be much harder for you
> to provide, is a way to get individual lines sent from ESS into the
> same place that lines that are manually typed go.  The reason is that
> multi-line commands, such as 
>
> 2+
>   3
>
> cannot currently be sent one line at a time (using ESS C-c C-n) to
> Rgui.  They can be sent to any other R or S-Plus process one line at a
> time.  I would like the same capability for the Rgui Console.  The
> plan that I am developing now can send multiple lines over, either by
> highlighting them and using C-c C-r, or by surrounding them with blank
> lines and using C-c C-c.
>
>
> Rich
>
> -----Original Message-----
> From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] 
> Sent: Sunday, March 09, 2008 10:52 PM
> To: Richard M. Heiberger
> Cc: r-help at r-project.org
> Subject: Re: [R] source(echo=TRUE) bug (was: source() behavior I don't
> understand)
>
> On 09/03/2008 10:40 PM, Richard M. Heiberger wrote:
>   
>> Thanks Duncan,
>>
>> While there, can you give a new optional argument that
>> will permit the echo of blanks and comments?
>>     
>
> Comments are already echoed, leading blank lines are not (but blanks in 
> comments are).  For example:
>
>  > temp.ttt <- "ttt <- 1\n\n# comment\n\nttt"
>  > cat(file="c:/temp/temp.R", temp.ttt)
>  > source("c:/temp/temp.R", echo=TRUE)
>
>  > ttt <- 1
>
>  > # comment
>  >
>  > ttt
> [1] 1
>
> (I ran this in the patched version, but I believe the behaviour would be 
> the same in the release as well.)
>
> I forget exactly why I chose to suppress leading blanks, but the 
> workaround of commenting the first of them is so easy, I don't think 
> it's worth the trouble to add an extra option.
>
> Duncan
>



More information about the R-help mailing list