[R] Default first argument in assignment function possible?

Heinz Tuechler tuechler at gmx.at
Thu Aug 3 13:08:57 CEST 2006


Dear All,

is there a possibility to provide a default for the first argument in an
assignment function?
I could not find out if and how. You see in the example below that not
explicitly stating the first argument leads to errors.

Thanks,
Heinz Tüchler

### example of assignment function
'testfun<-' <- function(x=a, y=b, value)
  { x <- x+ y+ value
    print(x)
    x }

a <- 0; b <- 1; c <- 2
testfun(c, 2) <- 2  # result: 6
c <- 2
testfun(c   ) <- 2  # result: 5
testfun( , 2) <- 2  # Error: argument is missing, with no default
testfun(y=2) <- 2   # Error: target of assignment expands to non-language
object
testfun() <- 2      # Error: invalid (NULL) left side of assignment

               _                                        
platform       i386-pc-mingw32                          
arch           i386                                     
os             mingw32                                  
system         i386, mingw32                            
status         Patched                                  
major          2                                        
minor          3.1                                      
year           2006                                     
month          07                                       
day            23                                       
svn rev        38687                                    
language       R                                        
version.string Version 2.3.1 Patched (2006-07-23 r38687)



More information about the R-help mailing list