1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
readMetlin =
function(url = "http://metlin.scripps.edu/download/MSMS_test.XML",
what = c("molid" = "integer", name = "character", formula = "character", mass = "numeric", mz = "numeric"))
{
doc = xmlTreeParse(url, useInternal = TRUE)
z = xmlChildren(xmlRoot(doc))
nodes = z[ sapply(z, inherits, "XMLInternalElementNode") ]
if(length(nodes) > 1) {
}
nodes = nodes[[1]]
n = xmlSize(nodes)
ans = as.data.frame(lapply(what, function(x) get(x)(n)))
for(i in 1:n) {
node = nodes[[i]]
sapply(names(what),
function(id) {
ans[i, id] <<- as(xmlValue(node[[id]]), what[id])
})
}
ans
}
|