Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to read and write to C level stdin and stderr #106

Open
jimhester opened this issue May 13, 2019 · 3 comments

Comments

@jimhester
Copy link
Member

commented May 13, 2019

This is something that people working on the command line often want to do, e.g. https://stackoverflow.com/questions/9370609/piping-stdin-to-r

Unfortunately R makes this more difficult than other languages, as the stdin() and stdout() connections are text mode connections, and also do not really correspond to the C style connections of the same name.

At a minimum we should document this in the getting started vignette or another vignette.

But potentially we could provide a nicer interface that would make this more automatic.

@jimhester jimhester changed the title Handle reading from text connections Handle reading and writing with text connections May 13, 2019

@jimhester jimhester added the feature label May 13, 2019

@jimhester

This comment has been minimized.

Copy link
Member Author

commented May 13, 2019

cat inst/extdata/mtcars.csv | Rscript -e 'writeLines(vroom::vroom_format(vroom::vroom(file("stdin"))), stdout())' > blah

This is pretty ugly, file("stdin") we can deal with, but writeLines(vroom_format(x), stdout()) is really unfortunate.

@jimhester

This comment has been minimized.

Copy link
Member Author

commented May 13, 2019

Some more alternatives

This works, not sure on the potential overhead

cat inst/extdata/mtcars.csv | Rscript -e 'cat(vroom::vroom_format(vroom::vroom(file("stdin"))))

This is likely the most efficient, but it hangs if the output is not redirected, because I think R's REPL uses stdout. just file("/dev/stdout") alone hangs the process.

 cat inst/extdata/mtcars.csv | Rscript -e 'vroom::vroom_write(vroom::vroom(file("stdin")), file("/dev/stdout"))' > blah

@jimhester jimhester changed the title Handle reading and writing with text connections Handle reading and writing to C level stdin and stderr May 13, 2019

@jimhester jimhester changed the title Handle reading and writing to C level stdin and stderr Document how to read and write to C level stdin and stderr May 13, 2019

jimhester added a commit that referenced this issue May 24, 2019

@jimhester

This comment has been minimized.

Copy link
Member Author

commented May 24, 2019

As of 8077625 we can now use stdout() directly.

cat inst/extdata/mtcars.csv | Rscript -e 'vroom::vroom_write(vroom::vroom(file("stdin")), stdout())' > blah

So we should show this and also some discussion of the difference between stdin() and file("stdin") and why you need to use the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.