我一直试图在R中使用xmstarlet,而不是在bash中运行我的xmlstarlet脚本,然后将其输送到R,但我尝试过的一切都没有奏效。我甚至不确定这是否可能。
我试过这个:
shell(cmd=(xmlstarlet sel -t -c "someinput"), intern=TRUE)仅bash中的命令就能工作,但是当我尝试这样做时,我会得到以下错误:
Error: unexpected symbol in "shell(cmd=(xmlstarlet sel"我不太确定是否应该使用system()而不是shell。我也用过系统,但没有成功
编辑:
完整的命令示例,也可以找到带有完整xml文件的here。
xmlstarlet sel -t -m "/bookstore/book/Description" -i "@stock='YES'" -v '/bookstore/book/Location/shelf'发布于 2016-05-30 10:05:44
将命令保存为字符向量,并使用system
cmd <- "xml el http://stackoverflow.com"
system(command = cmd, intern = T)这给了我
http://stackoverflow.com:12.163: EntityRef: expecting ';'
/cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded&a
^
[1] "html" "html/head" "html/head/title"
[4] "html/head/link" "html/head/link/link" "html/head/link/link/link"
[7] "html/head/link/link/link/meta"
attr(,"status")
[1] 4如果在xmlstarlet命令中使用双引号,则必须使用反斜杠将它们转义。使用添加到问题中的示例:
cmd <- "xmlstarlet sel -t -m \"bookstore/book\" -i \"Description/stock='YES'\" -v \"Location/shelf\" -n /PATH/TO/books.xml"
system(command = cmd, intern=T)输出:
[1] "30" "21" "11"https://stackoverflow.com/questions/37522281
复制相似问题