如何在r中重定向系统命令及其输出?
我正在使用如何在r中重定向系统命令及其输出?,r,R,我正在使用system命令查找ubuntu上的文件,并尝试将屏幕上的结果重定向到一个txt文件,如下例所示 # make file system("touch a.txt") system("touch b.txt") system("touch c.txt") system("touch d.txt") sink("t.txt") c("a.txt", "b.
system
命令查找ubuntu
上的文件,并尝试将屏幕上的结果重定向到一个txt文件,如下例所示
# make file
system("touch a.txt")
system("touch b.txt")
system("touch c.txt")
system("touch d.txt")
sink("t.txt")
c("a.txt", "b.txt")%>% lapply(function(f) {
system(sprintf("find -name %s", f))
})
sink()
但结果是一个包含O的列表。
请告诉我如何才能做到这一点。谢谢。您可以使用
intern=TRUE
选项,将系统
结果直接返回到R
环境中:
c("a.txt", "b.txt" , "test.txt") %>% lapply(function(f) {
system(sprintf("find -name %s", f), intern = T)
})
[[1]]
[1] "./a.txt"
[[2]]
[1] "./b.txt"
[[3]]
character(0)
这回答了你的问题吗?这似乎也是相关的,谢谢。我之前看过这篇文章。不幸的是,我只得到了一个包含空元素的列表。