【发布时间】:2013-04-25 11:09:52
【问题描述】:
更新:感谢 Joshua 的评论,我意识到问题不在函数内部,而是在脚本内部。所以我编辑了问题并提供了我自己的答案。
当我以交互方式使用plot.xts() 时,它会弹出一个图形窗口。我只是从一个函数内部尝试了它(我正在对单元测试进行故障排除并需要一些视觉帮助)但没有出现任何内容。啊哈,我说,我知道诀窍,只需使用print。
但是print(plot.xts(x)) 仍然没有显示图表,而是打印我的 xts 对象! IE。它与print(x) 完全相同。
我用来运行单元测试的脚本是:
#!/usr/bin/Rscript --slave
library('RUnit')
options(warn=2) #Turn warnings into errors
#By naming the files runit.*.R, and naming the functions test*(), we can use
# all the defaults to defineTestSuite().
#NOTE: they have a weird default random number generator, so changed here
# to match the R defaults instead.
test.suite=defineTestSuite('tests',dirs=file.path('tests'),
rngKind = "Mersenne-Twister", rngNormalKind = "Inversion")
test.result <- runTestSuite(test.suite)
printTextProtocol(test.result)
【问题讨论】:
-
你能提供一个可重现的例子吗?这对我有用:
f <- function(x) plot(x); f(.xts(1:10,1:10)). -
谢谢约书亚;你的例子对我有用。我明天会对此进行调查,然后可能会改写或删除这个问题:我敢打赌这与我如何运行单元测试有关。