从控制台执行与从 TextMate 执行时,R quantmod 包的行为不同

发布于 2024-10-06 14:26:25 字数 707 浏览 6 评论 0原文

代码如下:

require("quantmod")

getSymbols("GLD") 
getSymbols("SLV")
getSymbols("TLT")

GSR = GLD/SLV

par(mfrow=c(2,2))

chartSeries (GLD, subset="2010", TA = NULL)               
chartSeries (SLV, subset="2010", TA = NULL)               
chartSeries (TLT, subset="2010", TA = NULL)               
chartSeries (GSR, subset="2010", TA = NULL)

当我使用 Command R 按键从 TextMate 运行此文件时,我得到了四个排列在 2 x 2 网格中的图表,正如您对 par() 函数所期望的那样。当我从 R 控制台获取此数据时,

> source("~/myChartSeries.r")

我会看到每个图表的闪现,其中最后一个图表被单独描绘。我最后一次听到的说法是,chartSeries() 与 par() 函数不兼容,但 Chart_Series() 是。所以控制台的行为并不奇怪。但为什么 TextMate 的执行能起作用呢? ChartSeries() 是否已与 par() 兼容并且 R 控制台执行是否存在缺陷?

Here is the code:

require("quantmod")

getSymbols("GLD") 
getSymbols("SLV")
getSymbols("TLT")

GSR = GLD/SLV

par(mfrow=c(2,2))

chartSeries (GLD, subset="2010", TA = NULL)               
chartSeries (SLV, subset="2010", TA = NULL)               
chartSeries (TLT, subset="2010", TA = NULL)               
chartSeries (GSR, subset="2010", TA = NULL)

When I run this file from TextMate with the Command R keystroke, I get four charts lined up in a 2 x 2 grid, as you'd expect from the par() function. When I source this from the R console,

> source("~/myChartSeries.r")

I get a flash of each chart with the last one depicted alone. The last I'd heard, chartSeries() was not compliant with the par() function but chart_Series() is. So the behavior of the console is not surprising. But why does execution from TextMate work? Has chartSeries() been made par() compliant and is the R console execution flawed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2024-10-13 14:26:25

当代码从 TextMate 运行时,它会分别打印所有四个图表,并产生“错觉”,认为它是具有四个面板的单个图表。事实上,当我注释掉 par() 函数时,

#par(mfrow=c(2,2))

我得到了相同的结果。所以看来 ChartSeries() 仍然不符合 par() 标准。

When the code is run from TextMate, it prints all four charts separately with the 'illusion' that it is a single chart with four panels. In fact, when I comment out the par() function,

#par(mfrow=c(2,2))

I get the same result. So it appears that chartSeries() is still not par() compliant.

风轻花落早 2024-10-13 14:26:25

这对我来说无论在哪个位置都适用:

layout(matrix(seq(4), nrow=2))

chartSeries (GLD, subset="2010", TA = NULL, layout=NULL)               
chartSeries (SLV, subset="2010", TA = NULL, layout=NULL)               
chartSeries (TLT, subset="2010", TA = NULL, layout=NULL)               
chartSeries (GSR, subset="2010", TA = NULL, layout=NULL)

希望这有帮助。

this works for me from either location:

layout(matrix(seq(4), nrow=2))

chartSeries (GLD, subset="2010", TA = NULL, layout=NULL)               
chartSeries (SLV, subset="2010", TA = NULL, layout=NULL)               
chartSeries (TLT, subset="2010", TA = NULL, layout=NULL)               
chartSeries (GSR, subset="2010", TA = NULL, layout=NULL)

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文