Hi, Is it possible to run R in command line to evalute R expressions and return results to stdout, something like >R CMD -e "R.version$minor" then you got return >"8.1" Or do a simple calculation >R CMD -e "sin(1.2)" >0.932039 Thanks. -- Pingping Zheng Department of Mathematics and Statistics Fylde College Lancaster University Lancaster LA1 4YF UK
Pingping Zheng wrote:> Is it possible to run R in command line to evalute R expressions > and return results to stdout, something like > > Or do a simple calculation > >R CMD -e "sin(1.2)" > >0.932039Yes, with a bit of trickery! R on Unix will read from standard in, so you need to feed your R from stdin - typically use 'echo' to send a string to stdin. You'll also want to use --slave to stop all of R's startup messages, and probably --no-save as well. Also, you may need to cat() the expression: $ echo "cat(sin(1.2))" | R --no-save --slave 0.932039 ...otherwise you get R's default print labelling: $echo "sin(1.2)" | R --no-save --slave [1] 0.932039 Baz
Use echo in a Unix shell and pipe it to R. At the Windows command prompt, you could try: c:\home>echo R.version | Rterm --vanilla -q> R.version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 8.1 year 2003 month 11 day 21 language R HTH, Andy> From: Pingping Zheng > > Hi, > > Is it possible to run R in command line to evalute R expressions > and return results to stdout, something like > > >R CMD -e "R.version$minor" > then you got return > >"8.1" > > Or do a simple calculation > >R CMD -e "sin(1.2)" > >0.932039 > > Thanks. > > -- > Pingping Zheng > Department of Mathematics and Statistics > Fylde College > Lancaster University > Lancaster LA1 4YF > UK > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
The natural thing would be to pack this into script, but if you in windows do: echo %1 | Rterm --vanilla -q you run into the problem that everything after the first comma is discarded, unless you use: echo %~1 | Rterm --vanilla -q in which case you will have to quote any R-commands with commas in them. Bendix Carstensen> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Liaw, Andy > Sent: Friday, March 05, 2004 1:56 PM > To: 'Pingping Zheng'; r-help at stat.math.ethz.ch > Subject: RE: [R] Command Line Expressions > > > Use echo in a Unix shell and pipe it to R. At the Windows > command prompt, you could try: > > c:\home>echo R.version | Rterm --vanilla -q > > R.version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 1 > minor 8.1 > year 2003 > month 11 > day 21 > language R > > HTH, > Andy > > > From: Pingping Zheng > > > > Hi, > > > > Is it possible to run R in command line to evalute R > expressions and > > return results to stdout, something like > > > > >R CMD -e "R.version$minor" > > then you got return > > >"8.1" > > > > Or do a simple calculation > > >R CMD -e "sin(1.2)" > > >0.932039 > > > > Thanks. > > > > -- > > Pingping Zheng > > Department of Mathematics and Statistics > > Fylde College > > Lancaster University > > Lancaster LA1 4YF > > UK > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > -------------------------------------------------------------- > ---------------- > Notice: This e-mail message, together with any > attachments,...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html >
Christian Hoffmann
2004-Mar-05 15:02 UTC
[R] unusual name in .Rd file: documenting an infix function
Hi I am having difficulties documenting an infix function: paste.infix.r "%&%" <- function(x,y) { paste(x,y,sep="") } paste.infix.Rd \name{pasteInfix} # I wanted to write \name{"\%\&\%"} or some variation of it, but &, % not allowed in LaTeX, see Guide. \alias{pasteInfix} \title{Paste(infix)} \description{ Paste as infix } \usage{ a %&% b # or \%&\% # this results in: * checking Rd files ... OK * checking for missing documentation entries ... WARNING Undocumented code objects: %&% All user-level objects in a package should have documentation entries. See chapter 'Writing R documentation files' in manual 'Writing R Extensions'. * checking Rd \usage sections ... WARNING Objects in \usage without \alias in documentation object 'pasteInfix': %&% } \arguments{ \item{a}{character (1-dim)} \item{b}{character (1-dim)} } \value{ The concatenation of \code{a} and \code{b}, same as \code{ paste(a, b, sep="") } } \examples{ "I am" \%&\% " hungry" # [1] "I am hungry" } \author{Christian W. Hoffmann, \email{christian.hoffmann at wsl.ch}} \keyword{misc} \keyword{documentation} Does there exist a solution to this problem? Christian -- Dr.sc.math.Christian W. Hoffmann, http://www.wsl.ch/staff/christian.hoffmann Mathematics + Statistical Computing e-mail: christian.hoffmann at wsl.ch Swiss Federal Research Institute WSL Tel: ++41-44-73922- -77 (office) CH-8903 Birmensdorf, Switzerland -11(exchange), -15 (fax)