3

add_TA 関数 (quantmod パッケージ) の現在のサブチャートを設定できません。

curon = 2

add_TA(x, type = "l",col = "blue", lwd = 2, on=curon)

(サブチャート 2 に線を追加)

Rは私にこのエラーを与えています:

Error in plot_ta(x = current.chob(), ta = get("x"), on = curon, taType = NULL,  : 
 object 'curon' not found.

コマンド:

add_TA(x, type = "l",col = "blue", lwd = 2, on=2) 

しかし、正常に動作します。

注: この問題は、グローバル スコープではなく、関数で使用された場合にのみ発生します。完全な例を次に示します。

library(quantmod)

test=function(){
x=xts(runif(10),Sys.Date()+1:10)
z=1/x
chart_Series(x)
add_TA(x, type = "l",col = "green", lwd = 2)    #OK
add_TA(z, type = "l",col = "blue", lwd = 2, on=2)   #OK
curon = 2;add_TA(z, type = "l",col = "red", lwd = 2, on=curon)  #FAILS
}

test()
4

1 に答える 1

3

I think you must have a typo somewhere, in code you've not shown, as it works for me:

library(quantmod)
x=xts(runif(10),Sys.Date()+1:10)
z=1/x

chart_Series(x)
add_TA(x, type = "l",col = "green", lwd = 2)
curon = 2
add_TA(z, type = "l",col = "blue", lwd = 2, on=curon)

(By the way, this is what people mean by a "fully reproducible minimal example"; something you can copy and paste into a fresh R session. Unless it matters for your question, the data can be random.)

UPDATE: Having reproduced the problem when using a function, I did find a workaround (for what I think is a quantmod bug). If you name your variable on instead of curon then it works:

library(quantmod)

test=function(){
x=xts(runif(10),Sys.Date()+1:10)
z=1/x
chart_Series(x)
add_TA(x, type = "l",col = "green", lwd = 2) 
on=2;add_TA(z, type = "l",col = "blue", lwd = 2, on=on)
}
于 2012-04-29T00:22:14.760 に答える