How can I use pipe() in R to draw the following by calling gnuplot through that pipe?
set terminal latex
set output "eg1.tex"
plot [-3.14:3.14] sin(x)
I can't figure out how to use pipes in R.
You can do the same thing that system is doing with pipe:
# set up pipe for writing
gp <- pipe('gnuplot','w')
# send some data to it
cat('set terminal latex; set output "eg1.tex"; plot [-3.14:3.14] sin(x)',
file=gp)
# close the connection
close(gp)
You should see eg1.tex in the current working directory.
It will work with newlines as well:
cat('set terminal latex
set output "eg1.tex"
plot [-3.14:3.14] sin(x)',
file=gp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With