[R] Constructin a call of function including permutation of column names - how to escape parentheses?

Tae-kyun Kim taekyunk at gmail.com
Sun Nov 25 21:07:07 CET 2007


Hi,

I guess this may be a way to construct a list of character vectors
from variable names.

> library(gregmisc)
> mycolnames <- LETTERS[1:12]
> combinations.2<-combinations(12,2,mycolnames)
> arg.list <- as.list(as.data.frame(t(combinations.2), stringsAsFactors=FALSE))
> names(arg.list) <- paste("item", seq_len(length(arg.list)), sep="")
> head(arg.list)
$item1
[1] "A" "B"

$item2
[1] "A" "C"

$item3
[1] "A" "D"

$item4
[1] "A" "E"

$item5
[1] "A" "F"

$item6
[1] "A" "G"

On Nov 25, 2007 5:18 AM, Jiří Voller <jirivoller at gmail.com> wrote:
> Dear R-users,
> I would like to construct a list of arguments for a function in a format
> function (list(item1=c("A","B"), item2=c("B","C")), item3=...):
> The individual vectors in the list are permutations of colnames of a
> dataframe.
> The trouble is that I am not able to handle escaping of parentheses
> correctly.
>
> I was trying the following:
> library(gregmisc)
> combinations.2<-combinations(12,2,mycolnames)
> combinations.2.call<-apply(combinations.2,1,function(x){do.call(paste,c(
> as.list(x),sep="\",\""))})
> combinations.2.call<-paste("c(\"",combinations.2.call,"\")",sep="")
>
> but now calling call("list",combinations.2.list) doesnt work.
>
>
> Could anyone give an advice on this? Thank you.
>
> ----------------------------------------------------------------------------------------------
> Jiøí Voller
> Laboratory of Growth Regulators
> Palacký University & Institute of Experimental Botany AS CR
> (c)lechtitelù 11, 783 71 Olomouc
> Czech Republic
> landline: +420-585-634-855
> mobile: +420-737-520-506
> fax: +420-585-634-870
> ----------------------------------------------------------------------------------------------
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org 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.
>
>



-- 
======================================
T.K. (Tae-kyun) Kim
Ph.D. student
Department of Marketing
Marshall School of Business
University of Southern California
======================================


More information about the R-help mailing list