On 12-02-13 6:02 PM, Cleridy Lennert wrote:
Dear All -
The problem: comment lines in an R function (lines beginning with # ) are
*sometimes* removed on leaving the R default editor (same with notepad).
I'm working on a Windows machine with R version 2.14.1.
An example is below. Couldn't find anything that seemed to relate to this in
the Changelog. I don't recall encountering this behavior with previous versions
of R. Any suggestions on how to preserve the comment lines would be greatly
appreciated. Many apologies if this is a stupid question. Cleridy
You are likely seeing the results of dropping the source attribute that
happened in 2.14.0.
## this function has comments at the top:
mapsp.sqrtcpd.f
function (input.frm, cpd.numerator, cpd.denominator, basis.dim,
npts, nyrs.unq, prop.ctch)
{
# here are some comments
# and more
#
year.min<- 1975
......
## copy function to a dummy function:
tmp.f<-mapsp.sqrtcpd.f
## now edit it with fix and remove a ) so that it complains:
fix(tmp.f)
Error in edit(name, file, title, editor) :
unexpected symbol occurred on line 15 use a command like
x<- edit()
to recover
## and now recover it and add back in the ) that had been removed :
tmp.f<-edit()
## and look to see what happened... no comments at the top anymore..
tmp.f
function (input.frm, cpd.numerator, cpd.denominator, basis.dim,
npts, nyrs.unq, prop.ctch)
{
year.min<- 1975
......
I'll take a look at edit() and see if it is unnecessarily dropping the
source references which replaced the source attribute. But another way
to maintain your code where this would not be a problem is to keep it in
files outside of R, and source() them after changes. That does work to
keep the comments.
Duncan Murdoch
______________________________________________
R-help@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.