All R strings should be null-terminated, so strncpy will only copy the number of characters present (plus the null terminator) if less than n. Quite true; I'd forgotten strncpy stopped at null. I can see that writeChars might write rubbish out, but not why it should segfault. Ok, I've just had a poke at it with ddd. The above example faults in the memset() call (line 2772 connections.c) in both R versions. I think the problem is underallocation of buf:
len = 0; /* line 2757 */ for(i = 0; i < n; i++) { tlen = strlen(CHAR(STRING_ELT(object, i))); if (tlen > len) len = tlen; } buf = (char *) R_alloc(len + slen, sizeof(char));
which sets len to the longest string in object (in this case, 0 bytes), then allocates len+slen to buf. gdb confirms len=0 and slen=1 at this point. But a little later
len = INTEGER(nchars)[i]; /* line 2770 */ s = CHAR(STRING_ELT(object, i)); memset(buf, '\0', len + slen); strncpy(buf, s, len);
len is now set to [the first element of] nchars, which hasn't been checked, and is 10000000 (gdb confirms). So the call to memset() copies way over the end of allocated buf. Does that sound rational? I'm not very familiar with R's internals. I guess small overruns might not actually fault, because buf is within R's existing heap?
The notion that samples ought to be random is so firmly engrained in one's mind that it seems almost sacrilegious to object to the application of the rule in a particular case. But after all the problem surely is not whether a tract passing under the name Jones does or does not resemble, in this particular characteristics, a random sample from writings of Brown, but samples from Brown's writing dealing, so far as possible, with same sort of material in the same sort of way. The method of "selected samples" is, from this standpoint, entirely justified and perfectly correct.
PROGRAM p30_f90 IMPLICIT NONE REAL :: X,Y WRITE (*,*) 'X=' READ (*,*) X Y=((2.0*X+5.0)*X+3.0)*X+1.0 WRITE (*,*) 'Y=', Y STOP END PROGRAM p30_f90 $ gfortran -o p30 p30.f90
計量経済学やその周辺の学問体系は、マルクス経済学に由来する学び方の「輪読」や「レジメ」学習法からは何も得るものはないので注意してほしい。自分の手で実際に動かしてその仕組みを知る他はない。