I'm using bash
to pipe data through an Rscript
like so:
cat random.csv | Rscript test.R arg >| delete.csv
My aim is to use the R
package readr
to both read stdin and write stdout. I found the 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())
The above code produces the following error message at the command line:
Error Message
Error in path.expand(path) : invalid 'path' argument
Calls: write_csv -> write_delim -> normalizePath -> path.expand
Execution halted
I have also tried write_csv(df.in, file("stdout"))
and write_csv(df.in, stdout())
producing the same error message.
For reproducibility, here's a link to a random.csv
Definition of variables, by WHO for the Global Tuberculosis Report [43kb]