https://github.com/cran/XML
Tip revision: 3cc154f91cacaa5bc05a347c841f07984b5a28a6 authored by CRAN Team on 22 January 2024, 13:30:59 UTC
version 3.99-0.16.1
version 3.99-0.16.1
Tip revision: 3cc154f
metlin.R
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
}