[R] rename and color a list of list of list of values

Sven E. Templer sven.templer at gmail.com
Fri Jun 5 19:12:18 CEST 2015


Hi Karim,

you should learn ?Map to iterate along the list and supply mutliple list
arguments (there is also parallel:::mcMap for multicore).
The magic of the color code generation you figure out yourself, I guess...


Here 'i' intends to be the value, 'n' the name, e.g.

# returns color by character/numeric value:
magic_colour <- function (x) { ... }

# returns child
list_child <- function (i, n) { list(name=n, colour=magic_colour(i)) }

# returns parent
list_parent <- function (i, n) { list(name=n, children=Map(list_child, i,
names(i)), colour=magic_colour(n)) }

# get grandparent
grandparent <- Map(list_parent, expBefore, names(expBefore))


Hope this helps!

Best, S.


On 5 June 2015 at 18:31, Karim Mezhoud <kmezhoud at gmail.com> wrote:

> Hi all,
> I have a list like this
>
> expBefore <-
>
> list(HM450=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>
>
> gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
>                 ),
>
>
> HM27=list(brac_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03),
>
>
> gbm_tcga=list("ATM"=0.19,"ATR"=0.02,"BRCA1"=0.02,"BRCA2"=0.89,"CHEK1"=0.71,"CHEK2"=0.03)
>      )
>      )
>
>
> and I would convert it to
>
> expAfter <-list(
>   list(
>     name="HM450",
>     children=list(
>       list(name="brca_tcga",
>            children=list(
>              list(name="ATM", colour="110000"),
>              list(name="ATR", colour="330000"),
>              list(name="BRCA1", colour="550000"),
>              list(name="BRCA2", colour="770000"),
>              list(name="CHEK1", colour="990000"),
>              list(name="CHEK2", colour="bb0000")
>
>            ), colour="aa0000" # brca_tcga
>            ),
>         list(name="gbm_tcga",
>             children=list(
>               list(name="ATM", colour="001100"),
>               list(name="ATR", colour="003300"),
>               list(name="BRCA1", colour="005500"),
>               list(name="BRCA2", colour="007700"),
>               list(name="CHEK1", colour="009900"),
>               list(name="CHEK2", colour="00bb00")
>             ), colour="345345" # gbm_tcga
>             )
>
>            ), colour="ffa500" # HM450
>   ),
>   list(
>     name="HM27",
>     children=list(
>       list(name="brca_tcga",
>            children=list(
>              list(name="ATM", colour="110000"),
>              list(name="ATR", colour="330000"),
>              list(name="BRCA1", colour="550000"),
>              list(name="BRCA2", colour="770000"),
>              list(name="CHEK1", colour="990000"),
>              list(name="CHEK2", colour="bb0000")
>
>            ), colour="aa0000" ##brca_tcga
>            ),
>       list(name="gbm_tcga",
>            children=list(
>              list(name="ATM", colour="001100"),
>              list(name="ATR", colour="003300"),
>              list(name="BRCA1", colour="005500"),
>              list(name="BRCA2", colour="007700"),
>              list(name="CHEK1", colour="009900"),
>              list(name="CHEK2", colour="00bb00")
>            ), colour="345345") #gbm_tcga
>
>     ), colour="ff00ff"  #HM27
>   )
>
> );
> any suggestion?
> Thanks
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list