[R] would be nice ...

Martin Maechler maechler at stat.math.ethz.ch
Tue Feb 24 10:07:32 CET 2004


>>>>> "Jan" == Jan de Leeuw <deleeuw at stat.ucla.edu>
>>>>>     on Tue, 24 Feb 2004 00:52:51 -0800 writes:

    Jan> if R had something like
    >> python -c "print(sum([1,2,3]));print(3*2)"
    Jan> 6 6

    Jan> but I guess the only way to do this is by writing the
    Jan> string to a tmp file and then doing something like "R
    Jan> CMD BATCH --quiet" on the tmp file

Well, a bit better (with a shell prompt "%") is

    % echo "print(sum(c(1,2,3)));print(3*2)" | R --quiet --vanilla

    > print(sum(c(1,2,3)));print(3*2)
    [1] 6
    [1] 6
    > 

or (slightly nicer)

    % echo "sum(c(1,2,3)); 3*2" | R --quiet --vanilla
    > sum(c(1,2,3)); 3*2
    [1] 6
    [1] 6
    > 

but it still echoes the input by default

    Jan> I would like to use this for an R service, which allows
    Jan> you to select any string in any application and replace
    Jan> it by its R evaluation




More information about the R-help mailing list