Skip to content

Example in body() help page, unexpected warning

5 messages · David Winsemius, Brian Ripley

#
I am getting a warning when using the example s on the help page for  
body:

 > f <- function(x) x^5
 > body(f) <- quote(5^x)
 > ## or equivalently  body(f) <- expression(5^x)
 > f(3) # = 125
[1] 125
 > body(f)
5^x
 >
 > ## creating a multi-expression body
 > e <- expression(y <- x^2, return(y)) # or a list
 > body(f) <- as.call(c(as.name("\{"), e))
Warning messages:
1: '\{' is an unrecognized escape in a character string
2: unrecognized escape removed from "\{"
 > f
function (x)
{
     y <- x^2
     return(y)
}
 > f(8)
[1] 64

The text of the Details section says that:
"The bodies of all but the simplest are braced expressions, that is  
calls to {: see the ?Examples? section for how to create such a call."

So I am puzzled that "\{" is being removed.
 > sessionInfo()
R version 2.10.1 RC (2009-12-09 r50695)
x86_64-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] grid      splines   stats     graphics  grDevices utils      
datasets  methods   base

other attached packages:
  [1] gplots_2.7.4    caTools_1.10    bitops_1.0-4.1  gdata_2.6.1      
gtools_2.6.1
  [6] hexbin_1.20.0   seqinr_2.0-7    kernlab_0.9-9   IDPmisc_1.1.06   
lattice_0.17-26
[11] Design_2.3-0    Hmisc_3.7-0     survival_2.35-7

loaded via a namespace (and not attached):
[1] cluster_1.12.1 tools_2.10.1
#
Hmm, when I run example(body) I get

body> body(f) <- as.call(c(as.name("{"), e))

with no backslash.  And text help and the refman also have no 
backslash.

So, how are you doing this?  Cut-and-paste from HTML help?

I suspect this is yet another rendering problem with HTML help: I've 
fixed quite a few since 2.10.1 was released.
On Sat, 26 Dec 2009, David Winsemius wrote:

            
That is *not* what the message says: it says the backslash is being 
removed.
Please update to a released version.

  
    
#
On Dec 27, 2009, at 2:07 AM, Prof Brian Ripley wrote:

            
Yes; that was how I entered it, but just now I entered this line from  
the keyboard and got the same result:

 > body(f) <- as.call(c(as.name("\{"), e))
Warning messages:
1: '\{' is an unrecognized escape in a character string
2: unrecognized escape removed from "\{"


--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
#
On Sun, 27 Dec 2009, David Winsemius wrote:

            
Correct, as that is not a valid string in R ... R-devel gives an 
error.

  
    
#
On Dec 27, 2009, at 10:16 AM, Prof Brian Ripley wrote:

            
I got a warning