0

Is the filename of the current data set used in Lattice (e.g. in xyplot()) available as a variable name ?

I want to include the data set name as a footnote to the graph and write a generic function that takes the name.

Thanks

  • 2
    A minimal working example will help get you the best answers. (see http://stackoverflow.com/q/5963269) – BenBarnes Oct 17 '13 at 08:56

1 Answers1

0

Do you mean "how do I turn a variable name into a string"?

If so, use the magic incantation deparse(substitute(my_variable)).

drawplot <- function(x, data)
{
  dataname <- deparse(substitute(data))
  xyplot(
    x,
    data = data,
    main = dataname
  )  
}
drawplot(Sepal.Width ~ Sepal.Length, iris)

On second thoughts, that might be overthinking things. It's a little easier to go the other way: starting with the dataset name, and then retrieving the data with get.

dataname <- "iris"
xyplot(
  Sepal.Width ~ Sepal.Length,
  data = get(dataname),
  main = dataname
) 
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • @user1503320 If the answer was useful to you, then you can upvote it by clicking the up arrow next to the tick on the left. – Richie Cotton Oct 18 '13 at 14:12