是否可以使用readr中的write_csv()编写stdout?
发布时间:2020-12-15 17:03:11 所属栏目:安全 来源:网络整理
导读:我正在使用bash通过Rscript管道数据,如下所示: cat random.csv | Rscript test.R arg | delete.csv 我的目标是使用R包读取器来读取stdin和写入stdout.我找到了answer to stdin here. test.R #!/usr/bin/RscriptsuppressMessages(library(readr))args - comm
我正在使用bash通过Rscript管道数据,如下所示:
cat random.csv | Rscript test.R arg> | delete.csv 我的目标是使用R包读取器来读取stdin和写入stdout.我找到了answer to stdin here. test.R #!/usr/bin/Rscript suppressMessages(library(readr)) args <- commandArgs(trailingOnly = TRUE) df.in <- read_csv(file("stdin")) write_csv(df.in,path = stdout()) 上面的代码在命令行中生成以下错误消息: 错误信息 Error in path.expand(path) : invalid 'path' argument Calls: write_csv -> write_delim -> normalizePath -> path.expand Execution halted 我还尝试了write_csv(df.in,file(“stdout”))和write_csv(df.in,stdout()),产生相同的错误消息. 为了重现性,这里是random.csv的链接 Definition of variables,by WHO for the Global Tuberculosis Report [43kb]
readr中有一个format_csv函数.使用它而不是write_csv:
cat(format_csv(df.in)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |