[R] Outputting variable names and their value bindings

Simon Ellis @elli@ @ending from v@@@@r@edu
Sun Jun 24 20:00:51 CEST 2018


I'm writing a piece of scripting glue for a colleague who is doing
computations in several different languages. (It's the most convenient way,
right now.) My system calls the relevant program (e.g. Rstudio, MATLAB)
with a path to a script, captures stdout and parses it for output
variables, which it stores in its own environment for use later on.

This is easy with MATLAB, since it writes back the variable name with its
value, e.g.:

> freq = {somefunction}()
freq =


All I have to do is look for lines with '=' on the end, then grab the next
section of non-empty lines as the binding for the variable. Boom.

With Rscript, if I write something like this:

Rscript -e "a = (2 + 2)" -e "a"

it prints

[1] 4

Is there any way to get R to print output similarly to MATLAB, in an x = y

I have other solutions in mind, but they're all kludgy and I'd rather not
have to. Please can someone save me from the kludge? :-D

Thank you,

~Simon Ellis

Visiting Assistant Professor,
Department of Computer Science,
Vassar College,
Poughkeepsie, NY 12604

“The whole modern world has divided itself into Conservatives and
Progressives. The business of Progressives is to go on making mistakes. The
business of Conservatives is to prevent mistakes from being corrected.” *--
G. K. Chesterton*

	[[alternative HTML version deleted]]

More information about the R-help mailing list