[R] source(,echo=T) doesn't echo final comments

Peter Ehlers ehlers at ucalgary.ca
Tue Apr 13 20:42:20 CEST 2010


On 2010-04-13 6:50, Duncan Murdoch wrote:
> On 12/04/2010 7:14 PM, Kuhn, Alexandre (NIH/NIA/IRP) [V] wrote:
>> Hi,
>>
>> source(file,echo=T) will not echo the last comment in "file" if it is
>> the last line in the file.
>> For instance, when sourcing a file containing the following lines
>>
>> #comment 1
>> a<-1
>> #comment 2
>>
>> R will echo
>>
>> > #comment 1
>> > a<-1
>>
>> What is the solution to have R echo all of the comment lines?
> I think the only current solution is to have all the comment lines ahead
> of code lines. R doesn't specifically echo the comments, it only echoes
> the code, but comments that happen to precede the end of the code line
> are echoed as part of that line.

It might be worthwhile making 'skip.echo = n' an error for any
negative n.

Funny things can happen; try these lines:

  #comment 1
  a <- 1
  #comment 2
  b <- 2
  #comment 3
  #comment 4
  d <- 3
  #comment 5

with

  source(file, echo = TRUE, skip.echo = -n)

for n %in% 1:7

  -Peter Ehlers

>> Specific context:
>> This problem arises e.g. in the context of help files (.Rd) whose
>> example section contains only code that is not to be run (\dontrun
>> markup). Running the function example() (that itself calls
>> source(,echo=TRUE)) on such a file will not display anything (because
>> the code is commented out in the corersponding files in R-ex). Is that
>> the desired behavior of example() or is there a workaround (i.e. to be
>> able write help files with only dontrun code but that will
>> nevertheless echo the examples)?
>>
> I'm not sure we really want to show all the \dontrun examples, but I'll
> look into this, because as documented, they should be shown. (My
> preference would be to completely hide the \dontrun lines in example(),
> but that's not what is documented to happen, and that's not what happens
> when they are followed by code.)
>
> Duncan Murdoch
>
>> Thank you,
>> Alexandre Kuhn
>>
>>
>>
>> > sessionInfo()
>> R version 2.10.1 (2009-12-14) i386-apple-darwin9.8.0
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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.
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list