mhtess / rwebppl

RWebPPL, an R interface to Webppl http://webppl.org
22 stars 7 forks source link

Appropriately handle in-model console.log #2

Closed mhtess closed 8 years ago

mhtess commented 8 years ago

console.log calls within a webppl model will be written to standard output. When this gets passed into rwebppl.R, it should check to see if there was anything written before the final output. This can be done by putting special tags inside rwebppl binary that prints before the final output is printed.

mhtess commented 8 years ago

To "appropriately" handle this, we will need to figure out a way to pass messages from webppl to R as the webppl model is running. It's not a priori clear to me if this is possible, but it would be tremendously helpful. For example, in the case when there is an error in the factor statement and MCMC can't initialize, the model will just run indefinitely (or for a long time). With console.log statements inside, you could figure this out much earlier.

mhtess commented 8 years ago

Currently, we call webppl using system2(..., stdout=TRUE). This captures the output in a character vector, which we then parse. By default, wait=TRUE says that the R interpreter should wait for the command to finish.

We can get incremental printing by setting wait=FALSE. However, stdout=TRUE will nullify its effects. Instead, we will want to (probably) set stdout="" and write to a file within our system call. like system("webppl model.wppl > temp_file");

This will send the output to a file, but we also want to see it on the screen. Fortunately, this seems possible with the pipe | tee temp_file , as explained here