Skip to content

Supercripting text

6 messages · Kevin Coombes, Shang Gao, David Winsemius

#
You probably want to write your own titling function to add 
superscripts.  The following code will serve as a reasonable starting point:

# make the title expression
ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))), 
list(fn=fn)))
  }
  title
}
# example with footnotes
tt <- ourtitle("stuff", 1:3)
plot(1, 1)
title(tt)
# example without footnotes
plot(1, 1)
title(ourtitle("stuff"))

Note that the only way I could make this work was to combine the 
footnote list before calling the eval-substitute-expression code; I 
cannot get it to work by applying things ot a list.

    Kevin
Shang Gao wrote:
#
I tried writing that function before, but the expression() command is not preserved when we incorporate it into a function(). The first example you gave me, if run in R, produced a title that reads "title" instead of "stuff". It seems that in this case the expression() can't read the character string in the argument specified in the function() command.

-----Original Message-----
From: Kevin Coombes [mailto:kevin.r.coombes at gmail.com] 
Sent: Monday, May 10, 2010 12:08 PM
To: Shang Gao
Cc: r-help at r-project.org
Subject: Re: [R] Supercripting text

You probably want to write your own titling function to add 
superscripts.  The following code will serve as a reasonable starting point:

# make the title expression
ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))), 
list(fn=fn)))
  }
  title
}
# example with footnotes
tt <- ourtitle("stuff", 1:3)
plot(1, 1)
title(tt)
# example without footnotes
plot(1, 1)
title(ourtitle("stuff"))

Note that the only way I could make this work was to combine the 
footnote list before calling the eval-substitute-expression code; I 
cannot get it to work by applying things ot a list.

    Kevin
Shang Gao wrote:
#
Sigh; that's because I forget to include it in the 'substitute' list.  
Here is a version that works (and has been tested...).

ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))),
                             list(title=title, fn=fn)))
  }
  title
}
Shang Gao wrote:
#
Another question: is it possible to keep the superscripts unbolded? For example if you run the codes below, it can be seen that using the expression(bold(paste(...))) command will result in the text being bolded but not the superscripts.

ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))),
                             list(title=title, fn=fn)))
  }
  title
}

plot(0, type="n")
text(1,0, expression(bold(paste("stuff",""^1, " "^2, " "^3))))
text(1,0.5,ourtitle("stuff",1:3))

-----Original Message-----
From: Kevin Coombes [mailto:kevin.r.coombes at gmail.com] 
Sent: Monday, May 10, 2010 1:02 PM
To: Shang Gao
Cc: r-help at r-project.org
Subject: Re: [R] Supercripting text

Sigh; that's because I forget to include it in the 'substitute' list.  
Here is a version that works (and has been tested...).

ourtitle <- function(title, footnotes=NULL) {
  if (length(footnotes) > 0) {
    fn <- paste(footnotes, collapse=' ')
    title <- eval(substitute(expression(bold(paste(title, ""^fn))),
                             list(title=title, fn=fn)))
  }
  title
}
Shang Gao wrote:
#
On May 11, 2010, at 12:37 PM, Shang Gao wrote:

            
try instead:

expression(bold(paste(title^plain(fn))
David Winsemius, MD
West Hartford, CT