I've passed a data.frame as an input into a function which does some plotting on a 4x4 matrix of certain parameters within in the data.frame. I'd like to add a small header on top of each plot with the name of the data.frame so that it's clear as I compare these 16 things where each on came from. So far I haven't found the right way to get the name of the data.frame as a string which I can use in something like mtext. Is there one? If I put dummy text in, or take the time to pass in the name by hand, then I do get titles just as I'd like, but I'd far rather let the name of the data.frame speak for itself. Thanks, Mark
On 02-Jul-09 19:00:44, Mark Knecht wrote:> I've passed a data.frame as an input into a function which does some > plotting on a 4x4 matrix of certain parameters within in the > data.frame. I'd like to add a small header on top of each plot with > the name of the data.frame so that it's clear as I compare these 16 > things where each on came from. > > So far I haven't found the right way to get the name of the data.frame > as a string which I can use in something like mtext. Is there one? If > I put dummy text in, or take the time to pass in the name by hand, > then I do get titles just as I'd like, but I'd far rather let the name > of the data.frame speak for itself. > > Thanks, > MarkOne way to do this (which is how I usually do it) is to set up the dataframe name as a string variable, and then use this as required. For instance: datafr <- "My1stDF" DF <- read.csv(paste(datafr,".csv",sep="") {<do things>} plot(whatever,main=paste("Data from", datafr),...) which will read the CSV file whose name corresponds to what you have set 'datafr' to, and then put a corresponding header into the plot. This is a particularly useful technique if you want to loop through several datasets, on the lines of DataFrs <- c("My1stDF", "My2ndDFD", "My3rdDF", "My4thDF") for( datafr in DataFrs ) { {<stuff like the above>} } Several variants of this kind of approach are possible! Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 02-Jul-09 Time: 20:21:43 ------------------------------ XFMail ------------------------------
Use deparse(substitute(df)) Example from ?deparse: function(x, y) { plot(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } -Don At 12:00 PM -0700 7/2/09, Mark Knecht wrote:>I've passed a data.frame as an input into a function which does some >plotting on a 4x4 matrix of certain parameters within in the >data.frame. I'd like to add a small header on top of each plot with >the name of the data.frame so that it's clear as I compare these 16 >things where each on came from. > >So far I haven't found the right way to get the name of the data.frame >as a string which I can use in something like mtext. Is there one? If >I put dummy text in, or take the time to pass in the name by hand, >then I do get titles just as I'd like, but I'd far rather let the name >of the data.frame speak for itself. > >Thanks, >Mark > >______________________________________________ >R-help at r-project.org mailing list >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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
Perfect! Thanks! Cheers, Mark On 7/2/09, Phil Spector <spector at stat.berkeley.edu> wrote:> Mark - > Take a look at the help file for substitute. > For example: > > > > zz = function(x)print(substitute(x)) > > zz(variablename) > > > variablename > > - Phil > > > > On Thu, 2 Jul 2009, Mark Knecht wrote: > > > > > > I've passed a data.frame as an input into a function which does some > > plotting on a 4x4 matrix of certain parameters within in the > > data.frame. I'd like to add a small header on top of each plot with > > the name of the data.frame so that it's clear as I compare these 16 > > things where each on came from. > > > > So far I haven't found the right way to get the name of the data.frame > > as a string which I can use in something like mtext. Is there one? If > > I put dummy text in, or take the time to pass in the name by hand, > > then I do get titles just as I'd like, but I'd far rather let the name > > of the data.frame speak for itself. > > > > Thanks, > > Mark > > > > ______________________________________________ > > R-help at r-project.org mailing list > > 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. > > > > >
On 7/2/09, Don MacQueen <macq at llnl.gov> wrote:> Use > deparse(substitute(df)) > > Example from ?deparse: > > function(x, y) { > plot(x, y, xlab=deparse(substitute(x)), > ylab=deparse(substitute(y))) > } > > -Don >Now that's interesting... deparsed means ?? de-analyze ?? I'm not clear what that's doing for me beyond using only substitute but your example and the substitute example both use it so I suppose I shouldn't tempt the Fates... Thanks, Mark