view tolst.R @ 0:e66bb061af06 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 3529b25417f8e1a5836474c9adec4b696d35099d-dirty
author prog
date Tue, 12 Jul 2016 12:02:37 -0400
parents
children
line wrap: on
line source

##################
# 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)
}