Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot function cause R to crash for no particular error message #50

Open
stucash opened this issue Jul 15, 2021 · 3 comments
Open

Plot function cause R to crash for no particular error message #50

stucash opened this issue Jul 15, 2021 · 3 comments

Comments

@stucash
Copy link

stucash commented Jul 15, 2021

I was commenting under another crash related issue but found out mine eventually was a different story.

I am running R 4.1 in MX linux 19.04, with the package version being 1.2.7.

I have attached the test data as well, which is 900 rows of stock daily OHLCV data.
spce.csv

fin.ci <- function(data, interv.date, period="other", extend=F, range=c(5,9)){

  from <- range[1]
  to <- range[2]
  
  if (identical(period, "daily")){
    start <- ymd(interv.date) - days(from)
    end <- ymd(interv.date) + days(to) 
    pre.interv <- ymd(interv.date) - days(1)
    pre.period <- c(start, ymd(pre.interv))
    post.period <- c(ymd(interv.date), end)
    dat.xts <- xts(data$close, order.by = ymd(data$date))
  }else{
    start <- ymd_hms(interv.date) - days(from)
    end <- ymd_hms(interv.date) + days(to) + hours(5) + minutes(59)
    pre.interv <- ymd_hms(interv.date) - days(1) + ifelse(extend, hours(6), hours(5))
    pre.period <- c(start, ymd_hms(pre.interv))
    post.period <- c(ymd_hms(interv.date), end)
    dat.xts <- xts(data$close, order.by = ymd_hms(data$date))
  }
  res <- CausalImpact(dat.xts, pre.period, post.period)
  summary(res)
  plot(res)
}

I can run through to summary(res). The output from summary(res):

Posterior inference {CausalImpact}

                         Average      Cumulative 
Actual                   25           200        
Prediction (s.d.)        17 (0.28)    133 (2.23) 
95% CI                   [16, 17]     [128, 137] 
                                                 
Absolute effect (s.d.)   8.4 (0.28)   67.2 (2.23)
95% CI                   [7.9, 9]     [63.1, 72] 
                                                 
Relative effect (s.d.)   51% (1.7%)   51% (1.7%) 
95% CI                   [48%, 54%]   [48%, 54%] 

Posterior tail-area probability p:   0.00102
Posterior prob. of a causal effect:  99.89837%

For more details, type: summary(impact, "report")

It seems the new pull request could fix it, but I thought it's probably better to still flag it up.

Thanks Team.

@alhauser
Copy link
Collaborator

Can you provide a function call that leads to the crash? I can't reproduce a crash.

Tested:

library(CausalImpact)

test_data <- read.table("spce.csv", sep = ",", header = TRUE)
fin.ci(dat, "2021-05-28", period = "daily")

This works.

Note that the function fin.ci() itself produces an error if period is different from "daily" because the variable extend (argument to ifelse()) is not defined.

@stucash
Copy link
Author

stucash commented Jul 15, 2021

Can you provide a function call that leads to the crash? I can't reproduce a crash.

Tested:

library(CausalImpact)

test_data <- read.table("spce.csv", sep = ",", header = TRUE)
fin.ci(dat, "2021-05-28", period = "daily")

This works.

Note that the function fin.ci() itself produces an error if period is different from "daily" because the variable extend (argument to ifelse()) is not defined.

I have edited the function sorry I thought extend was irrelevant; I added it back now in the function signature.

The call that led to crash was just that plot(res).

I am experiencing crash with ggplot2 now as well; my gut feeling is that I might have messed up some base R plotting libraries (which is highly unlikely though......)? I am not sure whether this is a valid issue for this package any more. If you guys can't reproduce it in any environment it should be a safe close.

@alhauser
Copy link
Collaborator

I have edited the function sorry I thought extend was irrelevant; I added it back now in the function signature.

Thanks.

The call that led to crash was just that plot(res).

I meant, what call of fun.ci() crashes? Which arguments do you have to provide to fun.ci() to cause the crash in plot(res) within that function?

I am experiencing crash with ggplot2 now as well; my gut feeling is that I might have messed up some base R plotting libraries (which is highly unlikely though......)? I am not sure whether this is a valid issue for this package any more. If you guys can't reproduce it in any environment it should be a safe close.

OK. Maybe try updating all packages to the latest version and see if the error persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants