如何使用 R 中的管道函数来命令 GNUPlot?

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

如何使用 R 中的 pipe() 通过管道调用 gnuplot 来绘制以下内容?

set terminal latex
set output "eg1.tex"
plot [-3.14:3.14] sin(x)

我不知道如何在 R 中使用管道。

你可以用 systempipe 做同样的事情:

# 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)

您应该在当前工作目录中看到 eg1.tex

它也适用于换行符:

cat('set terminal latex
set output "eg1.tex"
plot [-3.14:3.14] sin(x)',
    file=gp)