From murdoch at stats.uwo.ca  Sat Dec 22 13:58:00 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sat, 22 Dec 2007 07:58:00 -0500
Subject: [Rd] substitute() bug? (PR#10525)
In-Reply-To: <20071221164531.D64372834632@mail.pubhealth.ku.dk>
References: <20071221164531.D64372834632@mail.pubhealth.ku.dk>
Message-ID: <476D09D8.3070403@stats.uwo.ca>

rossibarra at gmail.com wrote:
> The first four lines of code below work as normal.  The fifth thorows  
> an error: "Error in paste(theta[1], "=", 5) : object "theta" not found"
>
>
> x=rnorm(1000);
> bob=density(x);
> topp=5;
> plot(bob,xlab="", ylab="",  
> main=substitute(paste(theta[1],"=",topp),list(topp=topp)), type="l");
> plot(bob$y~bob$x,xlab="", ylab="",  
> main=substitute(paste(theta[1],"=",topp),list(topp=topp)), type="l");
>   
I'm not sure this is a bug, but if it is, it's in 
graphics:::plot.formula, not in substitute.  The problem is that 
substitute returns an unevaluated call, and plot.formula tries to 
evaluate it.  You can avoid the bug by wrapping the substitute call in 
as.expression.

The docs for plotmath say that it requires an expression, but "in most 
cases" language objects will be coerced to one:  it appears this is one 
of the cases where that is not true.

Duncan Murdoch
>
> Note that theta is not defined anywhere:
>
> ls()
>   [1] "bob"      "dline"    "dplot"    "dpt"      "less"     "lesseq"
>   [7] "more"     "moreeq"   "peak"     "peakline" "peakplot" "pop"
> [13] "topp"     "x"
>
>
> Version:
>   platform = i386-apple-darwin8.10.1
>   arch = i386
>   os = darwin8.10.1
>   system = i386, darwin8.10.1
>   status =
>   major = 2
>   minor = 6.1
>   year = 2007
>   month = 11
>   day = 26
>   svn rev = 43537
>   language = R
>   version.string = R version 2.6.1 (2007-11-26)
>
> Locale:
> C
>
> Search Path:
>   .GlobalEnv, package:stats, package:graphics, package:grDevices,  
> package:utils, package:datasets, package:methods,
>
> ____________
>
> Jeffrey Ross-Ibarra
> email: rossibarra at gmail.com
> web: rossibarra.googlepages.com
> Dept. Ecology and Evolutionary Biology
> University of California
> Irvine, Ca. 92697
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] substitute() bug? (PR#10525)
Duncan Murdoch