R appears to fail to execute a line in a function [duplicate]

时光毁灭记忆、已成空白 提交于 2020-01-26 02:09:17

问题


I'm a bit puzzled. I have a created a custom function:

doGraph <- function(x){
dev.new();
symb <- getSymbols(x, auto.assign = FALSE);
chartSeries(symb, subset = 'last 3 months', name=x);
addBBands();
addMACD();
}
doGraph("AAPL")

The above code does not add the Bollinger Bands, as I would expect (by the addBBands() call). However, if I remove the addMACD() call, the bands are added as expected. Additionally, if I type addBBands() after the function call, the bands are added. Does anyone have any thoughts on what could be going wrong here? Thanks!


回答1:


Wrap plot around your add* calls

doGraph <- function(x){
  dev.new()
  symb <- getSymbols(x, auto.assign = FALSE)
  chartSeries(symb, subset = 'last 3 months', name=x)
  plot(addBBands())
  plot(addMACD())
}
doGraph("AAPL")


来源:https://stackoverflow.com/questions/18342703/r-appears-to-fail-to-execute-a-line-in-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!