"Ashley" == Ashley Ford <ford at signal.QinetiQ.com>
on Wed, 07 Feb 2007 17:18:56 +0000 writes:
Ashley> If I read in an .xml file eg with
>> xeg <- xmlTreeParse(system.file("exampleData", "test.xml",
package="XML"))
Ashley> It appears to be OK however examining it with str() gives an apparent
Ashley> error
Ashley> List of 2
Ashley> $ doc:List of 3
Ashley> ..$ file : list()
Ashley> .. ..- attr(*, "class")= chr [1:2] "XMLComment" "XMLNode"
Ashley> ..$ version :List of 4
Ashley> .. ..- attr(*, "class")= chr "XMLNode"
Ashley> ..$ children:Error in obj$children[[...]] : subscript out of bounds
Ashley> I am unsure if this is a feature or a bug and if the latter whether it
Ashley> is in XML or str, it is not causing a problem but I would like to
Ashley> understand what is happening, any ideas ?
Yes - thank you for providing a well-reproducible example.
After setting
options(error = recover)
I do
> obj <- xeg$doc
> mode(obj) # "list"
> obj[[3]] # ---> the error you see above.
Error in obj$children[[...]] : subscript out of bounds
Enter a frame number, or 0 to exit
1: obj[[3]]
2: `[[.XMLDocumentContent`(obj, 3)
Selection: 0
> obj$children # works, should be identical to obj[[3]]
$comment
<!--A comment-->
$foo
<foo x="1">
<element attrib1="my value"/>
......
This shows that the XML package implements the "[[" method
wrongly IMHO and also inconsistently with the "$" method.
From a strict OOP view, the XML author could argue that
this is not a bug in XML but rather str() which assumes that
x[[length(x)]] works for objects of mode "list" even when they
are not of *class* "list", but I hope he would still rather
consider changing [[.XMLDocumentContent ...