[R] Strange display of saved functions

Mik Bickis m.bickis at sasktel.net
Mon Jan 30 18:29:08 CET 2017


Hello:

I recently upgraded to R version 3.3.2 (2016-10-31)

Now I find that functions that I load from an older .RData file give a strange display:

---------------------------------------------------------------------------------------------------------------------------
> payments
function (a, n, tol = 1e-10) 
{
    p <- a/(1 - (1 + a)^(-n))
    p[a < tol] <- 1/n + (n + 1) * a[a < tol]/(2 * n)
    p
}
attr(,"source")
[1] "function(a,n,tol=1E-10){# required proportion of principal required to "
[2] "\t# pay off loan in n installments at interest rate a"                  
[3] "\tp<-a/(1-(1+a)^(-n))"                                                  
[4] "\t# linear approximation for small rates"                               
[5] "\tp[a<tol]<-1/n+(n+1)*a[a<tol]/(2*n)"                                   
[6] "\tp}"                                                
------------------------------------------------------------------------------------------------------------------------------

In addition to the usual function definition it also prints the function contents as an attribute "source", including strange escape characters at the beginning of the lines.  Note that the comment only appears in this latter display.
This same display happens if I use the "edit" function.

However, if I copy and paste the definition into a new function, then it displays as expected:

----------------------------------------------------------------------------------------------------------------------------
> puments<-function (a, n, tol = 1e-10) 
+ {
+     p <- a/(1 - (1 + a)^(-n))
+     p[a < tol] <- 1/n + (n + 1) * a[a < tol]/(2 * n)
+     p
+ }
> 
> puments
function (a, n, tol = 1e-10) 
{
    p <- a/(1 - (1 + a)^(-n))
    p[a < tol] <- 1/n + (n + 1) * a[a < tol]/(2 * n)
    p
}
--------------------------------------------------------------------------------------------------------------------------------

And I can successfully insert a comment right in the definition, as one would like

-------------------------------------------------------------------------------------------------------------------------------------------
> puments
function (a, n, tol = 1e-10) 
{# required proportion of principal required to 
# pay off loan in n installments at interest rate a 
    p <- a/(1 - (1 + a)^(-n))
    p[a < tol] <- 1/n + (n + 1) * a[a < tol]/(2 * n)
    p
}
-------------------------------------------------------------------------------------------------------------------------------------------

What is happening to the displays of my function definitions?   I have never witnessed such behaviour before.   Is there some option I have to set (globally) to suppress this redundancy?

Mik Bickis
Department of Mathematics and Statistics
University of Saskatchewan


More information about the R-help mailing list