Re: [R] assign if not set; stand-alone R script, source'able too?

2007-11-19 Thread Marc Schwartz
Alexy, In addition to Gabor's reply, you might want to review the following page from the R Wiki: http://wiki.r-project.org/rwiki/doku.php?id=developers:rinterp which covers LittleR by Jeff Horner and Dirk Eddelbuettel and provides shell scripting support for R. HTH, Marc On Mon, 2007-11-19 a

Re: [R] assign if not set; stand-alone R script, source'able too?

2007-11-19 Thread Gabor Grothendieck
Here are two solutions: # 1 "%or%" <- function(x, y) if (is.na(x)) y else x NA %or% 1 # 1 3 %or% 1 # 3 # 3 # can omit Negate<- line in R 2.7.0 since its predefined there Negate <- function(f) function(...) ! match.fun(f)(...) Filter(Negate(is.na), c(NA, 1))[1] # 1 Filter(Negate(is.na), c(3, 1))[1

Re: [R] assign if not set; stand-alone R script, source'able too?

2007-11-19 Thread Alexy Khrabrov
Marc -- thanks, very interesting. I was in fact tinkering at a very simple default arguments assignment to a generic command-line R script header: #!/bin/sh # graph a fertility run tail --lines=+4 "$0" | R --vanilla --slave --args $*; exit args <- commandArgs()[-(1:4)] # the krivostroi library

Re: [R] assign if not set

2007-11-19 Thread Marc Schwartz
On Tue, 2007-11-20 at 03:32 +0300, Alexy Khrabrov wrote: > What's the idiom of assigning a default value to a variable if it's > not set? In Ruby one can say > > v ||= default > > -- that's an or-assign, which triggers the assignment only if v is > not set already. Is there an R shorthand?

[R] assign if not set

2007-11-19 Thread Alexy Khrabrov
What's the idiom of assigning a default value to a variable if it's not set? In Ruby one can say v ||= default -- that's an or-assign, which triggers the assignment only if v is not set already. Is there an R shorthand? Cheers, Alexy __ R-help@r