rstan 2.8.0 giving readRDS() error

780 views
Skip to first unread message

eric....@noaa.gov

unread,
Sep 29, 2015, 7:01:59 PM9/29/15
to Stan users mailing list
Hello,

I'm using rstan version 2.8.0 (installed from CRAN) in RStudio and getting a strange error message that I've never seen in previous versions. What's particularly odd is that everything was working fine for a while -- I was fitting models with no problems and trying to wrap my head around the switch from base graphics to ggplot. I have no idea what caused this change, but now I get the following behavior every time I call stan(), illustrated here with the 8schools example:

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.2.2
> library(rstan)
Loading required package: Rcpp
Loading required package: ggplot2
rstan (Version 2.8.0, packaged: 2015-09-19 14:48:38 UTC, GitRev: 05c3d0058b6a)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
> schools_dat <- list(J = 8, 
+                     y = c(28,  8, -3,  7, -1,  1, 18, 12),
+                     sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
> 
> fit <- stan(file = '8schools.r', data = schools_dat, 
+             iter = 1000, chains = 4)
Error in readRDS(file.rda) : unknown input format

It looks like file.rda is just a character string giving the file path of the 8schools.r model file. (Incidentally, I use the .r extension so the RStudio editor will recognize it, but the same thing happens if I change it to .stan.) When I open 8schools.r it looks exactly the same as it did earlier, before this problem started. I've tried restarting R, uninstalling and reinstalling rstan, and deleting all the temp dir files that rstan seems to be writing to.

Any suggestions would be greatly appreciated.

Ben Goodrich

unread,
Sep 29, 2015, 7:58:03 PM9/29/15
to Stan users mailing list
On Tuesday, September 29, 2015 at 7:01:59 PM UTC-4, eric....@noaa.gov wrote:
Any suggestions would be greatly appreciated.

I think the problem is that stan() presumes the filename has a .stan extension. It will probably work again if you just delete any .rda files from the directory that 8schools.stan is in. Also, the most recent versions of RStudio recognize a file with a .stan extension, do some limited source highlighting, and suggest reserved words in the Stan language.

Ben

eric....@noaa.gov

unread,
Sep 29, 2015, 8:53:10 PM9/29/15
to Stan users mailing list
Hi Ben,

Thanks for the speedy reply. You may well be right, but if so I don't understand why I was able to successfully call stan() with model files ending in .r, including 8schools.r, up until "something went wrong". I also don't understand why I got the same behavior when I changed the model filename to 8schools.stan, as I mentioned in the OP. Maybe it has something to do with these .rda files you mention, but I didn't see any of those when I looked at the working directory. Is this requirement for model filename extensions new in version 2.8.0? Because I've always used model files with the .r extension, and I've never gotten this error in any previous version of Stan.

I can't try this again until tomorrow morning, but I'll let you know if your suggestion works then.

Thanks,
Eric

James Savage

unread,
Sep 30, 2015, 2:21:13 AM9/30/15
to Stan users mailing list
Hi all - 

I was having the same issue; moved the files to a new folder and changed the file extension to .stan and now it's working. 

Thanks, Jim

eric....@noaa.gov

unread,
Sep 30, 2015, 2:32:56 AM9/30/15
to Stan users mailing list
Interesting. Do you have any idea why moving to a new folder helped? Were there some temp files in the original folder that you deleted or didn't move? Like I said, I haven't seen anything with an .rda extension in the working directory I'm using, so...[shrugs].

I'll try this tomorrow and hopefully it'll fix the problem.

Thanks,
Eric

James Savage

unread,
Sep 30, 2015, 2:44:11 AM9/30/15
to Stan users mailing list
I'm afraid I made both changes at the same time so can't identify which change worked. There were a few .RData files in the original folder. 

eric....@noaa.gov

unread,
Sep 30, 2015, 12:36:25 PM9/30/15
to Stan users mailing list
Okay, well, now it looks like changing the model file extension to .stan does the trick, no directory move necessary. I'm truly baffled, though, because (1) I tried this very thing yesterday with no success and (2) I was running version 2.8.0 with .r model files for a while before it stopped working. If it's got something to do with temp files needing to be deleted or overwritten then I guess I've been looking for those in the wrong place. Oh well, I suppose I'll get over it. It does seem like it would be good to have this (new, apparently) file naming requirement stated explicitly in the help page for stan() under the file argument.

Thanks to Ben and James for the help!

James Savage

unread,
Sep 30, 2015, 10:32:10 PM9/30/15
to Stan users mailing list
FWIW, I had problems with changing the extensions in mac. It automatically hides file extensions. So my original file, which was mymodel.cpp got changed to mymodel.stan.cpp (although in the finder it looked like mymodel.stan). Going to file info -> show extension and changing it from there did the trick. 
Reply all
Reply to author
Forward
0 new messages