Skip to content

R annoyances

6 messages · Brian Ripley, Ben Bolker, Uwe Ligges +2 more

#
On 20-May-05 Uwe Ligges wrote:
Just wanted to point out that there's another (darker) side to this:
code that produces bad results without the users even realizing it.
Personally, I would clearly prefer lots of broken code to mistakes
caused by T/TRUE and F/FALSE.

Hypothetically, if whatever=T/F were forbidden and only
whatever=TRUE/FALSE were allowed, all the code could be fixed with a
simple sed script:
for F in `ls *.r`
do 
  mv $F $F.$$ 
  sed -e 's/=T,/=TRUE,/g' -e 's/=F,/=FALSE,/g' -e 's/=T)/=TRUE)/g' -e
's/=F)/=FALSE)/g' $F.$$ > $F
  rm $F.$$
done



-----Original Message-----
From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de]
Sent: Friday, May 20, 2005 2:39 AM
To: John Fox
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] R annoyances


Dear John,

I have not expected to cause that many traffic and largish discussion.

What I tried to point out is that:
- a "programmer" should know that one has to use TRUE / FALSE in code in 
order to make it work generaly which is also checked by R CMD check.
- a "user" simply typing some lines in order to look at the data can 
shortly write T or F instead.

where "programmer" and "user" are not well defined and probably 
undistinguishable according to Chambers (1998).
I'd call people using [..., drop=FALSE] "programmer" here, since the 
code is probably used inside functions.

S-PLUS compatibility (T/F) has to be considered as well.

All possible changes to T/F (both removing the meaning of TRUE/FALSE in 
a clean session and making them reserved words) would break code of lots 
of users. With a common amount of statistical uncertainty I think it 
might be too late for changes ...

Best,
Uwe
John Fox wrote:
#
On Fri, 20 May 2005, bogdan romocea wrote:

            
You do realize that R CMD check checks for use of unassigned T/F?  So it 
would only be unchecked code which did that.
I assure you it is a *lot* harder than that.  Some of us use spaces for a 
start. No sed script can know the difference between

F <- "2";  as.numeric(x = F)
F <- "2";  as.numeric(x = FALSE)

(I know because I used to share code bases for S-PLUS and R, and had Perl 
scripts to do the conversion that worked for my style, but not for some 
other authors' code.)
#
[snip snip snip snip]
How about "strict" option that could be set to
disallow use of T/F variables?

   I had a student run into trouble fairly recently (although can't
at the moment provide a reproducible example using T as a
variable in a formula that was passed to nls() ... I think there
might still be some internal use of T/F in that package ...
#
Ben Bolker wrote:

            
Probably because T is defined in Namespace base

  T <- 0
  getFromNamespace("T", "base") # [1] TRUE

Uwe
#
Prof Ripley,

I'm aware of R CMD check, but who uses it? Not many regular users, I
presume. As long as T/F are allowed to stand for TRUE/FALSE without
being reserved words, there will be users who will fall in the trap.

As your example shows, some code would have to be manually converted.
Avoiding the difficult conversion may well be considered more
important than ensuring that new/intermediate R users don't get into
trouble. (After all, it's the experts who make the decisions, and who
have a large investment in existing code.) From another perspective
though, the total quantity of past, current - and especially future -
T/F mistakes made by the new members of a rapidly increasing R user
base may outweigh the difficulties the experts would have to go
through to convert their code.
b.


-----Original Message-----
From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
Sent: Friday, May 20, 2005 9:39 AM
To: bogdan romocea
Cc: R-help at stat.math.ethz.ch
Subject: RE: [R] R annoyances
On Fri, 20 May 2005, bogdan romocea wrote:

            
You do realize that R CMD check checks for use of unassigned T/F?  So it 
would only be unchecked code which did that.
I assure you it is a *lot* harder than that.  Some of us use spaces for a 
start. No sed script can know the difference between

F <- "2";  as.numeric(x = F)
F <- "2";  as.numeric(x = FALSE)

(I know because I used to share code bases for S-PLUS and R, and had Perl 
scripts to do the conversion that worked for my style, but not for some 
other authors' code.)
#
bogdan romocea wrote:
If you don't use it, then you should.  Putting your code in a package is 
a good idea even if you have no intention of showing it to anyone else, 
and check will flush out a lot of errors in package code and its 
documentation.
Users who don't follow good practices are going to run into trouble. 
What's so surprising about that?

Duncan Murdoch