patrickroocks / listcompr

An R package for list comprehension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

name conflicts

ggrothendieck opened this issue · comments

The code below gives an error. It is because the first argument, str=, is matched by the s= . It is easy enough to fix if you know the problem by naming the str= argument but it can seem quite mysterious when it happens. When I encountered this I was initially baffled. I didn't even realize that the name of the first argument was str= since one tends to use this function without the names. To make it worse, s= is commonly used as a subscript such as s and t being times.

I suggest that the names be changed to something that is less likely to cause a conflict such as .str= with a dot in front or some other method of dealing with this.

gen.named.vector("{s}", s*s, s = 1:2)
## Error: no named variables are given, expected at least one named variable in the '...' parameters

Very interesting, I am using R for more than 10 years now and did not know that named variables can be matched by left substrings of the variable name.
According to you suggesting I have changed the names str to .str and expr to .expr

I have some doubts what to do with the byrow parameter. As it is placed after the ... parameter pack, the matching is not problematic:

> gen.data.frame(x, x=1:2, byrow = TRUE)
  V1 V1
x  1  2
> gen.data.frame(x, x=1:2, b = TRUE)
  x
1 1
2 2

To avoid an API break, I tend to preserving the name byrow. Well, theoretically also renaming str and expr is an API break, but I assume nobody will use them with explicit names. Also in all the examples and tests they are just used as positioned variables.

Anyway, thanks for finding that bug! Fixed with the last commit.