[R] Converting character to function argument

Spencer Graves spencer.graves at pdf.com
Fri Sep 12 19:21:44 CEST 2003


Have you considered

	 eval(parse(text="expand.grid(c(1,0),c(1,0))"))

There are other ways to get what you want, but this should work.

hope this helps.  spencer graves

Alvaro.Antonio.Novo at bportugal.pt wrote:
> How can one transform a character string into an argument of a function
> (which is not or I don't want it to be a character string)?
> 
> Example:
> 
> 
>>expand.grid(c(1,0),c(1,0)) ## OK
> 
>   Var1 Var2
> 1    1    1
> 2    0    1
> 3    1    0
> 4    0    0
> 
> 
> 
>>paste(rep("c(0,1)",2),collapse=',') ## to be used below
> 
> [1] "c(0,1),c(0,1)"
> 
>>## string is the input I want, but it needs to be coerced to the correct
> 
> format
> 
> 
>>expand.grid(paste(rep("c(0,1)",2),collapse=',')) ## does not get me there
> 
>            Var1
> 1 c(0,1),c(0,1)
> 
> ***************************************************************************
>  AVISO DE CONFIDENCIALIDADE: Esta mensagem, assim como os ficheiros
> eventualmente anexos, é confidencial e reservada apenas ao conhecimento
> da(s) pessoa(s) nela indicada(s) como destinatária(s). Se não é o seu
> destinatário, solicitamos que não faça qualquer uso do respectivo conteúdo
> e proceda à sua destruição, notificando o remetente.
>  LIMITAÇÃO DE RESPONSABILIDADE: A segurança da transmissão de informação
> por via electrónica não pode ser garantida pelo remetente, o qual, em
> consequência, não se responsabiliza por qualquer facto susceptível de
> afectar a sua integridade.
> 
>  CONFIDENTIALITY NOTICE: This message, as well as existing attached files,
> is confidential and intended exclusively for the individual(s) named as
> addressees. If you are not the intended recipient, you are kindly requested
> not to make any use whatsoever of its contents and to proceed to the
> destruction of the message, thereby notifying the sender.
>  DISCLAIMER: The sender of this message can not ensure the security of its
> electronical transmission and consequently does not accept liability for
> any fact which may interfere with the integrity of its content.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list