[R] [External] Re: [External] Adding a superscript 6 to a number

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Wed Dec 30 00:45:10 CET 2020


This doesn't sound right. When you use expression() it freezes the syntax as the expression you wrote, so expression(paste(x^2,"[", m^2, "]")) is a perfectly valid plotmath expression. The expression() call is _not_ an "inverse" of paste because the presence of paste is supporting the inclusion of non-syntactic elements in this context... it is handled by plotmath, not by actually executing paste(), and expression is delaying evaluation to give plotmath a chance to combine the sub expressions including character literals without as.character or a subsequent eval().

Code that invokes paste on an expression seems unwise to me... but not the other way around.

On December 29, 2020 3:05:21 PM PST, Bert Gunter <bgunter.4567 using gmail.com> wrote:
>... yes, more specifically:
>
>(from ?paste)
>"paste converts its arguments (*via* as.character
><http://127.0.0.1:33923/help/library/base/help/as.character>) to
>character
>strings, and concatenates them (separating them by the string given by
>sep).
>"
>
>More to the point, I would say, is that if you need to manipulate
>expressions or other language objects you should live in the world of
>language objects, rather than converting them back and forth to
>character
>strings.  But this may be off topic and in the weeds;  for which, if
>so,
>apologies.
>
>Cheers,
>Bert
>
>
>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 )
>
>
>On Tue, Dec 29, 2020 at 2:57 PM Richard M. Heiberger <rmh using temple.edu>
>wrote:
>
>> It is a generalization.
>> Don't use paste() and expression() together because paste is a
>sort-of
>> inverse to expression.
>> In this example I start by typing several characters, and the result
>> of paste(expression()) is a string containing the characters I
>> initially typed.
>>
>> > expression(12^6)
>> expression(12^6)
>> > paste(expression(12^6))
>> [1] "12^6"
>>
>>
>> expression(12^6)
>> paste(expression(12^6))
>>
>> plot(0:1, 0:1)
>> text(.1, .4, labels=paste(expression(12^6)))
>> text(.1, .3, labels=expression(12^6))
>>
>> On Tue, Dec 29, 2020 at 4:15 PM Jeff Newmiller
><jdnewmil using dcn.davis.ca.us>
>> wrote:
>> >
>> > Why not? Is that a generalization, or specific to this case?
>> >
>> > On December 29, 2020 7:54:22 AM PST, "Richard M. Heiberger" <
>> rmh using temple.edu> wrote:
>> > >paste() is the problem.  don’t use paste with expression()
>> > >
>> > >On Tue, Dec 29, 2020 at 10:50 Sorkin, John
><jsorkin using som.umaryland.edu>
>> > >wrote:
>> > >
>> > >> Colleagues,
>> > >>
>> > >> I would like to create a number (stored in the variable x) to
>the
>> > >number
>> > >> with the exponent of, i.e. the number to the sixth power. The
>code I
>> > >have
>> > >> tried, pasted below does not work.
>> > >>
>> > >> # create plot
>> > >> plot(x=0.2,y=0.2,xlim=c(0,1),ylim=c(0,1))
>> > >> PNotSusp=0.69
>> > >> # Create a string containing the base and exponent.
>> > >> x <- 0.95123
>> > >> # Convert the base to text and add the exponent of 6
>> > >> mylab <- expression(paste(" ",character(x)^6))
>> > >> # Add the text to the plot
>> > >> text(0.4,0.8,labels=paste(PNotSusp,"=\n",mylab))
>> > >>
>> > >> I hope someone can show me how to create the text string I need.
>> > >>
>> > >> Thank you,
>> > >> John
>> > >>
>> > >> John David Sorkin M.D., Ph.D.
>> > >> Professor of Medicine
>> > >> Chief, Biostatistics and Informatics
>> > >> University of Maryland School of Medicine Division of
>Gerontology and
>> > >> Geriatric Medicine
>> > >> Baltimore VA Medical Center
>> > >> 10 North Greene Street
>> > >>
>> > ><
>>
>https://www.google.com/maps/search/10+North+Greene+Street?entry=gmail&source=g
>> >
>> > >> GRECC (BT/18/GR)
>> > >> Baltimore, MD 21201-1524
>> > >> (Phone) 410-605-7119
>> > >> (Fax) 410-605-7913 (Please call phone number above prior to
>faxing)
>> > >>
>> > >>
>> > >> ______________________________________________
>> > >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more,
>see
>> > >> https://stat.ethz.ch/mailman/listinfo/r-help
>> > >> PLEASE do read the posting guide
>> > >> http://www.R-project.org/posting-guide.html
>> > >> and provide commented, minimal, self-contained, reproducible
>code.
>> > >>
>> > >
>> > >       [[alternative HTML version deleted]]
>> > >
>> > >______________________________________________
>> > >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > >https://stat.ethz.ch/mailman/listinfo/r-help
>> > >PLEASE do read the posting guide
>> > >http://www.R-project.org/posting-guide.html
>> > >and provide commented, minimal, self-contained, reproducible code.
>> >
>> > --
>> > Sent from my phone. Please excuse my brevity.
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list