【问题标题】:How can I use pipe function in R to command GNUPlot?如何在 R 中使用管道函数来命令 GNUPlot?
【发布时间】:2015-07-02 00:26:20
【问题描述】:

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

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

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

【问题讨论】:

  • 为什么不能将这些命令写入临时文件并使用system
  • 你总是可以做system('echo \'set terminal latex; set output "eg1.tex"; plot [-3.14:3.14] sin(x)\' | gnuplot')
  • @hrbrmstr 我可以,但我想知道如何使用管道。感谢您的建议,尽管这不是我的问题的意思。

标签: r plot latex pipe gnuplot


【解决方案1】:

您可以做与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)

【讨论】:

  • 感谢您的回答。为了让它工作,我删除了 ; 否则我看不到输出(mac os x)。
猜你喜欢
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-12
相关资源
最近更新 更多