Mercurial > repos > prog > lcmsmatching
diff tolst.R @ 0:3afe41d3e9e7 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit bb4d3e23d99828bfee16d31d794c49a17313ec2f
| author | prog |
|---|---|
| date | Mon, 11 Jul 2016 09:12:03 -0400 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tolst.R Mon Jul 11 09:12:03 2016 -0400 @@ -0,0 +1,30 @@ +################## +# OBJECT TO LIST # +################## + +.object_to_list <- function(obj) { + + if(is.null(obj)) + return(NULL) + + field_names <- names(obj$getRefClass()$fields()) + l <- c() + lapply( field_names, function(x) { l<<-c(l,list(obj$field(x))) } ) + names(l) <- field_names + return(l) +} + +########### +# TO LIST # +########### + +tolst <- function(v) { + + switch(typeof(v), + S4 = lst <- .object_to_list(v), + list = lst <- v, + stop("Unknown type '", typeof(v), "'.") + ) + + return(lst) +}
