Skip to content

indexing question

5 messages · jim holtman, Ista Zahn, Thomas Lumley

#
How about this:
[1] "ToothGrowth"
[1] "data"

        
On Tue, Jan 13, 2009 at 9:53 AM, Ista Zahn <istazahn at gmail.com> wrote:

  
    
#
R does understand the class of the object so that it knows it should
not try to call the dataframe 'data' if the function 'data' is being
called.  It is probably best to avoid what would be termed "reserved"
words just to prevent mistakes in the future.  How about calling them
"Data"?
On Tue, Jan 13, 2009 at 10:31 AM, Ista Zahn <istazahn at gmail.com> wrote:

  
    
#
There are real examples; they are all fairly obscure.  It can't be a big problem because the standard formal argument name for a data frame in modelling and graphics functions is 'data'.  That's actually a more serious problem than the function called data() -- having local and global variables with the same name won't confuse R, but it can easily confuse you.

Possibilities for R getting confused include
  1. The functions for environment access by name, eg exists(), get(), don't by default check the type of the argument.
  2. bquote() and substitute() substitute before evaluating and could get confused.

There used to be real problems in S when certain function names were used as data names.  Then there was a period of aversive conditioning by irritating warnings. As a result, I still avoid 'c' and 't' as variable names.

You could call your data frames 'df' -- many of the people who complain about 'data' don't realise that df() is the density function of the F distribution :)

      -thomas
On Tue, 13 Jan 2009, Ista Zahn wrote:

            
Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle