In preparing data sets for the lme library, I bring the data into R,
convert it to the groupedData class, which is an extension of the
data.frame class, and use "dump" to create an R-readable version.
To cut down on the size of these files I convert the row.names
attribute from expressions like c("1", "2", ...,
"54") to 1:54.
I have run into a curious problem that seems to related to the
position of the row.names attribute in the R-readable representation.
The following transcript was generated under R-0.61.1 on a Debian
Linux system. I apologize for the length of the transcript.
R> print.groupedData
function (x, ...)
{
cat("Grouped Data: ")
print(attr(x, "formula"))
NextMethod("print", x, ...)
}
R> "Machines" <-
+ structure(list
+ (Worker = structure(ordered(c(4, 4, 4, 2, 2, 2,
+ 5, 5, 5, 3, 3, 3, 6, 6, 6, 1, 1, 1, 4, 4, 4, 2, 2, 2, 5, 5, 5,
+ 3, 3, 3, 6, 6, 6, 1, 1, 1, 4, 4, 4, 2, 2, 2, 5, 5, 5, 3, 3, 3,
+ 6, 6, 6, 1, 1, 1), levels=1:6), class = c("ordered",
"factor"),
+ .Label = c("6", "2", "4", "1",
"3", "5")),
+ Machine = structure(factor(c(1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), levels=1:3), class =
"factor",
+ .Label = c("A", "B", "C")),
+ score = c(52, 52.8,
+ 53.1, 51.8, 52.8, 53.1, 60, 60.2, 58.4, 51.1, 52.3, 50.3, 50.9,
+ 51.8, 51.4, 46.4, 44.8, 49.2, 62.1, 62.6, 64, 59.7, 60, 59, 68.6,
+ 65.8, 69.7, 63.2, 62.8, 62.2, 64.8, 65, 65.4, 43.7, 44.2, 43,
+ 67.5, 67.2, 66.9, 61.5, 61.7, 62.3, 70.8, 70.6, 71, 64.1, 66.2,
+ 64, 72.1, 72, 71.1, 62, 61.4, 60.5)),
+ class = c("nffGroupedData", "nfGroupedData",
"groupedData", "data.frame"),
+ row.names = 1:54,
+ formula = score ~ 1 | Worker,
+ labels = list(y = "Productivity score"),
+ inner = ~ Machine)
R> Machines
Grouped Data: score ~ 1 | Worker
Worker Machine score
1 1 A 52.0
2 1 A 52.8
3 1 A 53.1
4 2 A 51.8
5 2 A 52.8
6 2 A 53.1
7 3 A 60.0
8 3 A 60.2
9 3 A 58.4
10 4 A 51.1
11 4 A 52.3
12 4 A 50.3
13 5 A 50.9
14 5 A 51.8
15 5 A 51.4
16 6 A 46.4
17 6 A 44.8
18 6 A 49.2
19 1 B 62.1
20 1 B 62.6
21 1 B 64.0
22 2 B 59.7
23 2 B 60.0
24 2 B 59.0
25 3 B 68.6
26 3 B 65.8
27 3 B 69.7
28 4 B 63.2
29 4 B 62.8
30 4 B 62.2
31 5 B 64.8
32 5 B 65.0
33 5 B 65.4
34 6 B 43.7
35 6 B 44.2
36 6 B 43.0
37 1 C 67.5
38 1 C 67.2
39 1 C 66.9
40 2 C 61.5
41 2 C 61.7
42 2 C 62.3
43 3 C 70.8
44 3 C 70.6
45 3 C 71.0
46 4 C 64.1
47 4 C 66.2
48 4 C 64.0
49 5 C 72.1
50 5 C 72.0
51 5 C 71.1
52 6 C 62.0
53 6 C 61.4
54 6 C 60.5
R> "Machines" <- # only change is position of
"row.names" and "class" attributes
+ structure(list
+ (Worker = structure(ordered(c(4, 4, 4, 2, 2, 2,
+ 5, 5, 5, 3, 3, 3, 6, 6, 6, 1, 1, 1, 4, 4, 4, 2, 2, 2, 5, 5, 5,
+ 3, 3, 3, 6, 6, 6, 1, 1, 1, 4, 4, 4, 2, 2, 2, 5, 5, 5, 3, 3, 3,
+ 6, 6, 6, 1, 1, 1), levels=1:6), class = c("ordered",
"factor"),
+ .Label = c("6", "2", "4", "1",
"3", "5")),
+ Machine = structure(factor(c(1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), levels=1:3), class =
"factor",
+ .Label = c("A", "B", "C")),
+ score = c(52, 52.8,
+ 53.1, 51.8, 52.8, 53.1, 60, 60.2, 58.4, 51.1, 52.3, 50.3, 50.9,
+ 51.8, 51.4, 46.4, 44.8, 49.2, 62.1, 62.6, 64, 59.7, 60, 59, 68.6,
+ 65.8, 69.7, 63.2, 62.8, 62.2, 64.8, 65, 65.4, 43.7, 44.2, 43,
+ 67.5, 67.2, 66.9, 61.5, 61.7, 62.3, 70.8, 70.6, 71, 64.1, 66.2,
+ 64, 72.1, 72, 71.1, 62, 61.4, 60.5)),
+ row.names = 1:54,
+ class = c("nffGroupedData", "nfGroupedData",
"groupedData", "data.frame"),
+ formula = score ~ 1 | Worker,
+ labels = list(y = "Productivity score"),
+ inner = ~ Machine)
R> Machines
Grouped Data: score ~ 1 | Worker
Process R segmentation fault at Mon Mar 23 09:14:43 1998
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Douglas Bates <bates@stat.wisc.edu> writes:> R> Machines > Grouped Data: score ~ 1 | Worker > > Process R segmentation fault at Mon Mar 23 09:14:43 1998in 0.61.2, this behaves differently:> MachinesGrouped Data: score ~ 1 | Worker Error: attempt to type-coerce non-vector In both cases, that is. However, applying print.data.frame directly or indirectly by removing the print method, on the structures gives a print of the data frame in the 1st case and a segfault in the 2nd. A quick tour into the debugger show that it dies trying to do CHAR(x[i]) with x[0] == 1, -- and x[1] == 2, etc. Methinks that row.names<-as.character(1:54) might help! However, one should probably also do the explicit coercion of rownames to character in printDataFrame... But where did the type-coerce error come from? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard writes:>>row.names<-as.character(1:54) might help!Yes, that does help. ... 478 PROTECT(rl = getAttrib(x, install("row.names"))); .... 545 if (!isNull(rl)) formatString(STRING(rl), r, &rlabw, 0); I guess if row.names are not strings, then the above line causes seg fault. Somehow in the first example they are coerced into strings because they came after c("xxx" , ...). In the second example row.names comes after c(2 , ...) . Is there a way to check to see it rl contains strings? Osman -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The PROTECT macro has to do with protecting an internal object from the garbage collector. SEXP x; /* x is an s-expression */ /* i.e. an R object of some sort */ x = allocate an object PROTECT(x) ... UNPROTECT(x) Every PROTECTED object must be UNPROTECTed before you exit from the current function. The interpreter keeps track of how may pointers are protected at entry and checks that this is the same at exit. I am hoping that medium term we will be able to switch from our home-grown garbage-collector to the Boehm conservative collector. This should fix all sorts of problems, but there are a couple of save/restore problems which need to fixed before that. Ross -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Well, it wasn't in dataframe.c, but in attrib.c file function rownamesgets! coerceVector( , STRSEXP) was already there but due to if(isFrame(vec)) line was not getting executed. I moved the "If(isFrame..." line to right after PROTECT(val) (3 lines down). Now it works :-). At least as far as running the test code. I don't know why isFrame(vec) was returning false. We are reading in a data frame. Osman -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._