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

Kuhn, Alexandre (NIH/NIA/IRP) [V] kuhnam at mail.nih.gov
Tue Apr 13 01:14:02 CEST 2010


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
#comment 2

R will echo

> #comment 1
> a<-1

What is the solution to have R echo all of the comment lines?

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)?

Thank you,
Alexandre Kuhn

> sessionInfo()
R version 2.10.1 (2009-12-14) 

[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 

More information about the R-help mailing list