Closed mhtess closed 8 years ago
We can suppress the "incomplete final line" warning by adding the warn = F
option to the readLines
call:
output_string <- paste(readLines(output_file, warn = F), collapse = "\n")
The issue there is that readLines keep reading until it hits an EOL
marker. If you don't include a final new line, there's no marker, so the function is surprised to hit the end of input.
I'm afraid I can't replicate your returnify error, though.
So passing inference to files is working for you? Erin was getting a similar error as mine (I think...)
Yes, the example you have above is working as expected, and other examples worked too (e.g. changing the distributions in the model, changing inference parameters, etc.)
Cannot reproduce the error.
FWIW, I did reproduce this error, but it's not really an rwebppl error.
It doesn't seem to me like it's actually problematic. Here's a minimal example. Basically, if the webppl file doesn't have a return value, then webppl.js won't be able to do anything with it. But if it does have a return value, then it will return either that return value or whatever model_var and inference_opts ask for. (I think this is all true.)
The following should reproduce the returnify error if you comment out the last line of the webppl file:
#error-test.R
library(rwebppl)
## runs and takes the output of the webppl program as its value
numbers = webppl(program_file = 'error-test.wppl')
## runs *if there's an output* and takes the result of desired inference.
## otherwise throws returnify error.
numbers = webppl(program_file = 'error-test.wppl',
model_var = 'model',
inference_opts = list(method='enumerate'))
#error-test.wppl
var model = function() {
return flip(); // ? RParams.a : 2;
};
var apples = function() {
return 200;
};
// if the following line is commented out, we'll get the returnify error.
"finished";
Passing inference options to model works when program is a string but not when it's a file.
Works when program is a string. When it is a file
meaning that there is no last line of the program to return
Also, strangely, when you write a model in a program and the last line of the program is NOT white space, you get the following warning: