Skip to content

variable (column) in a data frame

5 messages · Paulo Barata, Peter Dalgaard, Peter Ehlers +1 more

#
Dr. Dalgaard,

Thank you. But pre-checking with is.null() or using with()
doesn't solve the problem of catching spelling mistakes
in the name of a variable inside a data frame, when using 
the df$var notation often in a program.

Is there some way for R to behave, in relation to a variable 
inside a data frame, the same way it behaves for a variable 
not in a data frame? For example:

##----------------------------------------
a <- c(1,2,3)

## the variable exists, we get a correct answer
a==1

## the variable does not exist, R rightly points this out
aaa==1
##----------------------------------------

My point is, if we make a spelling mistake in a program when referring
to a variable inside a data frame, using the df$var notation, 
there seems to be no way of getting warned about that. 

Thank you once again.

Paulo Barata

---------------------------------------------------------------------


---------- Original Message -----------
From: peter dalgaard <pdalgd at gmail.com>
To: "Paulo Barata" <paulo.barata at ensp.fiocruz.br>
Sent: Sun, 15 Jul 2012 16:47:35 +0200
Subject: Re: [R] variable (column) in a data frame
------- End of Original Message -------
#
On Jul 15, 2012, at 17:41 , Paulo Barata wrote:

            
You could try reading the 2nd half of my one-line reply....

  
    
#
On 2012-07-15 08:41, Paulo Barata wrote:
You could wean yourself from the $-habit. It's convenient but can
lead to the problems you're experiencing (and this has been
discussed before). For programming, if you're prone to make
spelling errors, you should prefer df[, "aaa"]. See ?Extract.

Peter Ehlers
#
Dr. Dalgaard,

Thank you. You are right, with() is able to catch
spelling errors in the name of variables inside a data frame.

But couldn't some error or warning be included in R when referring
to a non-existent variable inside a data frame with the df$var
notation, without the use of with()? 

Is there any reason why R does not have such a kind of error
message?

Thank you again.

Paulo Barata

---------------------------------------------------------------------


---------- Original Message -----------
From: peter dalgaard <pdalgd at gmail.com>
To: "Paulo Barata" <paulo.barata at ensp.fiocruz.br>
Cc: r-help at r-project.org
Sent: Sun, 15 Jul 2012 18:14:22 +0200
Subject: Re: [R] variable (column) in a data frame
------- End of Original Message -------
#
Paulo Barata-3 wrote
See this discussion:
https://stat.ethz.ch/pipermail/r-help/2012-July/317562.html

Berend


--
View this message in context: http://r.789695.n4.nabble.com/variable-column-in-a-data-frame-tp4636561p4636579.html
Sent from the R help mailing list archive at Nabble.com.