[R] Selective 'expansion' of arguments in a match.call() result ...

2007-05-31 Thread Roberto Brunelli
Is it  possible to  write a support  function to  automatize selective
argument expansion (based on argument  value type) as in the following
example, in  order  to write  terse  code  even  when there  are  many
arguments?  Forcing evaluation of all arguments is not a problem ...

__Thanks a lot!__R_

# When called with document = 1, we have the simple match.call() result,
# when document =  2 and name is a string, it  is expanded, otherwise it
# is not

example <- function (name, document = FALSE) {

   print(name)

   if(document == 1) {
 resh  <- match.call()
   } else if (document == 2) {
 resh  <- match.call()

 if(is.character(name)) {
   resh$name <- name
 }
 resh$document <- document
   } else {
 resh <- call("")
   }

   resh
}

 > a <- "Roberto"
 > b <- 1
 > example(a, document = 1)
[1] "Roberto"
example(name = a, document = 1)
 > example(a, document = 2)
[1] "Roberto"
example(name = "Roberto", document = 2)
 > example(b, document = 2)
[1] 1
example(name = b, document = 2)
 >

-- 

| Roberto Brunelli - [scientist at  Fondazione Bruno Kessler-irst]
|   'Home can be anywhere, for it is a part of one's self'

--
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] S4 object slot of type 'call'

2007-05-28 Thread Roberto Brunelli
I'm using an S4 object with a slot of type 'call': I would like to be able to 
initialize 
it with something like NULL or NA (indicating that there is no information in 
the slot)
but the value should comply with the fact that it must be of type call.

Is there any simple way to obtain this?

Thanks for any hint,

Roberto

-- 
    
| Roberto Brunelli - [scientist at  Fondazione Bruno Kessler-irst]
|   'Home can be anywhere, for it is a part of one's self'

--
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.