Re: [R] Pasting R code lines into labels

2019-06-07 Thread Marc Schwartz via R-help
Hi Martin, See inline below... > On Jun 7, 2019, at 9:25 AM, Martin Maechler > wrote: > >> Marc Schwartz via R-help >>on Fri, 7 Jun 2019 09:07:21 -0400 writes: > >> Hi, Ok, some additional tweaks. > >> Relative to Bert's pointing out the aesthetic issues, >> certainly, those are

Re: [R] Pasting R code lines into labels

2019-06-07 Thread Nick Wray via R-help
Wow! I hadn't meant to set off such an email flurry... Tbh all I wanted to do was to label some plots for my own recording and notes so Bert's idea was more than adequate. On the other hand it's instructive to venture further into the R-universe in such distinguished company... Nick > On 07

Re: [R] Pasting R code lines into labels

2019-06-07 Thread Martin Maechler
> Marc Schwartz via R-help > on Fri, 7 Jun 2019 09:07:21 -0400 writes: > Hi, Ok, some additional tweaks. > Relative to Bert's pointing out the aesthetic issues, > certainly, those are attributes that can be adjusted as > Nick may require. I was focused more on the pri

Re: [R] Pasting R code lines into labels

2019-06-07 Thread Marc Schwartz via R-help
Hi, Ok, some additional tweaks. Relative to Bert's pointing out the aesthetic issues, certainly, those are attributes that can be adjusted as Nick may require. I was focused more on the primary issue. Using "..." is an easy way to pass additional parameters to plot.default() as Bert indicated.

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Duncan Murdoch
These look like very fragile suggestions. Allow x^2 to be an argument (named expr, for example) to plotFx, don't force a user to write a function in a very particular way. Then use deparse(substitute(expr)) in the title. Duncan Murdoch On 06/06/2019 4:33 p.m., Bert Gunter wrote: Well, if y

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
Well, if you want to do it this way, note that as written, the y axis default label isn't "nice," and you should anyway allow for additional graphical arguments (either way). Also, slightly better I think is to use the built-in access function, body(): plotFx <- function(x, fun, ...) { plot(x,

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Marc Schwartz via R-help
Hi, Sorry for the misfire on the first attempt. After seeing the clarifications, I thought about a possible way to do this, perhaps a little more simply, while encapsulating the plotting in a function: plotFx <- function(x, fun) { plot(x, fun(x), main = paste0("Plot of y = ", deparse(fun)[2])

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
Yes, plot(z,y,..) Bert On Thu, Jun 6, 2019 at 9:21 AM Nick Wray wrote: > Thanks Bert, that is exactly what I wanted. I think that you meant > plot(z,y... in the last line? > > Nick > > On 06 June 2019 at 17:13 Bert Gunter wrote: > > ... and if you wanted too streamline the process, something

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Thanks Bert, that is exactly what I wanted. I think that you meant plot(z,y... in the last line? Nick > On 06 June 2019 at 17:13 Bert Gunter wrote: > > ... and if you wanted too streamline the process, something like the > following could be encapsulated in a function: > > fun <- qu

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
... and if you wanted too streamline the process, something like the following could be encapsulated in a function: fun <- quote(exp(x)) z <- 1:9 y <- eval(fun,list(x = z) ) plot(x, y, main = paste("Plot of y =", deparse(fun))) Further details can be found in the "Computing on the Language" secti

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Thanks but that's not quite what I meant I am trying out different functions and they don't necessarily vary in a regular way (like say all being powers of x where it'd be simple to just have a vector for the powers you want) So I might have y<-x^2 y<-cos(x) y<-exp(x+1) What I am after is a way o

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
The well known deparse(substitute(...)) construction. plot(1:9, main = paste("plot of",deparse(substitute(y <- x^2 Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Marc Schwartz via R-help
> On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help > wrote: > > Is there any way of taking a line of r code (eg y<-x^2) and pasting that line > of code, as is, into a label, so that for example I could then have a plot > label "Plot of y<-x^2"? > > Thanks Nick Wray Hi, See ?plotmath A

[R] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Is there any way of taking a line of r code (eg y<-x^2) and pasting that line of code, as is, into a label, so that for example I could then have a plot label "Plot of y<-x^2"? Thanks Nick Wray [[alternative HTML version deleted]] __ R-help@r