[Rd] "+" for character method...
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Aug 26 16:47:51 CEST 2006
On 8/26/06, John Chambers <jmc at r-project.org> wrote:
> 1. I have to say that I find the idea of using "+" to paste character
> strings together aesthetically ugly.
>
> IMO, one thing that makes functional object-based languages attractive
> is that the generic function retains a consistent _function_, that is,
> purpose and meaning, of which the methods are implementations.
>
> It escapes me totally why I should think of pasting strings as addition
> in the mathematical or intuitive sense (as Brian points out re
> commutativity, it fails a number of axiomatic properties). And if so,
> what about "-", "*", "/" and so on? The mind boggles.
>
> Its excuse presumably is to save typing, but I would favor using some
> %thing% operator at the cost of a couple of extra key strokes.
1. Anyone who uses javascript, python or the VAX/VMS DCL shell language
probably finds + intuitive as all of those use + with strings to mean string
concatentation.
The use of + does have the advantage of some obvious extensions:
- DCL used x - y to mean x with the first occurrence of y removed
so that "banana" - "n" would be "baana"
- python uses 3 * "b" to give "bbb".
- one could define s += "x" to append x to s
2. The gsubfn package does include paste0 and cat0 (as well as the
cati0 extension to gsubfn's cati) which are like paste and cat but default
to sep = "" which reduces typing a bit. This is not as short as defining
a new operator but does get rid of the sep= argument in a very common
case and could be a reasonable compromise if it were moved to the core
of R.
More information about the R-devel
mailing list