Comments (7)
Sorry for the slow response.
Writing both stdout and stderr to the same file is tricky, because of non-atomic IO, possible race conditions, the buffering of stdout, possible more problems.
Making this to work across platforms is not an easy task imo.
But if you have some ideas, I would be happy to hear them.
from callr.
Maybe if we just redirect with 2&>1 >file
that works well enough? Let me give it a try....
from callr.
Sorry for not responding in time.
Another possibility would be to just wrap the expression in a R function which calls sink
twice (for stdout and stderr):
wrapper = function(expr, dst) {
fp = file(dst, open = "wt")
sink(file = fp)
sink(file = fp, type = "message")
on.exit({ sink(type = "message"); sink(type = "output"); close(fp) })
expr
}
This is basically what I use in batchtools and it works quite okay most of the time. Your solution might be even better, because you could also record output from C which does not use Rprintf
etc. However, the wrapper might be a nice fallback for windows where you do not have pipes and redirections (or do you?).
from callr.
sink
would work for r
, but not for rcmd
, because that just runs R CMD
. So I would prefer an approach that works for both, because they both use the same safe_system
internally.
Redirection works fine on windows, even 2>&1
is fine, in fact R itself uses redirection in system
:
...
if (ignore.stdout)
command <- paste(command, ">/dev/null")
if (ignore.stderr)
command <- paste(command, "2>/dev/null")
...
So I think this will be fine. r
(and rcmd
) both return stdout
and stderr
separately, and I would keep this. But if you specify the same file for stdout
and stderr
, then I would do 2>&1
.
from callr.
Oh, wait. If I redirect both to the same file, then I cannot return them separately.....
from callr.
OK, looks like there is no way to collect stdout and stderr in the right order...... sink()
would be the only way, i.e. within R, but that does not work for rcmd()
.
I can "fix" the current behavior, in that I can make sure that if you redirect output and error to the same file, then they will be in the file, although in the wrong order....
from callr.
Hmmm, looking at this again, r
does not return the output, actually....
So I guess we could use sink()
for it.
from callr.
Related Issues (20)
- r_bg process stop after some time as session reload or closed HOT 9
- Subscript out of bounds error HOT 2
- system2("Rscript", args ="-e 1") via r_session$new(): Fatal error: creating temporary file for '-e' failed HOT 6
- Incompatible with websocket library HOT 1
- Release callr 3.7.3
- BATCH: outfile cannot have relative path with ~, while R CMD BATCH allows it? HOT 1
- rsession `get_running_time()` method HOT 1
- Feature request: Capture all R Console output with timestamp? HOT 6
- ignoring sigpipe signal HOT 2
- Wrong context for error handling? HOT 1
- Support `carrier::crate()` functions
- Set device for printing HOT 3
- Client library occasionally not found HOT 7
- Overwritten S3 methods when pak is loaded before callr
- Use library path of a fresh R session HOT 2
- Access original error HOT 2
- How do I pass object back to main session from `r_bg`. HOT 2
- Subprocess isolation HOT 6
- Reset non-set environment variables HOT 9
- How Do I Pass A Custom Function To callr::r()? HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from callr.