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

Option to send $sample() output to file instead of console #473

Open
seth127 opened this issue Mar 18, 2021 · 1 comment
Open

Option to send $sample() output to file instead of console #473

seth127 opened this issue Mar 18, 2021 · 1 comment
Labels
feature New feature or request
Milestone

Comments

@seth127
Copy link

seth127 commented Mar 18, 2021

Summary

I would like to be able to route to a file all of the messages (diagnostics, etc.) that $sample() prints to the console.

Possible interface options

There are two obvious options for how to expose this:

  1. Have a new argument (something like messages_file or messages_out_path) that take a file path and sends all output to that file.
  2. Change the show_messages argument to accept a boolean or a file path:
  • TRUE prints messages to console
  • FALSE prints no messages
  • path sends messages to file instead of console

The second option has the appeal of not adding another (fairly specific) argument, though it does make this argument take mixed types (logical or character). This is a little messy, but not unprecedented (for example, callr does it here).

This second option would also mean that the user could either print to console or save to file, but not both. Looking at the implementation in processx, we may be stuck with this behavior regardless, in which case I'd prefer this second solution. However, I think ideally the user could choose console, file, or both.

Additional context

This originally came out of discussion in #424 and @rok-cesnovar suggested splitting this into its own issue.

There are some possible workarounds, which I think makes this not super high priority. For example, @wlandau uses withr for this purpose in stantargets. It's also possible to call $sample() within either callr::r() or callr::r_bg() and use the show, stdout, and stderr args to accomplish any desired combo of logging to the console and/or a file:

res <- callr::r(
  {function() stanmod$sample(...)},
  args = list(stanmod),
  show = TRUE,                # controls printing to console
  stdout = "/some/log/file",  # sends stdout to file
  stderr = "2>&1"             # interleaves stderr with stdout
)
@rok-cesnovar
Copy link
Member

The just released processx 3.5.0 (https://github.com/r-lib/processx/releases/tag/v3.5.0) offers the option to redirect stdout/stderr to a file which will make solving this issue easy.

@rok-cesnovar rok-cesnovar added this to the v1.0.0 - release milestone Jul 6, 2021
@jgabry jgabry modified the milestones: v1.0.0 - release, future Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants