Hi, I'm trying to make sense of the output of getParseData(). The "parent" column is supposed to refer to the "id" of the parent of the given item, but there are numbers in the parent column that do not exist in the id column. Example:
> p <- parse(text="f<-function(){if(TRUE)1 else 2}") > df <- getParseData(p) > df line1 col1 line2 col2 id parent token terminal text 29 1 1 1 31 29 30 expr FALSE 1 1 1 1 1 1 3 SYMBOL TRUE f 3 1 1 1 1 3 29 expr FALSE 2 1 2 1 3 2 29 LEFT_ASSIGN TRUE <- 28 1 4 1 31 28 29 expr FALSE 4 1 4 1 11 4 28 FUNCTION TRUE function 5 1 12 1 12 5 28 '(' TRUE ( 6 1 13 1 13 6 28 ')' TRUE ) 25 1 14 1 31 25 27 expr FALSE 7 1 14 1 14 7 25 '{' TRUE { 22 1 15 1 30 22 23 expr FALSE 8 1 15 1 16 8 22 IF TRUE if 9 1 17 1 17 9 13 '(' TRUE ( 10 1 18 1 21 10 11 NUM_CONST TRUE TRUE 11 1 18 1 21 11 13 expr FALSE 12 1 22 1 22 12 13 ')' TRUE ) 14 1 23 1 23 14 15 NUM_CONST TRUE 1 15 1 23 1 23 15 17 expr FALSE 16 1 25 1 28 16 22 ELSE TRUE else 18 1 30 1 30 18 19 NUM_CONST TRUE 2 19 1 30 1 30 19 21 expr FALSE 20 1 31 1 31 20 25 '}' TRUE } The following numbers occur in the parent column but not the id column: [1] 30 27 23 13 17 21 What I'm trying to do is determine the length (in lines) of every function in a source file using the getParseData() information. I can see that the opening and closing curly braces of my test function have the same parent (25), but 25 has the parent 27, which does not occur in the id column. I realize that my function is all on one line, and not all functions have opening and closing curly braces, but I'd still like to understand what's going on here.... What does it mean when an item's parent does not exist in the id column? Thanks, Dan > sessionInfo() R Under development (unstable) (2013-10-18 r64076) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel