if R had something like > python -c "print(sum([1,2,3]));print(3*2)" 6 6 but I guess the only way to do this is by writing the string to a tmp file and then doing something like "R CMD BATCH --quiet" on the tmp file I would like to use this for an R service, which allows you to select any string in any application and replace it by its R evaluation ==Jan de Leeuw; Professor and Chair, UCLA Department of Statistics; Editor: Journal of Multivariate Analysis, Journal of Statistical Software US mail: 8130 Math Sciences Bldg, Box 951554, Los Angeles, CA 90095-1554 phone (310)-825-9550; fax (310)-206-5658; email: deleeuw at stat.ucla.edu homepage: http://gifi.stat.ucla.edu ------------------------------------------------------------------------ ------------------------- No matter where you go, there you are. --- Buckaroo Banzai http://gifi.stat.ucla.edu/sounds/nomatter.au
>>>>> "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
On Tue, Feb 24, 2004 at 10:07:32AM +0100, Martin Maechler wrote:> >>>>> "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 defaultNot with --slave: edd at chibud:~> echo "sum(c(1,2,3)); 3*2" | R --slave [1] 6 [1] 6 I would be pretty trivial to filter the "^[1] " out. Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page
On Tue, 24 Feb 2004, Martin Maechler wrote:> > 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 >You can use --slave to suppress the input [al:~] thomas% echo "print(sum(1:3))" | R --slave [1] 6 -thomas
Jan de Leeuw <deleeuw at stat.ucla.edu> wrote: if R had something like > python -c "print(sum([1,2,3]));print(3*2)" 6 6 What's wrong with % echo "print(sum(c(1,2,3))); print(3*2)" | R --no-save -q > print(sum(c(1,2,3))); print(3*2) [1] 6 [1] 6 >