I had an obscure bug that boiled down to this ``feature'' in R, Read 3921 items> A = list(aa = 1) > A$aa [1] 1> if (A$a) print("a is there")[1] "a is there" The test appear to check is A$a is TRUE, but what happen is that it auto-complete (silently), and expand to 'A$aa'. The problem was caused by the fact that I had also a element named 'a' which was evaluated to NULL, like> A$a = NULL > A$aa [1] 1> if (A$a) print("a is there")[1] "a is there" since NULL elements are removed from the list, and that A$a auto-expand to A$aa, my error appeared. To me, this seems not a feature I want in order to have a robust program. Is there any option to turn this ''feature'' off? Best, H -- H?vard Rue Department of Mathematical Sciences Norwegian University of Science and Technology N-7491 Trondheim, Norway Voice: +47-7359-3533 URL : http://www.math.ntnu.no/~hrue Fax : +47-7359-3524 Email: havard.rue at math.ntnu.no This message was created in a Microsoft-free computing environment.
Hi, From ?"$", you can see that using [[ instead would do what you're looking for. You should read and try to understand the whole help file. The reason is that for [[ the default is exact=TRUE, wheareas for $ the only possible value is exact=FALSE, which means partial matching if possible. So try A[["aa"]] instead. HTH, Ivan Le 3/11/2011 09:55, H?vard Rue a ?crit :> I had an obscure bug that boiled down to this ``feature'' in R, > > Read 3921 items >> A = list(aa = 1) >> A > $aa > [1] 1 > >> if (A$a) print("a is there") > [1] "a is there" > > The test appear to check is A$a is TRUE, but what happen is that it > auto-complete (silently), and expand to 'A$aa'. > > The problem was caused by the fact that I had also a element named 'a' > which was evaluated to NULL, like > >> A$a = NULL >> A > $aa > [1] 1 > >> if (A$a) print("a is there") > [1] "a is there" > > since NULL elements are removed from the list, and that A$a auto-expand > to A$aa, my error appeared. > > To me, this seems not a feature I want in order to have a robust > program. > > Is there any option to turn this ''feature'' off? > > Best, > H > > >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
On Mar 11, 2011, at 09:55 , H?vard Rue wrote: ....> > since NULL elements are removed from the list, and that A$a auto-expand > to A$aa, my error appeared. > > To me, this seems not a feature I want in order to have a robust > program. >Partial matching of arguments and list item names is a feature long regretted by its inventors, but too late to remove. Too many people doing chisq.test(...)$exp etc.> Is there any option to turn this ''feature'' off?No. It's not the sort of thing you want to control with an option. It's a nightmare when you think of package development. For one thing, your code would break if someone turned the option back on. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com