1

When I call chart_Series from a script I get a blank, white graphics device only. Example code:

Lines <- "2018-01-02;2683.73;2695.89;2682.36;2695.81
2018-01-03;2697.85;2714.37;2697.77;2713.06
2018-01-04;2719.31;2729.29;2719.07;2723.99
2018-01-05;2731.33;2743.45;2727.92;2743.15
2018-01-08;2742.67;2748.51;2737.60;2747.71
2018-01-09;2751.15;2759.14;2747.86;2751.29"

a <- as.xts (read.csv2.zoo (text = Lines,
    col.names = c("Date", "Open", "High", "Low", "Close"),
    header=F, stringsAsFactors = F, dec = ".", FUN = as.POSIXct))

chart_Series (a)

When I call "chart_Series (a)" on the R console it runs fine.

What's the issue with sourced chart_Series?

packageVersion("quantmod") [1] '0.4.13'

tom9
  • 25
  • 2
  • Does chartSeries() function work for you. The one you are using chart_Series() is marked as highly experimental. Also could you attach a few first lines to your read.cs2.zoo file? – Katia Apr 30 '18 at 16:38
  • When I replace "chart_Series (a)" by "chartSeries (a)" and "addTA (Cl (a), type="p", pch=18, col = 'black', on = 1, cex = 2)" it plots the chart, but ignores addTA when sourced from a file. addTA also only works from console. But I want to draw a chart and (conditionally) some indicators from a script. Why should I "attach a few first lines" more? The sample data (Lines) is not relevant to the issue in question. – tom9 May 01 '18 at 22:43
  • Sorry about the data - your input is sufficient. I explored this in more details and can confirm that this is indeed a bug in the chart_Series() function. I copied the source of the function in my own file and named it myreplot.R and named the function myreplot(). Then I sourced that function and tried to use it instead of chart_Series() and it did not work. I confirmed that my workflow correct by going to the function and replacing their plot with my own and everything worked fine. They are using cs <- new.replot() and then fill cs object with properties. Somewhere there is mistake there. – Katia May 01 '18 at 23:10

1 Answers1

0

As authors of this package stated in their documentation, the function is highly experimental. Looking at their source code they are using their new new.replot() function and fill it with some environment parameters. Environment within source() function however is different from when the function is called directly and it looks like it causes problems in this case.

Here are some notes from github where they explain that they had a bug with tracing local variables. However they did not address the same issue with .plotEnv variable they are using in their function https://github.com/joshuaulrich/quantmod/commit/427e68a6c2f1997ce477f2bacd3ed54913b585fe

I would recommend to submit a bug report to the author of the package

Katia
  • 3,784
  • 1
  • 14
  • 27