[19112] in s-news-athena

home help back first fref pref prev next nref lref last post

[S] need help writing a function

daemon@ATHENA.MIT.EDU (Paul Schwarz)
Sat Sep 4 22:18:13 1999

From: "Paul Schwarz" <Paul.Schwarz@cornell.edu>
To: <s-news@wubios.wustl.edu>
Date: Sat, 4 Sep 1999 22:10:32 -0400
Message-Id: <001401bef743$d5c1a5e0$96a95f18@schwarz.twcny.rr.com>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


Hello,

I suspect that there is a simple solution to this programming problem,
but so far it eludes me.  I am trying to write a function that allows me
to plot variables from a dataframe without specifying the name of the
data frame (yes, I know that I could attach the data frame but please
bear with me).  The difficulty appears to be related to working with the
names of data objects versus the objects themselves.  The first approach
I tried was to preserve both the dataframe name and the variable name as
components of the data object.  E.g.,

plotit <- function( y ) {
   df <- mydataframe
   boxplot( df$y )
}

This seems to fail because df$y get evaluated as mydataframe$y, and the
substitution of y never happens.

The second approach I tried was to paste the dataframe name and the
variable name together into a single string.  However, I was unable to
figure out how to coerce this string, which represents the name of the
object, into a reference to the actual object.  For example:

plotit <- function( y ) {
   df <- "mydataframe"
   yvar <- paste( df, deparse( substitute( y ) ), sep = "$" )
   boxplot( yvar )
}

This fails because yvar is a string and not a reference to an object.

I'd appreciate any tips or advice that you might have regarding this
problem.

Thank you.

-Paul

Paul.Schwarz@Cornell.EDU


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post