Cleridy Lennert
2012-Feb-13 23:02 UTC
[R] comment lines sometimes removed from a function on exit from internal R editor
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 ## this function has comments at the top:> mapsp.sqrtcpd.ffunction (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.ffunction (input.frm, cpd.numerator, cpd.denominator, basis.dim, npts, nyrs.unq, prop.ctch) { year.min<- 1975 ...... [[alternative HTML version deleted]]
Duncan Murdoch
2012-Feb-14 12:11 UTC
[R] comment lines sometimes removed from a function on exit from internal R editor
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. CleridyYou 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
Apparently Analagous Threads
- Named numeric vectors with the same value but different names return different results when used as thresholds for calculating true positives
- samba CPD nfs lock
- Multiple linear regression with for loop
- text(x,y,greek character)
- number of items to replace is not a multiple of replacement length