Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use pipe function in R to command GNUPlot?

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.

like image 815
Ash Avatar asked Aug 27 '26 06:08

Ash


1 Answers

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)
like image 121
hrbrmstr Avatar answered Aug 29 '26 00:08

hrbrmstr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!