> 1:3
[1] 1 2 3
> c(1:3)
[1] 1 2 3
> test=1:3
> test
[1] 1 2 3
> str(test)
int [1:3] 1 2 3
No surprises so far.
> bb <- c(tst=1:3)
> bb
Expected:
int [1:3] 1 2 3
or
[1] 1 2 3
.
> str(bb)
Expected:
Named int [1:3] 1 2 3
- attr(*, "names")= chr [1] "tst"
Actual:
> bb
tst1 tst2 tst3
1 2 3
> str(bb)
Named int [1:3] 1 2 3
- attr(*, "names")= chr [1:3] "tst1" "tst2" "tst3"
Where did those names come from?
I mean, they are plausible enough names, but I don't see anything that could produce them.
I've looked at help for c, :
, =
, at the names() function, and even at (
. I've looked at the code for :
and c
, so see if I might have overwritten them somehow, and at tst in case it was some weird function that doesn't need a parenthesis. I've closed R and restarted it with an empty workspace.
I'm baffled.
NEW INFORMATION:
Well, it looks to me like the answer is probably in this code snippet, and I'm prepared to bet that the creation of three names has something to do with the "recurse" argument to NewExtractNames, but I don't know enough c to understand exactly what is happening. But I thought I would put the code here to make it easier for someone with deeper knowledge (@hrbrmstr, maybe?) to answer if they are so moved.
if (data.ans_nnames && data.ans_length > 0) {
PROTECT(data.ans_names = allocVector(STRSXP, data.ans_length));
data.ans_nnames = 0;
while (args != R_NilValue) {
nameData.seqno = 0;
nameData.firstpos = 0;
nameData.count = 0;
NewExtractNames(CAR(args), R_NilValue, TAG(args), recurse, &data, &nameData);
args = CDR(args);
}
setAttrib(ans, R_NamesSymbol, data.ans_names);
UNPROTECT(1);
}