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)
- Error in tests: `Failure ('test-rcmd.R:14:3'): rcmd echo works: `rcmd\("config", "CC", echo = TRUE\)` does not match "config\\s+CC".` HOT 8
- Upkeep for callr (2023) HOT 1
- Posit rebranding
- Upkeep for callr (2023)
- Add alt-text to pictures, plots, etc; see https://posit.co/blog/knitr-fig-alt/ for examples
- Alternative to `arch` argument with `callr` v3.3.2 HOT 2
- r_bg processes hang when waiting for others to spawn HOT 2
- How to detect failure in `r_bg()` ? HOT 1
- Release callr 3.7.4
- please do not run unsigned dll files with random names from temp folder HOT 7
- Release callr 3.7.5
- callr update from CRAN HOT 1
- callr update from CRAN HOT 2
- Rtmp files left in /tmp directory with VSCode HOT 2
- How to use customize functions in the `func` function? HOT 4
- callr update from CRAN HOT 3
- Release callr 3.7.6 HOT 1
- how to get out of session$attach() HOT 5
- Setting different R_HOME for the callr subprocess HOT 1
- r_process subclass shouldn't be cloneable HOT 1
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.