Virus warning

I encountered a very bizarre error warning while running my code in a loop to do simulations. My code worked normally without error for some time before this suddenly happened.

Here is my R code:

stan.fit.mod4 <- stan(
    file = "Orchid Stan Code NegBinNoInt v3c.stan",  # Stan program
    data = list(Y = dat_poi_int_list[[j]],
                N = nrow(dat_poi_int_list[[j]]),
                S = ncol(dat_poi_int_list[[j]]),
                prior_only = F),    # named list of data
    chains = 4,             # number of Markov chains
    warmup = 1000,          # number of warmup iterations per chain
    iter = 3000,            # total number of iterations per chain
    cores = 4,              # number of cores (could use one per chain)
    control = list(adapt_delta=0.99,max_treedepth=12),
    init = "0"
    #  refresh = 0             # no progress shown
  ) 

Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: unable to load shared object ‘C:/Users/NELSJO~1/AppData/Local/Temp/RtmpeU0891/file3e0849571322.dll’:
LoadLibrary failure: Operation did not complete successfully because the file contains a virus or potentially unwanted software.

Any ideas on how to fix this issue or what has caused it?

Hi Nels, that’s very strange, thanks for letting us know. I definitely don’t think there’s a virus (or at least it didn’t come from RStan if you actually do have a virus), so I don’t know why you’re getting this message. According to https://ugetfix.com/ask/how-to-fix-operation-did-not-complete-successfully/:

There are three possible reasons you are seeing the Operation did not complete successfully error:
-The executable you just downloaded is actually infected with malware;
-Windows Defender or other security software is set to a maximum protection mode;
-It is a false-positive scan result from the AV vendor;

although I don’t know how reliable that site it.

One thing you can try is switching from using the stan() function to using stan_modlel() and sampling(), which does the same thing but splits it into a compile step and a sampling step. This is especially relevant when running RStan in a loop because of issues like this: Error in dyn.load(libLFile). It’s possible that something related to that error is also at play here although I’m not 100% sure.

So if you’re running RStan in a loop I would use stan_model() once to compile your model outside the loop, and then inside the loop you can use sampling() repeatedly. For example:

mod <- stan_model(file)
for (j in 1:J) {
  fit <- sampling(mod, data, chains, ...) # etc.
}
2 Likes

Thanks, Jonah. Your advice has seemed to resolve the issue (and speeds up my simulations!). I am going to leave this open for a few days just in case it happens again.

1 Like