Re: [R] error in dat

From: Prof Brian Ripley <>
Date: Mon, 16 Jun 2008 09:57:55 +0100 (BST)

On Mon, 16 Jun 2008, Wacek Kusnierczyk wrote:

> Paul Adams wrote:
>> Hello everyone,
>> I have the following code which keeps giving me an error.
>> The code is:
>> dat<-read.table(file="C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt",header=T,row.names=1,blank.lines.skip=F,na..strings="NA")
>> dimnames(dat)((1)) <-as.character(dat(,1))
>> dat<-dat(,-1)
>> dat<
>>"C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt")
>> ann<-read.table(file="C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt",header=T)

>>"C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt")
>> cl<-as.character(ann[,2])
>> dat<-dat[,cl]
>> gc<-cl(1:19)
>> act<-cl(20:39)
>> x<-as.numeric(dat(2000,gc))
>> y<-as.numeric(dat(2000,act))
>> x<-x(!
>> y<-y(!
>> xy.list<-list(x,y)
>> boxplot(xy.list,col=c("red","blue"),main="Gene 2000")
>> The error is: "error in eval .with.vis(expr, envir, enclos) :
>> could not find function "dat"
> you misuse the syntax, check the docs. with 'dat(...)' r tries to apply
> dat, but dat is a data frame, and is thus not applicable. what you want
> is dat[...].
> you can argue that the error message is misleading; unless you defined
> one, r cannot find a function named 'dat', but it does find your data
> frame, and it should complain about its non-applicability.

It is this explanation which is misleading. R (not r) looks for a function named 'dat': it does not find the data frame when looking for a function. To be explicit, when R encounters foo() it looks in the current environment for a function named 'foo' and ignores all other objects named 'foo' even if they are higher on the search path. This was not the behaviour of Blue-Book S, but it has been the behvaviour of S and R for many years.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 16 Jun 2008 - 09:01:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 16 Jun 2008 - 09:30:40 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive