google / CausalImpact

An R package for causal inference in time series
Apache License 2.0
1.71k stars 254 forks source link

Error in parse(text = x, keep.source = FALSE) : <text>:1:9: unexpected symbol #35

Closed AlexSiormpas closed 3 years ago

AlexSiormpas commented 5 years ago

I apply casual impact with the following code impact <- CausalImpact(SynthTS, pre.period, post.period, model.args = list(niter = 5000, nseasons = 7, season.duration = 1, dynamic.regression=FALSE))

but I hit the following error:

Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:9: unexpected symbol
1: My Column
                    ^

For debugging my SynthTS is a zoo object:

> str(SynthTS)
‘zoo’ series from 2016-07-01 to 2019-10-30
  Data: num [1:1217, 1:7] 0 66.4 49.7 10 76.9 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:7] "My Column" "My Column2" "My Column3" "My Column4" ...
  Index:  Date[1:1217], format: "2016-07-01" "2016-07-02" "2016-07-03" "2016-07-04" "2016-07-05" "2016-07-06" "2016-07-07" "2016-07-08" "2016-07-09" "2016-07-10" "2016-07-11" ...

Can it be an issue that my column names have a space inside?

alhauser commented 3 years ago

A space should be fine (although it's better to avoid for readability), but there might be yet another special character (a tab or similar?) that causes this. Sticking to column names that are also valid variable names in R will solve the issue.